PydanticAIInteroperability
autogen.interop.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.
inject_params staticmethod
#
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.
PARAMETER | DESCRIPTION |
---|---|
ctx | The run context, which may include dependencies and retry information. |
tool | The Pydantic AI tool whose function is to be wrapped. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable[..., Any] | Callable[..., Any]: A wrapped function that includes context injection and retry handling. |
RAISES | DESCRIPTION |
---|---|
ValueError | If the tool fails after the maximum number of retries. |
Source code in autogen/interop/pydantic_ai/pydantic_ai.py
convert_tool classmethod
#
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.
PARAMETER | DESCRIPTION |
---|---|
tool | The tool to convert, expected to be an instance of TYPE: |
deps | The dependencies to inject into the context, required if the tool takes a context. Defaults to None. TYPE: |
**kwargs | Additional arguments that are not used in this method. TYPE: |
RETURNS | DESCRIPTION |
---|---|
AG2PydanticAITool | A standardized TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | If the provided tool is not an instance of |
UserWarning | If the |