Skip to content

Agent

dopus.core.Agent

Bases: ABC

Abstract base class of an agent capable of running tools and managing conversations. The agent interfaces with a language model (LLM) and has access to various tools through the tool registry. It is designed to handle conversations where tools may be called upon dynamically.

Attributes:

Name Type Description
provider Provider

The language model provider used by the agent.

name str

The name of the agent.

convo Convo

Conversation handler that manages the dialogue context.

registry dict

A registry of tools that can be utilized by the agent.

tool_manager ToolRunner

Manager that handles tool execution and lifecycle events.

__init__

__init__(provider: Provider, name: str = 'Agent', convo: Convo = None, registry: dict = None, tool_manager: ToolRunner = None)

Parameters:

Name Type Description Default
name str

Name of the agent.

'Agent'
provider Provider

language model provider instance.

required

get_actions

get_actions()

Get the list of actions the agent has taken

reset

reset()

Resets the conversation context for the agent. Clears the current conversation history.

run

run(message: str = None)

Runs the agent, initiating a conversation or tool execution loop. If a message is provided, it appends it to the conversation.

Parameters:

Name Type Description Default
message str

Message from the user to be processed by the agent.

None

Returns:

Type Description

Result of the tool execution loop managed by the tool manager.

stop

stop(result=None)

Stops the current tool execution or conversation flow and returns a result.

Parameters:

Name Type Description Default
result

Optional result to return when stopping.

None

on_tool_use

on_tool_use(tool: str, func)

Registers a callback function to be triggered when a tool is used.

Parameters:

Name Type Description Default
tool str

Name of the tool.

required
func function

Function to be called when the tool is triggered.

required

add_tool

add_tool(tool: str)

Adds a tool by name to the tool manager, making it available for the agent to use.

Parameters:

Name Type Description Default
tool str

Name of the tool to add.

required

add_tools

add_tools(tools: list)

Adds a list of tools to the tool manager

Parameters:

Name Type Description Default
tools list

List of tool names to add.

required

prompt abstractmethod

prompt() -> str

Abstract method to provide the agent's system prompt or message. Must be implemented by subclasses.

Returns:

Name Type Description
str str

The prompt or message that represents the agent's behavior.