ToolRunner
dopus.core.ToolRunner
A class for managing and executing tools from LLM requests.
This class handles tool execution for a set of tools that can be used by an AI agent in a conversation.
Event
Bases: Enum
Enum defining various events that can occur during tool execution.
__init__
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools |
list
|
Initial list of tools to add. |
None
|
registry |
dict
|
Custom tool registry to use. |
None
|
on_event
Register a callback function for a specific event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event |
Event
|
The event to listen for. |
required |
callback |
callable
|
The function to call when the event occurs. |
required |
on
Register a callback function for a specific tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool |
str
|
The name of the tool. |
required |
callback |
callable
|
The function to call when the tool is used. |
required |
add_tool
Add a tool to the ToolRunner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool |
str
|
The name of the tool to add. |
required |
agent |
object
|
The agent object to attach the tool to. |
None
|
add_tools
Add multiple tools to the ToolRunner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools |
list
|
A list of tool names to add. |
required |
agent |
object
|
The agent object to attach the tools to. |
None
|
remove_tool
Remove a tool from the ToolRunner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool |
str
|
The name of the tool to remove. |
required |
loop
Start the main execution loop for processing conversations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convo |
object
|
The conversation object. |
required |
llm |
object
|
The language model object. |
required |
agent |
object
|
The agent object. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing the final result and a list of actions performed. |
execute
Execute a single step in the conversation processing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convo |
object
|
The conversation object. |
required |
llm |
object
|
The language model object. |
required |
agent |
object
|
The agent object. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing the result and a log of the execution. |