Agents

class mindsdb_sdk.agents.Agent(name: str, model_name: str, skills: List[mindsdb_sdk.skills.Skill], params: dict, created_at: datetime.datetime, updated_at: datetime.datetime, collection: mindsdb_sdk.utils.objects_collection.CollectionBase = None)

Bases: object

Represents a MindsDB agent.

Working with agents:

Get an agent by name:

>>> agent = agents.get('my_agent')

Query an agent:

>>> completion = agent.completion([{'question': 'What is your name?', 'answer': None}])
>>> print(completion.content)

List all agents:

>>> agents = agents.list()

Create a new agent:

>>> model = models.get('my_model') # Or use models.create(...)
>>> # Connect your agent to a MindsDB table.
>>> text_to_sql_skill = skills.create('text_to_sql', 'sql', { 'tables': ['my_table'], 'database': 'my_database' })
>>> agent = agents.create('my_agent', model, [text_to_sql_skill])

Update an agent:

>>> new_model = models.get('new_model')
>>> agent.model_name = new_model.name
>>> new_skill = skills.create('new_skill', 'sql', { 'tables': ['new_table'], 'database': 'new_database' })
>>> updated_agent.skills.append(new_skill)
>>> updated_agent = agents.update('my_agent', agent)

Delete an agent by name:

>>> agents.delete('my_agent')
add_file(file_path: str, description: str, knowledge_base: str = None)

Add a file to the agent for retrieval.

Parameters

file_path – Path to the file to be added.

completion(messages: List[dict]) → mindsdb_sdk.agents.AgentCompletion
classmethod from_json(json: dict, collection: mindsdb_sdk.utils.objects_collection.CollectionBase)
class mindsdb_sdk.agents.AgentCompletion(content: str)

Bases: object

Represents a full MindsDB agent completion

class mindsdb_sdk.agents.Agents(api, project: str, knowledge_bases: mindsdb_sdk.knowledge_bases.KnowledgeBases, databases: mindsdb_sdk.databases.Databases, skills: mindsdb_sdk.skills.Skills = None)

Bases: mindsdb_sdk.utils.objects_collection.CollectionBase

Collection for agents

add_file(name: str, file_path: str, description: str, knowledge_base: str = None)

Add a file to the agent for retrieval.

Parameters
  • name – Name of the agent

  • file_path – Path to the file to be added, or name of existing file.

  • description – Description of the file. Used by agent to know when to do retrieval

  • knowledge_base – Name of an existing knowledge base to be used. Will create a default knowledge base if not given.

completion(name: str, messages: List[dict]) → mindsdb_sdk.agents.AgentCompletion

Queries the agent for a completion.

Parameters
  • name – Name of the agent

  • messages – List of messages to be sent to the agent

Returns

completion from querying the agent

create(name: str, model: mindsdb_sdk.models.Model, skills: List[Union[mindsdb_sdk.skills.Skill, str]] = None, params: dict = None) → mindsdb_sdk.agents.Agent

Create new agent and return it

Parameters
  • name – Name of the agent to be created

  • model – Model to be used by the agent

  • skills – List of skills to be used by the agent. Currently only ‘sql’ is supported.

  • params – Parameters for the agent

Returns

created agent object

drop(name: str)

Drop an agent by name.

Parameters

name – Name of the agent to be dropped

get(name: str) → mindsdb_sdk.agents.Agent

Gets an agent by name.

Parameters

name – Name of the agent

Returns

agent with given name

list() → List[mindsdb_sdk.agents.Agent]

List available agents.

Returns

list of agents

update(name: str, updated_agent: mindsdb_sdk.agents.Agent)

Update an agent by name.

Parameters
  • name – Name of the agent to be updated

  • updated_agent – Agent with updated fields

Returns

updated agent object