![JAR search and dependency download from the Maven repository](/logo.png)
cn.homj.autogen4j.AgentFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of autogen4j-agent Show documentation
Show all versions of autogen4j-agent Show documentation
Design inspired by Microsoft's AutoGen
The newest version!
package cn.homj.autogen4j;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* @author jiehong.jh
* @date 2023/11/28
*/
@Data
@Accessors(fluent = true)
public class AgentFunction {
/**
* The name of the function.
*/
private String name;
private String description;
private Object parameters;
private Function parser;
private Function, ?> action;
private boolean permitAll;
private List permitted;
public AgentFunction permit(Agent agent) {
if (permitted == null) {
permitted = new ArrayList<>();
}
permitted.add(agent);
return this;
}
public boolean isPermit(Agent agent) {
if (permitAll) {
return true;
}
if (permitted == null) {
return false;
}
return permitted.contains(agent);
}
@SuppressWarnings({"unchecked", "rawtypes"})
public Object run(String input) {
try {
Object args;
if (parser == null) {
args = input;
} else {
args = parser.apply(input);
}
return ((Function)action).apply(args);
} catch (Exception e) {
return "Execution failed: " + e.getMessage();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy