1
Domain Layer
Pure entities and business invariants with zero framework dependencies. Contains data contracts like Task, AgentCapability, RoutingDecision, and the EvidenceEvaluator ranking logic. It can be tested instantly without network access or databases.
2
Application Layer
Coordinates workflows and orchestration use cases such as SubmitTask and FindCandidatesQuery. Defines abstract ports (interfaces like TaskDispatcher and StateReader) without knowing whether they are implemented by Redis, HTTP, or memory fakes.
3
Presentation Layer
The delivery mechanism: FastAPI routes (/api/tasks, /api/agents, /health) and the browser-based Prototype Console SPA. Never interacts directly with domain logic; it passes inputs to application use cases and renders returned views.
4
Infrastructure Layer
Houses concrete implementations of application ports: Redis list queues, Redis stream publishers, Tavily web search clients, and Cloudflare Workers AI inference connectors. Adapters can be replaced or mocked without modifying business rules.
Why This Matters for Autonomous Agents
AI frameworks frequently blur the line between model prompts, network transport, and business rules. By strictly enforcing Clean Architecture boundaries:
- Replaceable AI Providers: We can switch from Cloudflare Workers AI to a local Ollama model or cloud API by writing an adapter—zero domain changes required.
- Fast Deterministic Testing: Fast deterministic automated testing without requiring live infrastructure or external APIs, using lightweight in-memory fake ports.
- Credential Isolation: All provider tokens remain strictly inside containerized infrastructure adapters and are never exposed to browser consoles or client payloads.