Class Agent

java.lang.Object
mindsdb.models.agent.Agent

public class Agent extends Object
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 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 agent
      modelName - - the name of the model associated with the agent
      skills - - the list of skills the agent possesses
      params - - additional parameters for the agent in JSON format
      createdAt - - the timestamp when the agent was created
      updatedAt - - the timestamp when the agent was last updated
      provider - - the provider of the agent
      agents - - 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 agent
      modelName - - name of the model
      skills - - list of skills
      params - - parameters
      createdAt - - created at
      updatedAt - - updated at
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • describe

      public String describe()
      Returns a string representation of the agent.
      Returns:
      A string representation of the agent.
    • fromJson

      public static Agent fromJson(com.google.gson.JsonObject data, Agents agents)
      Converts JSON data to an Agent object.
      Parameters:
      data - - the JSON data to convert
      agents - - the Agents instance associated with this agent
      Returns:
      An Agent object created from the JSON data.
    • completion

      public AgentCompletion completion(List<Map<String,String>> messages)
      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

      public AgentCompletion completion(String input, String inputColumnName)
      Generates a completion for the given message.
      Parameters:
      input - - input message
      inputColumnName - - input column name
      Returns:
      An AgentCompletion object containing the result of the completion.
    • addFiles

      public void addFiles(List<String> filePaths, String description, String knowledgebase)
      Add files to the agent.
      Parameters:
      filePaths - - list of file paths
      description - - description of the files
      knowledgebase - - knowledgebase
    • addFile

      public void addFile(String filePath, String description, String knowledgebase)
      Add a file to the agent.
      Parameters:
      filePath - - file path
      description - - description of the file
      knowledgebase - - 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 URLs
      description - - description of the web pages
      knowledgebase - - knowledgebase
      crawlDepth - - crawl depth
      filters - - 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 - - URL
      description - - description of the web page
      knowledgebase - - knowledgebase
      crawlDepth - - crawl depth
      filters - - list of filters
    • addDatabase

      public void addDatabase(String database, List<String> table, String description)
      Add a database to the agent.
      Parameters:
      database - - database
      table - - list of tables
      description - - description of the database