Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pydantic_ai_slim/pydantic_ai/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ class DeferredToolRequests:
See [deferred tools docs](../deferred-tools.md#deferred-tools) for more information.
"""

calls: list[ToolCallPart] = field(default_factory=list)
calls: list[ToolCallPart] = field(default_factory=lambda: list[ToolCallPart]())
"""Tool calls that require external execution."""
approvals: list[ToolCallPart] = field(default_factory=list)
approvals: list[ToolCallPart] = field(default_factory=lambda: list[ToolCallPart]())
"""Tool calls that require human-in-the-loop approval."""
metadata: dict[str, dict[str, Any]] = field(default_factory=dict)
metadata: dict[str, dict[str, Any]] = field(default_factory=lambda: dict[str, dict[str, Any]]())
"""Metadata for deferred tool calls, keyed by `tool_call_id`."""


Expand Down Expand Up @@ -209,9 +209,9 @@ class DeferredToolResults:
See [deferred tools docs](../deferred-tools.md#deferred-tools) for more information.
"""

calls: dict[str, DeferredToolCallResult | Any] = field(default_factory=dict)
calls: dict[str, DeferredToolCallResult | Any] = field(default_factory=lambda: dict[str, DeferredToolCallResult | Any]())
"""Map of tool call IDs to results for tool calls that required external execution."""
approvals: dict[str, bool | DeferredToolApprovalResult] = field(default_factory=dict)
approvals: dict[str, bool | DeferredToolApprovalResult] = field(default_factory=lambda: dict[str, bool | DeferredToolApprovalResult]())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert these changes; looks like your IDE is using a newer pyright than we have in pyproject.toml

"""Map of tool call IDs to results for tool calls that required human-in-the-loop approval."""


Expand Down Expand Up @@ -372,6 +372,7 @@ def from_schema(
json_schema: JsonSchemaValue,
takes_ctx: bool = False,
sequential: bool = False,
requires_approval: bool = False,
) -> Self:
"""Creates a Pydantic tool from a function and a JSON schema.

Expand All @@ -386,6 +387,7 @@ def from_schema(
takes_ctx: An optional boolean parameter indicating whether the function
accepts the context object as an argument.
sequential: Whether the function requires a sequential/serial execution environment. Defaults to False.
requires_approval: Whether this tool requires human-in-the-loop approval. Defaults to False.

Returns:
A Pydantic tool that calls the function
Expand All @@ -406,6 +408,7 @@ def from_schema(
description=description,
function_schema=function_schema,
sequential=sequential,
requires_approval=requires_approval,
)

@property
Expand Down
Loading