Skip to content

fix(pydantic-ai): preserve caller-inferred agent names - #1143

Merged
Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-pydantic-unamed-agents
Nov 18, 2026
Merged

Abhijeet Prasad (AbhiPrasad) merged 1 commit into
mainfrom
abhi-pydantic-unamed-agents

Conversation

@AbhiPrasad

Copy link
Copy Markdown
Member

🤖 This text was AI-generated.

Pydantic AI infers an unnamed agent's name from its caller. Braintrust's wrappers could cause that lookup to find an internal variable named instance, while the outer span still had a generic name.

Run Pydantic AI's lookup in the caller's scope before starting the span. Keep explicit names and infer_name=False, and defer inference for run_stream() until the caller enters the stream.

For my_agent.run_sync("hi"), the outer and inner span names become:

Before
agent_run_sync -> agent_run [instance]

After
agent_run_sync [my_agent] -> agent_run [my_agent]

Fixes #1139
Refs: #1141

> 🤖 **This text was AI-generated.**

Pydantic AI infers an unnamed agent's name from its caller. Braintrust's
wrappers could cause that lookup to find an internal variable named
`instance`, while the outer span still had a generic name.

Run Pydantic AI's lookup in the caller's scope before starting the span.
Keep explicit names and `infer_name=False`, and defer inference for
`run_stream()` until the caller enters the stream.

For `my_agent.run_sync("hi")`, the outer and inner span names become:

```text
Before
agent_run_sync -> agent_run [instance]

After
agent_run_sync [my_agent] -> agent_run [my_agent]
```

Fixes #1139
Refs: #1141
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 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-18T17:26:37.695783Z 4fb71dc 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.

@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) merged commit 64437b9 into main Nov 18, 2026
98 checks passed
@AbhiPrasad
Abhijeet Prasad (AbhiPrasad) deleted the abhi-pydantic-unamed-agents branch November 18, 2026 20:04
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.

Pydantic AI integration: unnamed agents are named "instance"

1 participant