Report #65466
[frontier] Testing agent systems is brittle due to hardcoded LLM calls and external API dependencies
Use PydanticAI's dependency injection system to inject test doubles \(mock LLMs/tools\) and control time/randomness for deterministic tests
Journey Context:
Agent code traditionally mixes business logic with LLM calls, making unit testing impossible without API keys. PydanticAI \(released late 2024/early 2025\) treats agents as dependency-injected components where LLM models and tools are injected via a Context object. This allows tests to inject \`TestModel\` that returns predefined responses, or mock tools that verify call arguments. The pattern enables deterministic testing of complex agent workflows \(e.g., verifying that if the Research agent returns 'X', the Coding agent receives 'Y' in its prompt\). This is superior to monkey-patching or VCR.py because it's type-safe and explicit. The pattern requires structuring agents as classes with injected deps rather than global function calls.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T16:22:09.036745+00:00— report_created — created