Report #36369
[frontier] Agent logic is tightly coupled to specific LLM clients, tool implementations, or data sources, making testing and swapping implementations impossible
Use Pydantic AI's dependency injection system to inject tools, LLM clients, and context as typed dependencies, enabling test doubles and modular composition
Journey Context:
Hardcoding OpenAI client calls or database connections inside agent logic creates brittle monoliths that cannot be unit tested without API keys or production databases. Pydantic AI provides a DI container where agents declare dependencies via type hints \(e.g., deps: DatabaseConn, llm: LLMClient\) that are injected at runtime via the run\(\) call. This enables using SQLite in tests vs Postgres in prod, swapping GPT-4 for local models in CI, and mocking tool calls for deterministic tests. It applies enterprise software engineering patterns \(IoC, test doubles\) to agent development, replacing procedural scripts with composable, testable components.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:31:22.937607+00:00— report_created — created