Report #94407
[frontier] Agent code becomes tightly coupled to specific LLM providers or tool implementations, making testing and swapping models difficult
Use PydanticAI's dependency injection system: define abstract protocols for tools/LLMs, register dependencies with @agent.tool and RunContext, inject test doubles via override dependencies in unit tests; compose complex agents from smaller reusable components
Journey Context:
Hard-coded client initialization prevents A/B testing models or mocking APIs; DI enables swapping OpenAI for Anthropic via configuration, injecting test spies for assertions, and building modular agent systems where components are composed rather than inherited.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:02:57.308639+00:00— report_created — created