diff --git a/pydantic_ai_slim/pydantic_ai/tools.py b/pydantic_ai_slim/pydantic_ai/tools.py index c22630d72..c1a385161 100644 --- a/pydantic_ai_slim/pydantic_ai/tools.py +++ b/pydantic_ai_slim/pydantic_ai/tools.py @@ -271,6 +271,7 @@ def from_schema( name: str, description: str, json_schema: JsonSchemaValue, + takes_ctx: bool = False, ) -> Self: """Creates a Pydantic tool from a function and a JSON schema. @@ -282,7 +283,9 @@ def from_schema( description: Used to tell the model how/when/why to use the tool. You can provide few-shot examples as a part of the description. json_schema: The schema for the function arguments - + takes_ctx: An optional boolean parameter indicating whether the function + accepts the context object as an argument. + Returns: A Pydantic tool that calls the function """ @@ -291,13 +294,13 @@ def from_schema( description=description, validator=SchemaValidator(schema=core_schema.any_schema()), json_schema=json_schema, - takes_ctx=False, + takes_ctx=takes_ctx, is_async=_utils.is_async_callable(function), ) return cls( function, - takes_ctx=False, + takes_ctx=takes_ctx, name=name, description=description, function_schema=function_schema,