You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Convert tests to use snapshots instead of manual assertions
- Add backticks around tool_call_id in docstring
- Integrate metadata examples into existing documentation sections
- Simplify DeferredToolRequests.metadata docstring
1. The `metadata` parameter can attach arbitrary context to deferred tool calls, accessible in `DeferredToolRequests.metadata` keyed by `tool_call_id`.
180
+
179
181
_(This example is complete, it can be run "as is")_
result = ModelRetry('No result for this tool call was found.')
270
272
@@ -326,156 +328,12 @@ async def main():
326
328
"""
327
329
```
328
330
329
-
1. In reality, you'd likely use Celery or a similar task queue to run the task in the background.
330
-
2. In reality, this would typically happen in a separate process that polls for the task status or is notified when all pending tasks are complete.
331
+
1. Generate a task ID that can be tracked independently of the tool call ID.
332
+
2. The `metadata` parameter passes the `task_id` so it can be matched with results later, accessible in `DeferredToolRequests.metadata` keyed by `tool_call_id`.
333
+
3. In reality, this would typically happen in a separate process that polls for the task status or is notified when all pending tasks are complete.
331
334
332
335
_(This example is complete, it can be run "as is" — you'll need to add `asyncio.run(main())` to run `main`)_
333
336
334
-
## Attaching Metadata to Deferred Tools
335
-
336
-
Both [`CallDeferred`][pydantic_ai.exceptions.CallDeferred] and [`ApprovalRequired`][pydantic_ai.exceptions.ApprovalRequired] exceptions accept an optional `metadata` parameter that allows you to attach arbitrary context information to deferred tool calls. This metadata is available in [`DeferredToolRequests.metadata`][pydantic_ai.tools.DeferredToolRequests.metadata] keyed by tool call ID.
337
-
338
-
Common use cases include cost estimates for approval decisions and tracking information for external systems.
0 commit comments