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 |
reset
Resets the conversation context for the agent. Clears the current conversation history.
run
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
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
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
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
Adds a list of tools to the tool manager
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools |
list
|
List of tool names to add. |
required |