Package mindsdb.models.agent
Class Agent
java.lang.Object
mindsdb.models.agent.Agent
Represents a MindsDB agent.
Working with agents:
Get an agent by name:
Agent agent = agents.get("my_agent");
Query an agent:
AgentCompletion completion = agent.completion(List.of(Map.of("question", "What is your name?", "answer", null)));
System.out.println(completion.getContent());
Query an agent with streaming:
AgentCompletion completion = agent
.completionStream(List.of(Map.of("question", "What is your name?", "answer", null)));
for (CompletionChunk chunk : completion) {
System.out.println(chunk.getChoices().get(0).getDelta().getContent());
}
List all agents:
List<Agent> agents = agents.list();
Create a new agent:
Model model = models.get("my_model"); // Or use models.create(...)
// Connect your agent to a MindsDB table.
Skill textToSqlSkill = skills.create("text_to_sql", "sql",
Map.of("tables", List.of("my_table"), "database", "my_database"));
Agent agent = agents.create("my_agent", model, List.of(textToSqlSkill));
Update an agent:
Model newModel = models.get("new_model");
agent.setModelName(newModel.getName());
Skill newSkill = skills.create("new_skill", "sql",
Map.of("tables", List.of("new_table"), "database", "new_database"));
agent.getSkills().add(newSkill);
Agent updatedAgent = agents.update("my_agent", agent);
Delete an agent by name:
agents.drop("my_agent");
-
Constructor Summary
ConstructorsConstructorDescriptionAgent(String name, String modelName, List<Skill> skills, com.google.gson.JsonObject params, LocalDateTime createdAt, LocalDateTime updatedAt) Constructor for AgentAgent(String name, String modelName, List<Skill> skills, com.google.gson.JsonObject params, LocalDateTime createdAt, LocalDateTime updatedAt, String provider, Agents agents) Constructs a new Agent instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDatabase(String database, List<String> table, String description) Add a database to the agent.voidAdd a file to the agent.voidAdd files to the agent.voidaddWebPage(String url, String description, String knowledgebase, Integer crawlDepth, List<String> filters) Add a web page to the agent.voidaddWebPages(List<String> urls, String description, String knowledgebase, Integer crawlDepth, List<String> filters) Add web pages to the agent.completion(String input, String inputColumnName) Generates a completion for the given message.completion(List<Map<String, String>> messages) Generates a completion for the given list of messages.describe()Returns a string representation of the agent.static AgentConverts JSON data to an Agent object.toString()
-
Constructor Details
-
Agent
public Agent(String name, String modelName, List<Skill> skills, com.google.gson.JsonObject params, LocalDateTime createdAt, LocalDateTime updatedAt, String provider, Agents agents) Constructs a new Agent instance.- Parameters:
name- - the name of the agentmodelName- - the name of the model associated with the agentskills- - the list of skills the agent possessesparams- - additional parameters for the agent in JSON formatcreatedAt- - the timestamp when the agent was createdupdatedAt- - the timestamp when the agent was last updatedprovider- - the provider of the agentagents- - the Agents instance associated with this agent
-
Agent
public Agent(String name, String modelName, List<Skill> skills, com.google.gson.JsonObject params, LocalDateTime createdAt, LocalDateTime updatedAt) Constructor for Agent- Parameters:
name- - name of the agentmodelName- - name of the modelskills- - list of skillsparams- - parameterscreatedAt- - created atupdatedAt- - updated at
-
-
Method Details
-
toString
-
describe
Returns a string representation of the agent.- Returns:
- A string representation of the agent.
-
fromJson
Converts JSON data to an Agent object.- Parameters:
data- - the JSON data to convertagents- - the Agents instance associated with this agent- Returns:
- An Agent object created from the JSON data.
-
completion
Generates a completion for the given list of messages. This method takes a list of messages, where each message is represented as a map of key-value pairs. It converts each message into a JSON object and then calls the completion method of the agents with the name and the list of JSON objects.- Parameters:
messages- A list of messages, where each message is a map of key-value pairs.- Returns:
- An AgentCompletion object containing the result of the completion.
-
completion
Generates a completion for the given message.- Parameters:
input- - input messageinputColumnName- - input column name- Returns:
- An AgentCompletion object containing the result of the completion.
-
addFiles
Add files to the agent.- Parameters:
filePaths- - list of file pathsdescription- - description of the filesknowledgebase- - knowledgebase
-
addFile
Add a file to the agent.- Parameters:
filePath- - file pathdescription- - description of the fileknowledgebase- - knowledgebase
-
addWebPages
public void addWebPages(List<String> urls, String description, String knowledgebase, Integer crawlDepth, List<String> filters) Add web pages to the agent.- Parameters:
urls- - list of URLsdescription- - description of the web pagesknowledgebase- - knowledgebasecrawlDepth- - crawl depthfilters- - list of filters
-
addWebPage
public void addWebPage(String url, String description, String knowledgebase, Integer crawlDepth, List<String> filters) Add a web page to the agent.- Parameters:
url- - URLdescription- - description of the web pageknowledgebase- - knowledgebasecrawlDepth- - crawl depthfilters- - list of filters
-
addDatabase
Add a database to the agent.- Parameters:
database- - databasetable- - list of tablesdescription- - description of the database
-