PydanticAIInteroperability

PydanticAIInteroperability()

A class implementing the Interoperable protocol for converting Pydantic AI tools into a general Tool format.
This class takes a PydanticAITool and converts it into a standard Tool object, ensuring compatibility between Pydantic AI tools and other systems that expect the Tool format. It also provides a mechanism for injecting context parameters into the tool’s function.

Static Methods

convert_tool

convert_tool(
    tool: Any,
    deps: Any = None,
    **kwargs: Any
) -> autogen.interop.pydantic_ai.pydantic_ai_tool.PydanticAITool

Converts a given Pydantic AI tool into a general Tool format.
This method verifies that the provided tool is a valid PydanticAITool, handles context dependencies if necessary, and returns a standardized Tool object.

Parameters:
NameDescription
toolThe tool to convert, expected to be an instance of PydanticAITool.

Type: Any
depsThe dependencies to inject into the context, required if the tool takes a context.

Defaults to None.

Type: Any

Default: None
**kwargsAdditional arguments that are not used in this method.

Type: Any
Returns:
TypeDescription
autogen.interop.pydantic_ai.pydantic_ai_tool.PydanticAIToolAG2PydanticAITool: A standardized Tool object converted from the Pydantic AI tool.

get_unsupported_reason

get_unsupported_reason() -> str | None

inject_params

inject_params(ctx: Any, tool: Any) -> Callable[..., Any]

Wraps the tool’s function to inject context parameters and handle retries.
This method ensures that context parameters are properly passed to the tool when invoked and that retries are managed according to the tool’s settings.

Parameters:
NameDescription
ctxThe run context, which may include dependencies and retry information.

Type: Any
toolThe Pydantic AI tool whose function is to be wrapped.

Type: Any
Returns:
TypeDescription
Callable[..., Any]Callable[…, Any]: A wrapped function that includes context injection and retry handling.