Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ async def main():
content='What is the capital of France?',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
)
),
CallToolsNode(
Expand All @@ -329,6 +330,7 @@ async def main():
usage=RequestUsage(input_tokens=56, output_tokens=7),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
)
),
End(data=FinalResult(output='The capital of France is Paris.')),
Expand Down Expand Up @@ -382,7 +384,8 @@ async def main():
content='What is the capital of France?',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
)
),
CallToolsNode(
Expand All @@ -391,6 +394,7 @@ async def main():
usage=RequestUsage(input_tokens=56, output_tokens=7),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
)
),
End(data=FinalResult(output='The capital of France is Paris.')),
Expand Down Expand Up @@ -1044,7 +1048,8 @@ with capture_run_messages() as messages: # (2)!
content='Please get me the volume of a box with size 6.',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -1057,6 +1062,7 @@ with capture_run_messages() as messages: # (2)!
usage=RequestUsage(input_tokens=62, output_tokens=4),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
ModelRequest(
parts=[
Expand All @@ -1066,7 +1072,8 @@ with capture_run_messages() as messages: # (2)!
tool_call_id='pyd_ai_tool_call_id',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -1079,6 +1086,7 @@ with capture_run_messages() as messages: # (2)!
usage=RequestUsage(input_tokens=72, output_tokens=8),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
]
"""
Expand Down
3 changes: 2 additions & 1 deletion docs/api/models/function.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ async def model_function(
content='Testing my agent...',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
)
]
"""
Expand Down
19 changes: 14 additions & 5 deletions docs/deferred-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ print(result.all_messages())
content='Delete `__init__.py`, write `Hello, world!` to `README.md`, and clear `.env`',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -129,6 +130,7 @@ print(result.all_messages())
usage=RequestUsage(input_tokens=63, output_tokens=21),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
ModelRequest(
parts=[
Expand All @@ -138,7 +140,8 @@ print(result.all_messages())
tool_call_id='update_file_readme',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelRequest(
parts=[
Expand All @@ -154,7 +157,8 @@ print(result.all_messages())
tool_call_id='delete_file',
timestamp=datetime.datetime(...),
),
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -165,6 +169,7 @@ print(result.all_messages())
usage=RequestUsage(input_tokens=79, output_tokens=39),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
]
"""
Expand Down Expand Up @@ -275,7 +280,8 @@ async def main():
content='Calculate the answer to the ultimate question of life, the universe, and everything',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -290,6 +296,7 @@ async def main():
usage=RequestUsage(input_tokens=63, output_tokens=13),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
ModelRequest(
parts=[
Expand All @@ -299,7 +306,8 @@ async def main():
tool_call_id='pyd_ai_tool_call_id',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -310,6 +318,7 @@ async def main():
usage=RequestUsage(input_tokens=64, output_tokens=28),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
]
"""
Expand Down
2 changes: 1 addition & 1 deletion docs/durable_execution/temporal.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ As workflows and activities run in separate processes, any values passed between

To account for these limitations, tool functions and the [event stream handler](#streaming) running inside activities receive a limited version of the agent's [`RunContext`][pydantic_ai.tools.RunContext], and it's your responsibility to make sure that the [dependencies](../dependencies.md) object provided to [`TemporalAgent.run()`][pydantic_ai.durable_exec.temporal.TemporalAgent.run] can be serialized using Pydantic.

Specifically, only the `deps`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries`, `run_step` and `partial_output` fields are available by default, and trying to access `model`, `usage`, `prompt`, `messages`, or `tracer` will raise an error.
Specifically, only the `deps`, `run_id`, `retries`, `tool_call_id`, `tool_name`, `tool_call_approved`, `retry`, `max_retries`, `run_step` and `partial_output` fields are available by default, and trying to access `model`, `usage`, `prompt`, `messages`, or `tracer` will raise an error.
If you need one or more of these attributes to be available inside activities, you can create a [`TemporalRunContext`][pydantic_ai.durable_exec.temporal.TemporalRunContext] subclass with custom `serialize_run_context` and `deserialize_run_context` class methods and pass it to [`TemporalAgent`][pydantic_ai.durable_exec.temporal.TemporalAgent] as `run_context_type`.

### Streaming
Expand Down
27 changes: 20 additions & 7 deletions docs/message-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ print(result.all_messages())
content='Tell me a joke.',
timestamp=datetime.datetime(...),
),
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -61,6 +62,7 @@ print(result.all_messages())
usage=RequestUsage(input_tokens=60, output_tokens=12),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
]
"""
Expand Down Expand Up @@ -92,7 +94,8 @@ async def main():
content='Tell me a joke.',
timestamp=datetime.datetime(...),
),
]
],
run_id='...',
)
]
"""
Expand All @@ -118,7 +121,8 @@ async def main():
content='Tell me a joke.',
timestamp=datetime.datetime(...),
),
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -129,6 +133,7 @@ async def main():
usage=RequestUsage(input_tokens=50, output_tokens=12),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
]
"""
Expand Down Expand Up @@ -172,7 +177,8 @@ print(result2.all_messages())
content='Tell me a joke.',
timestamp=datetime.datetime(...),
),
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -183,14 +189,16 @@ print(result2.all_messages())
usage=RequestUsage(input_tokens=60, output_tokens=12),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
ModelRequest(
parts=[
UserPromptPart(
content='Explain?',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -201,6 +209,7 @@ print(result2.all_messages())
usage=RequestUsage(input_tokens=61, output_tokens=26),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
]
"""
Expand Down Expand Up @@ -293,7 +302,8 @@ print(result2.all_messages())
content='Tell me a joke.',
timestamp=datetime.datetime(...),
),
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -304,14 +314,16 @@ print(result2.all_messages())
usage=RequestUsage(input_tokens=60, output_tokens=12),
model_name='gpt-5',
timestamp=datetime.datetime(...),
run_id='...',
),
ModelRequest(
parts=[
UserPromptPart(
content='Explain?',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -322,6 +334,7 @@ print(result2.all_messages())
usage=RequestUsage(input_tokens=61, output_tokens=26),
model_name='gemini-2.5-pro',
timestamp=datetime.datetime(...),
run_id='...',
),
]
"""
Expand Down
6 changes: 5 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ async def test_forecast():
content='What will the weather be like in London on 2024-11-28?',
timestamp=IsNow(tz=timezone.utc), # (7)!
),
]
],
run_id=IsStr(),
),
ModelResponse(
parts=[
Expand All @@ -146,6 +147,7 @@ async def test_forecast():
),
model_name='test',
timestamp=IsNow(tz=timezone.utc),
run_id=IsStr(),
),
ModelRequest(
parts=[
Expand All @@ -156,6 +158,7 @@ async def test_forecast():
timestamp=IsNow(tz=timezone.utc),
),
],
run_id=IsStr(),
),
ModelResponse(
parts=[
Expand All @@ -169,6 +172,7 @@ async def test_forecast():
),
model_name='test',
timestamp=IsNow(tz=timezone.utc),
run_id=IsStr(),
),
]
```
Expand Down
12 changes: 9 additions & 3 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ print(dice_result.all_messages())
content='My guess is 4',
timestamp=datetime.datetime(...),
),
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -98,6 +99,7 @@ print(dice_result.all_messages())
usage=RequestUsage(input_tokens=90, output_tokens=2),
model_name='gemini-2.5-flash',
timestamp=datetime.datetime(...),
run_id='...',
),
ModelRequest(
parts=[
Expand All @@ -107,7 +109,8 @@ print(dice_result.all_messages())
tool_call_id='pyd_ai_tool_call_id',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -118,6 +121,7 @@ print(dice_result.all_messages())
usage=RequestUsage(input_tokens=91, output_tokens=4),
model_name='gemini-2.5-flash',
timestamp=datetime.datetime(...),
run_id='...',
),
ModelRequest(
parts=[
Expand All @@ -127,7 +131,8 @@ print(dice_result.all_messages())
tool_call_id='pyd_ai_tool_call_id',
timestamp=datetime.datetime(...),
)
]
],
run_id='...',
),
ModelResponse(
parts=[
Expand All @@ -138,6 +143,7 @@ print(dice_result.all_messages())
usage=RequestUsage(input_tokens=92, output_tokens=12),
model_name='gemini-2.5-flash',
timestamp=datetime.datetime(...),
run_id='...',
),
]
"""
Expand Down
Loading