Report #67898
[frontier] Agent tools tightly coupled to external services making unit testing impossible without mocking network calls
Use PydanticAI's dependency injection system to declare external services \(databases, APIs\) as abstract dependencies in tool signatures, allowing test doubles to be injected during unit tests while real implementations are provided at runtime.
Journey Context:
Agent tools often hardcode HTTP clients or database connections, requiring brittle monkey-patching for testing. PydanticAI \(late 2024/early 2025\) treats agents and tools as dependency-injectable components, similar to FastAPI. Tools declare dependencies \(e.g., \`db: Database\`\) in their signatures, and the framework resolves them from a context. This enables 'testability by design'—replacing production databases with in-memory fakes without monkey-patching—crucial for high-stakes agents where tool behavior must be verified against deterministic test fixtures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:26:57.276412+00:00— report_created — created