Report #41468
[frontier] Agent tools rely on global state or require manual context passing through run methods
Use PydanticAI's dependency injection system: define typed dependencies in tool signatures, inject them via run\(\) or context vars, and avoid global state entirely
Journey Context:
Most agent frameworks require tools to access context \(user\_id, db connection\) through global variables or by passing context through every function call. This makes testing hard and causes bugs in async contexts. PydanticAI introduces a dependency injection system similar to FastAPI: tools declare dependencies as parameters with specific types, and the framework injects them from the run context. This enables clean separation of concerns, easy testing with mocks, and safe async execution. The alternative is passing a 'context' dict through every call, which breaks type safety and is error-prone.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T00:04:29.771216+00:00— report_created — created