Skip to content

Commit 3d7ca23

Browse files
committed
Record output_tools as well
1 parent 8dc2592 commit 3d7ca23

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

pydantic_ai_slim/pydantic_ai/_agent_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ async def _prepare_request(
498498
# Populate tool tracking on the ModelRequest (the last request in the original history)
499499
self.request.function_tools = model_request_parameters.function_tools
500500
self.request.builtin_tools = model_request_parameters.builtin_tools
501+
self.request.output_tools = model_request_parameters.output_tools
501502

502503
model_settings = ctx.deps.model_settings
503504
usage = ctx.state.usage

pydantic_ai_slim/pydantic_ai/messages.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,14 @@ class ModelRequest:
963963
Available for introspection during a run. This field is excluded from serialization.
964964
"""
965965

966+
output_tools: Annotated[list[ToolDefinition] | None, pydantic.Field(exclude=True, repr=False)] = field(
967+
default=None, repr=False
968+
)
969+
"""Output tools that were available for this request.
970+
971+
Available for introspection during a run. This field is excluded from serialization.
972+
"""
973+
966974
kind: Literal['request'] = 'request'
967975
"""Message type identifier, this is available on all parts as a discriminator."""
968976

tests/test_messages.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,25 +612,33 @@ def test_binary_content_validation_with_optional_identifier():
612612

613613

614614
def test_model_request_tool_tracking_excluded_from_serialization():
615-
"""Test that function_tools and builtin_tools are not serialized in the request."""
615+
"""Test that function, builtin, and output tools are not serialized in the request."""
616616
tool_def = ToolDefinition(
617617
name='test_tool',
618618
description='A test tool',
619619
parameters_json_schema={'type': 'object', 'properties': {}},
620620
)
621+
output_tool_def = ToolDefinition(
622+
name='request_output',
623+
description='An output tool',
624+
parameters_json_schema={'type': 'object', 'properties': {}},
625+
)
621626

622627
request = ModelRequest(
623628
parts=[UserPromptPart('test prompt')],
624629
instructions='test instructions',
625630
function_tools=[tool_def],
626631
builtin_tools=[ImageGenerationTool()],
632+
output_tools=[output_tool_def],
627633
)
628634

629635
# Verify the fields are accessible
630636
assert request.function_tools == [tool_def]
631637
assert request.builtin_tools == [ImageGenerationTool()]
638+
assert request.output_tools == [output_tool_def]
632639

633640
# Serialize - fields ARE excluded
634641
serialized = ModelMessagesTypeAdapter.dump_python([request], mode='json')
635642
assert 'function_tools' not in serialized[0]
636643
assert 'builtin_tools' not in serialized[0]
644+
assert 'output_tools' not in serialized[0]

0 commit comments

Comments
 (0)