Tool

Tool(
    *,
    name: str | None = None,
    description: str | None = None,
    func_or_tool: ForwardRef('Tool') | Callable[..., Any]
)

A class representing a Tool that can be used by an agent for various tasks.

This class encapsulates a tool with a name, description, and an executable function. The tool can be registered with a ConversableAgent for use either with an LLM or for direct execution.

Attributes: name (str): The name of the tool. description (str): The description of the tool. func_or_tool (Union[Tool, Callable[…, Any]]): The function or Tool instance to create a Tool from.

Create a new Tool object.

Parameters:
NameDescription
nameThe name of the tool.

Type: str | None

Default: None
descriptionThe description of the tool.

Type: str | None

Default: None
func_or_toolThe function or Tool instance to create a Tool from.

Type: ForwardRef('Tool') | Callable[..., Any]

Instance Attributes

description



func



function_schema


Get the schema for the function.

This is the old way of handling function calls with OpenAI and compatible frameworks. It is provided for backward compatibility.

name



realtime_tool_schema


Get the schema for the tool.

This is the preferred way of handling function calls with OpeaAI and compatible frameworks.

tool_schema


Get the schema for the tool.

This is the preferred way of handling function calls with OpeaAI and compatible frameworks.

Instance Methods

register_for_execution

register_for_execution(self, agent: ConversableAgent) -> 

Registers the tool for direct execution by a ConversableAgent.

This method registers the tool so that it can be executed by the agent, typically outside of the context of an LLM interaction.

Parameters:
NameDescription
agentThe agent to which the tool will be registered.

Type: ConversableAgent

register_for_llm

register_for_llm(self, agent: ConversableAgent) -> 

Registers the tool for use with a ConversableAgent’s language model (LLM).

This method registers the tool so that it can be invoked by the agent during interactions with the language model.

Parameters:
NameDescription
agentThe agent to which the tool will be registered.

Type: ConversableAgent

register_tool

register_tool(self, agent: ConversableAgent) -> 

Register a tool to be both proposed and executed by an agent.

Equivalent to calling both register_for_llm and register_for_execution with the same agent.

Note: This will not make the agent recommend and execute the call in the one step. If the agent recommends the tool, it will need to be the next agent to speak in order to execute the tool.

Parameters:
NameDescription
agentThe agent to which the tool will be registered.

Type: ConversableAgent