Skip to content

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__

__init__(tools=None, registry=None)

Parameters:

Name Type Description Default
tools list

Initial list of tools to add.

None
registry dict

Custom tool registry to use.

None

on_event

on_event(event: Event, callback)

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

on(tool, callback)

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_tool(tool, agent=None)

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_tools(tools, agent=None)

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_tool(tool)

Remove a tool from the ToolRunner.

Parameters:

Name Type Description Default
tool str

The name of the tool to remove.

required

loop

loop(convo, llm, agent=None)

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(convo, llm, agent=None)

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.

stop

stop(result=None)

Stop the execution loop.

Parameters:

Name Type Description Default
result any

The final result to return.

None