Skip to content

PydanticAITool

autogen.interop.pydantic_ai.pydantic_ai_tool.PydanticAITool #

PydanticAITool(name, description, func, parameters_json_schema)

Bases: Tool

A class representing a Pydantic AI Tool that extends the general Tool functionality with additional functionality specific to Pydantic AI tools.

This class inherits from the Tool class and adds functionality for registering tools with a ConversableAgent, along with providing additional schema information specific to Pydantic AI tools, such as parameters and function signatures.

ATTRIBUTE DESCRIPTION
parameters_json_schema

A schema describing the parameters that the tool's function expects.

TYPE: Dict[str, Any]

Initializes a PydanticAITool object with the provided name, description, function, and parameter schema.

PARAMETER DESCRIPTION
name

The name of the tool.

TYPE: str

description

A description of what the tool does.

TYPE: str

func

The function that is executed when the tool is called.

TYPE: Callable[..., Any]

parameters_json_schema

A schema describing the parameters that the function accepts.

TYPE: Dict[str, Any]

Source code in autogen/interop/pydantic_ai/pydantic_ai_tool.py
def __init__(
    self, name: str, description: str, func: Callable[..., Any], parameters_json_schema: dict[str, Any]
) -> None:
    """Initializes a PydanticAITool object with the provided name, description,
    function, and parameter schema.

    Args:
        name (str): The name of the tool.
        description (str): A description of what the tool does.
        func (Callable[..., Any]): The function that is executed when the tool is called.
        parameters_json_schema (Dict[str, Any]): A schema describing the parameters
                                                 that the function accepts.
    """
    super().__init__(name=name, description=description, func_or_tool=func)
    self._func_schema = {
        "type": "function",
        "function": {
            "name": name,
            "description": description,
            "parameters": parameters_json_schema,
        },
    }

name property #

name

description property #

description

func property #

func

tool_schema property #

tool_schema

Get the schema for the tool.

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

function_schema property #

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.

realtime_tool_schema property #

realtime_tool_schema

Get the schema for the tool.

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

register_for_execution #

register_for_execution(agent)

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.

PARAMETER DESCRIPTION
agent

The agent to which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/tools/tool.py
def register_for_execution(self, agent: "ConversableAgent") -> None:
    """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.

    Args:
        agent (ConversableAgent): The agent to which the tool will be registered.
    """
    agent.register_for_execution()(self)

register_tool #

register_tool(agent)

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.

PARAMETER DESCRIPTION
agent

The agent to which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/tools/tool.py
def register_tool(self, agent: "ConversableAgent") -> None:
    """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.

    Args:
        agent (ConversableAgent): The agent to which the tool will be registered.
    """
    self.register_for_llm(agent)
    self.register_for_execution(agent)

register_for_llm #

register_for_llm(agent)

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

This method updates the agent's tool signature to include the function schema, allowing the agent to invoke the tool correctly during interactions with the LLM.

PARAMETER DESCRIPTION
agent

The agent with which the tool will be registered.

TYPE: ConversableAgent

Source code in autogen/interop/pydantic_ai/pydantic_ai_tool.py
def register_for_llm(self, agent: ConversableAgent) -> None:
    """Registers the tool with the ConversableAgent for use with a language model (LLM).

    This method updates the agent's tool signature to include the function schema,
    allowing the agent to invoke the tool correctly during interactions with the LLM.

    Args:
        agent (ConversableAgent): The agent with which the tool will be registered.
    """
    agent.update_tool_signature(self._func_schema, is_remove=False)