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
ConstructorDescriptionAgent
(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
-
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.
-