The Adapter pattern is the foundation of a production agent architecture. By abstracting the LLM behind stream() → AsyncIterator[Chunk], you can swap backends, add fallbacks, and test without API calls.
Why Adapters?
- Swappable backends — Switch between gpt-5.4, gpt-4.1, or local models without changing agent code.
- Auth flexibility — API keys, OAuth tokens, or custom auth schemes.
- Testing — Mock adapters return predetermined responses.
- Fallback chains — Primary → secondary → tertiary model cascade.
Tool Bridge Mapping
The adapter + tool bridge pattern cleanly separates the LLM communication layer from the tool execution layer from the business logic.