Don't show the first-run banner for runs an installed package starts

Merged
DO
1mo ago
+252-7

Why we make these changes

The first-run banner shows on the first uninstrumented run in a process, whoever starts it, so libraries and platforms built on Pydantic AI switch it off in production code for their own users: Airflow ("would land in the task log as ERROR lines"), Baserow, Code Puppy, Converge, Funes, and code-graph-rag, which filed it as a bug. Decided by @DouweM: stay quiet when a library runs agents, show for an application.

Design. When a run starts, the first frame outside Pydantic AI and the standard library decides it: if that frame is in site-packages or dist-packages, the run gets no banner and doesn't use up the once-per-process claim, so the user's own agent later in the same process still shows it. Where the starter can't be attributed, the banner shows as it does today: where the chain of coroutines ends (or at an anyio/trio task wrapper), the frames below belong to whatever drives the loop (uvicorn, ipykernel). run_stream_events() decides in the stack of whoever iterates it, because the run itself happens in a task of its own, and a run a UI adapter streams counts as the user's app. Rejected options: deciding at Agent(...) construction (it misattributes agents a library builds for the user, and the reverse), and deciding when the banner is displayed (the stack has crossed a task boundary by then).

For the maintainer: an app that hands agent.run to a framework which awaits it in the same coroutine chain, like Starlette's BackgroundTasks.add_task(agent.run, ...), is attributed to the framework and gets no banner. Telling that apart from a library awaiting its own run would need more than the stack.

New public surface

None.

User-visible behavior

Run started byBeforeAfter
An installed package (e.g. airflow.providers..., a uv tool CLI)bannernone, claim kept
Your own script, notebook, app, thread, anyio task, or a UI adapter served by your appbannerbanner

Verification

Tests in tests/test_display.py: sync run from an installed package, run() and run_stream_events() from one, a UI adapter behind an installed server, a server loop, an anyio task group and a thread. The wait_for case is a parametrization of the async test. I checked 13 scenarios with an inline script.

What changes for existing users

Libraries and platforms built on Pydantic AI no longer show their users our banner; application users see no change.

PR decisions

2026-10-29 · Decide library-vs-application by the run's call stack · iter -

  • Decision: first frame outside pydantic_ai/pydantic_graph/stdlib at _prepare_run; site-packages or dist-packages means library; a starter past an event loop not driven by our sync methods keeps the banner
  • Why: construction site misattributes library-built agents; display time crosses task boundaries; unknown falls back to today's behavior
  • Source: https://github.com/pydantic/pydantic-ai/tree/banner-quiet-in-libraries

2026-10-29 · pre-push review 1 of 3 at aaa15dde6422718d7fe85eb06a77aa72f1cc6b56 · iter -

2026-10-29 · pre-push review 2 of 3 at c3c8cf111c603d8d49dccb8b95185ba66a346398 · iter -

2026-10-29 · Decide run_stream_events in the iterating caller's stack; UI adapter runs keep the banner · iter -

2026-10-29 · pre-push review 3 of 3 at ca4baee4cbd0911452241c7b4fd3c76702014d6f · iter -

2026-10-29 · push after budget at d7d86f88a70359eaa6d6f94475c45529132fe7f9 · iter -

  • Decision: applied douwebot's three optional wording suggestions without a fourth local review
  • Why: comment/docstring rewording plus one docs/logfire.md sentence split; review budget exhausted at 3 of 3; fresh douwebot approval required on the new head
  • Source: https://github.com/pydantic/pydantic-ai/pull/11893

2026-10-29 · push after budget at e8c1fb997d5f428e62bc40c59f4de8e7939b7077 · iter -

  • Decision: applied douwebot's two optional refactor suggestions (named verdict, one _compiled_as test helper) without a fourth local review
  • Why: behavior-preserving refactor; the 12-scenario inline check still passes; fresh douwebot approval required
  • Source: https://github.com/pydantic/pydantic-ai/pull/11893

2026-10-29 · late report of pre-push review 2 of 3 (at c3c8cf111c), triaged at df7236ca136605f481448a3bb37a5dd7d7ea212b · iter -

  • Decision: finding 1 (anyio/trio) already fixed by review 3; finding 2 fixed by marking the boundary where a coroutine chain ends instead of at any asyncio frame (covers wait_for and uvloop), with a wait_for test; finding 3 fixed by hedging the BANNER_ENABLED docstring. Not addressed: an app handing agent.run to a framework that awaits it in the same chain (Starlette BackgroundTasks) is attributed to the framework
  • Why: budget exhausted; inline 13-scenario check passes; remediating a delivered finding needs no further dispatch
  • Source: https://github.com/pydantic/pydantic-ai/pull/11893

2026-10-29 · CI repair at fe357b79974a839872e5f31d7784680c76f6590d · iter -

  • Decision: skip the wait_for parametrization before 3.12
  • Why: 3.11 asyncio.wait_for wraps the coroutine in a Task, so the starter is past a task boundary and keeps today's banner (safe direction); test-only delta
  • Source: https://github.com/pydantic/pydantic-ai/pull/11893

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.