Repository navigation
Commit 825f457
fix(pydantic-ai): trace harness background tool execution (#1196)
## Summary
Pydantic AI Harness background tools (`background_tools/_capability.py`)
schedule the real handler and return a pending receipt immediately. Our
`tool` span used to end at dispatch, recording only the receipt. Because
`context.py` skips ended spans, the later child agent run attached
directly to the parent agent.
An optional Harness patcher, skipped on pydantic-ai 1.x, now produces
ONE `tool` span per model tool call, following the instrumentation spec.
That span covers the actual run-scoped handler: it records the
model-supplied arguments and the handler's real return value or error.
The handler runs with that span current:
```text
before: agent -> tool (pending receipt) agent -> child agent run
after: agent -> tool (args, real result/error) -> child agent run
```
- The pending receipt is still returned to the model but creates no
span; detached submission/polling lifecycles are not auto-traced.
- Braintrust spans are kept regardless of native Pydantic/Logfire
instrumentation.
- Direct `Agent.iter()` now passes its root span to step persistence, so
the lineage metadata from #1194 stays attached alongside the #1192 iter
root span.
Tests: success and failure regressions in
`pydantic_ai/harness/test_background_tools.py` replay real OpenAI VCR
cassettes (`harness/cassettes/latest/`) in the Harness nox session from
#1191.
---------
Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>1 parent 19afe35 commit 825f457
7 files changed
Lines changed: 993 additions & 20 deletions
File tree
- py/src/braintrust/integrations/pydantic_ai
- harness
- cassettes/latest
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments