Skip to content

feat(pydantic-ai): trace harness capability decisions - #1193

Merged
Abhijeet Prasad (AbhiPrasad) merged 5 commits into
mainfrom
devin/1795708369-pydantic-ai-harness-decision-spans
Nov 26, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 5 commits into
mainfrom
devin/1795708369-pydantic-ai-harness-decision-spans

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Braintrust now traces four Pydantic AI Harness decisions as child task
spans of the current agent run. Braintrust patches the optional Harness
package directly and keeps its spans even when native OTel/Logfire is on.
The fixed harness_* operation names follow the integration's snake_case
task names, such as agent_run.

Span Captured
harness_message_compaction Before/after message counts, strategy, and background/model-requested flags; retrieving detached background work is not traced
harness_memory_injection Source sizes, truncation, outcome, and injected character count, without memory text
harness_guardrail_block Block outcome, with direction and optional tool name in metadata; free-text reason omitted
harness_model_selection Choices, default, selected route, fallback reason, and allowlisted router metadata: mode, run step, probability, and error type
agent_run
  harness_model_selection
    agent_run [model_router]
  harness_memory_injection
  harness_message_compaction
  harness_guardrail_block

harness/test_decisions.py runs in the shared Harness nox session from
#1191. It replays real OpenAI VCR cassettes, including model selection with
native instrumentation off and on. Older Pydantic AI versions and
installations without Harness remain supported.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T16:05:41.536667Z e026f12 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e026f1250a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795708369-pydantic-ai-harness-decision-spans branch from e026f12 to 0bdb8a0 Compare November 26, 2026 16:09
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795708369-pydantic-ai-harness-decision-spans branch 2 times, most recently from edfc201 to 3baceb0 Compare November 26, 2026 17:06
devin-ai-integration Bot and others added 4 commits November 26, 2026 17:16
> 🤖 **This text was AI-generated.**

Braintrust traces show the agent and model calls but leave out what
Pydantic AI Harness did between them. Patch the optional Harness hooks
to record history compaction, memory injection, guardrail blocks, and
the model route without depending on native instrumentation.

```text
agent_run
  model_router.select
    agent_run [model_router]
  memory.inject
  compact_messages
  guardrail blocked output
```

Older Pydantic AI versions and installs without Harness continue to
use the existing agent and model patches.

Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com>
> 🤖 **This text was AI-generated.**

Run the Harness decision tests alongside the existing offline smoke
test. Reuse its agent factory, in-memory span fixture, and nox session
rather than maintaining a second Harness dependency pin or test setup.

Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com>
> 🤖 **This text was AI-generated.**

Record real OpenAI calls for compaction, memory injection, guardrail
blocks, and model routing. The tests replay those calls without
credentials and still assert the Braintrust spans and their parentage.
Routing reuses the same recording with native instrumentation on and off.

Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com>
> 🤖 **This text was AI-generated.**

A guardrail reason can quote content the policy blocked. Keep the
direction and outcome on the span, but leave the reason in the
application exception. Allowlist the router's mode, step, probability,
and error type so new upstream attributes are not captured implicitly.

Skip compaction decision spans when the result was retrieved from
detached background work. Foreground compaction still reports the
message counts.

Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1795708369-pydantic-ai-harness-decision-spans branch from 3baceb0 to 15b40d7 Compare November 26, 2026 17:19
> 🤖 **This text was AI-generated.**

Use a consistent harness_* operation name for decision spans, following
the snake_case convention of Pydantic AI task spans such as agent_run.
Put the guardrail direction in metadata so every guardrail block has
the same span name, regardless of which part of the run it blocked.

Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com>
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 7fd4377 into main Nov 26, 2026
193 of 195 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the devin/1795708369-pydantic-ai-harness-decision-spans branch November 26, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant