Project 6: Personal AI Command Center

Project 6: Personal AI Command Center

The Synthesis Project - Everything you have learned comes together here


Learning Objectives

By completing this project, you will master:

  • Multi-agent orchestration - Design and implement a system where multiple specialized agents collaborate to complete complex tasks, understanding when to use sequential vs. parallel execution patterns
  • Agent-to-agent communication - Build shared context stores and message passing mechanisms that allow agents to exchange information, results, and delegate subtasks
  • Task decomposition and planning - Implement an orchestration layer that breaks natural language requests into executable plans, selecting appropriate agents and managing dependencies
  • Concurrent streaming in web UIs - Create React components that stream responses from multiple agents simultaneously while maintaining UI responsiveness
  • Provider abstraction at scale - Route different agents to optimal models based on task requirements, cost constraints, and performance characteristics
  • Production cost management - Implement rate limiting, usage tracking, and budget controls across multiple agents and providers
  • Full-stack AI application architecture - Integrate CLI, web dashboard, and API interfaces into a cohesive system with proper error handling and observability

Deep Theoretical Foundation

Before building a multi-agent system, you must deeply understand the patterns that make them work. This section explores the theory behind each major component.

Multi-Agent Orchestration Patterns

Multi-agent systems come in several architectural patterns, each with distinct tradeoffs:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    MULTI-AGENT ORCHESTRATION PATTERNS                       โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   PATTERN 1: CENTRALIZED ORCHESTRATOR                                      โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                     โ”‚
โ”‚                                                                             โ”‚
โ”‚                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                      โ”‚
โ”‚                    โ”‚   Orchestrator   โ”‚ โ—„โ”€โ”€โ”€ Single brain                   โ”‚
โ”‚                    โ”‚   (Planner)      โ”‚       controls all                  โ”‚
โ”‚                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                      โ”‚
โ”‚                             โ”‚                                               โ”‚
โ”‚           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                            โ”‚
โ”‚           โ–ผ                 โ–ผ                 โ–ผ                            โ”‚
โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                        โ”‚
โ”‚      โ”‚ Agent A โ”‚      โ”‚ Agent B โ”‚       โ”‚ Agent C โ”‚                        โ”‚
โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                        โ”‚
โ”‚                                                                             โ”‚
โ”‚   Pros: Simple to reason about, clear control flow                         โ”‚
โ”‚   Cons: Single point of failure, orchestrator bottleneck                   โ”‚
โ”‚   Use when: Tasks have clear decomposition, agents don't need to negotiate โ”‚
โ”‚                                                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   PATTERN 2: HIERARCHICAL DELEGATION                                       โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                         โ”‚
โ”‚                                                                             โ”‚
โ”‚                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                      โ”‚
โ”‚                    โ”‚   Supervisor     โ”‚ โ—„โ”€โ”€โ”€ High-level planning            โ”‚
โ”‚                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                      โ”‚
โ”‚                             โ”‚                                               โ”‚
โ”‚           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                            โ”‚
โ”‚           โ–ผ                                   โ–ผ                            โ”‚
โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                        โ”‚
โ”‚      โ”‚ Manager โ”‚                        โ”‚ Manager โ”‚ โ—„โ”€โ”€โ”€ Domain managers   โ”‚
โ”‚      โ”‚   A     โ”‚                        โ”‚   B     โ”‚                        โ”‚
โ”‚      โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                        โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                        โ”‚
โ”‚           โ”‚                                  โ”‚                             โ”‚
โ”‚      โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”                        โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”                        โ”‚
โ”‚      โ–ผ         โ–ผ                        โ–ผ         โ–ผ                        โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”                      โ”‚
โ”‚  โ”‚Workerโ”‚ โ”‚Workerโ”‚                  โ”‚Workerโ”‚ โ”‚Workerโ”‚ โ—„โ”€โ”€โ”€ Task executors  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ”‚
โ”‚                                                                             โ”‚
โ”‚   Pros: Scales well, domain expertise isolation                            โ”‚
โ”‚   Cons: Complex communication, latency accumulates                         โ”‚
โ”‚   Use when: Large systems, clear domain boundaries                         โ”‚
โ”‚                                                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   PATTERN 3: PEER-TO-PEER COLLABORATION                                    โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                     โ”‚
โ”‚                                                                             โ”‚
โ”‚               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                              โ”‚
โ”‚               โ”‚ Agent A โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚ Agent B โ”‚                              โ”‚
โ”‚               โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                              โ”‚
โ”‚                    โ”‚                   โ”‚                                    โ”‚
โ”‚                    โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚                                    โ”‚
โ”‚                    โ””โ”€โ”€โ”€โ–บโ”‚ Agent C โ”‚โ—„โ”€โ”€โ”€โ”˜                                    โ”‚
โ”‚                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                         โ”‚
โ”‚                                                                             โ”‚
โ”‚   Pros: Flexible, resilient to failures, emergent behavior                 โ”‚
โ”‚   Cons: Hard to debug, unpredictable execution                             โ”‚
โ”‚   Use when: Creative tasks, exploration, research                          โ”‚
โ”‚                                                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   PATTERN 4: PIPELINE (Sequential Chain)                                   โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                     โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”             โ”‚
โ”‚   โ”‚ Agent A โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚ Agent B โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚ Agent C โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚ Agent D โ”‚             โ”‚
โ”‚   โ”‚ (Input) โ”‚     โ”‚(Process)โ”‚     โ”‚(Process)โ”‚     โ”‚(Output) โ”‚             โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜             โ”‚
โ”‚                                                                             โ”‚
โ”‚   Pros: Predictable, easy to test, clear data flow                         โ”‚
โ”‚   Cons: Slow (serial), no parallelism                                      โ”‚
โ”‚   Use when: Data transformation, document processing                       โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

For the Personal AI Command Center, we use Pattern 1 (Centralized Orchestrator) because:

  • Tasks have clear decomposition (โ€œresearch X, then email Yโ€)
  • Agents have distinct responsibilities that rarely overlap
  • We need predictable execution for cost tracking
  • Debugging requires clear visibility into control flow

Agent-to-Agent Communication Strategies

Agents need to share information. There are three primary strategies:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              AGENT COMMUNICATION STRATEGIES                                 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   STRATEGY 1: SHARED CONTEXT STORE (Blackboard Pattern)                    โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                     โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                              โ”‚
โ”‚   โ”‚ Agent A โ”‚     โ”‚ Agent B โ”‚     โ”‚ Agent C โ”‚                              โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                              โ”‚
โ”‚        โ”‚    write      โ”‚    read       โ”‚                                    โ”‚
โ”‚        โ–ผ               โ–ผ               โ–ผ                                    โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚
โ”‚   โ”‚                 SHARED CONTEXT STORE                   โ”‚                โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚                โ”‚
โ”‚   โ”‚  โ”‚ research_results: { facts: [...], sources: [...] }โ”‚ โ”‚                โ”‚
โ”‚   โ”‚  โ”‚ user_preferences: { tone: "formal", ... }         โ”‚ โ”‚                โ”‚
โ”‚   โ”‚  โ”‚ task_context: { goal: "summarize research", ... } โ”‚ โ”‚                โ”‚
โ”‚   โ”‚  โ”‚ conversation_history: [ ... ]                     โ”‚ โ”‚                โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚                โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚
โ”‚                                                                             โ”‚
โ”‚   Implementation: In-memory Map, Redis, or database                        โ”‚
โ”‚   Pros: Simple, decoupled agents                                           โ”‚
โ”‚   Cons: Requires coordination on data format                               โ”‚
โ”‚                                                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   STRATEGY 2: MESSAGE PASSING                                              โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                   โ”‚
โ”‚   โ”‚ Agent A โ”‚โ”€โ”€โ”€message()โ”€โ”€โ”€โ–บโ”‚ Agent B โ”‚                                   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                                   โ”‚
โ”‚        โ”‚                          โ”‚                                         โ”‚
โ”‚        โ”‚โ—„โ”€โ”€โ”€โ”€response()โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                         โ”‚
โ”‚                                                                             โ”‚
โ”‚   Messages: { type: 'task', payload: {...}, from: 'research', to: 'email' }โ”‚
โ”‚                                                                             โ”‚
โ”‚   Implementation: Event emitters, message queues                           โ”‚
โ”‚   Pros: Explicit communication, traceable                                  โ”‚
โ”‚   Cons: Tighter coupling between agents                                    โ”‚
โ”‚                                                                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   STRATEGY 3: ORCHESTRATOR MEDIATION                                       โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                        โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”‚
โ”‚   โ”‚ Agent A โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚ Agent B โ”‚               โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜                                    โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜               โ”‚
โ”‚        โ”‚                                              โ”‚                     โ”‚
โ”‚        โ–ผ                                              โ–ผ                     โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”‚
โ”‚   โ”‚                    ORCHESTRATOR                       โ”‚                 โ”‚
โ”‚   โ”‚  โ€ข Receives output from Agent A                      โ”‚                 โ”‚
โ”‚   โ”‚  โ€ข Transforms/filters as needed                      โ”‚                 โ”‚
โ”‚   โ”‚  โ€ข Passes to Agent B as input                        โ”‚                 โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ”‚
โ”‚                                                                             โ”‚
โ”‚   Implementation: Orchestrator manages all data flow                       โ”‚
โ”‚   Pros: Full control, easy to modify handoffs                              โ”‚
โ”‚   Cons: Orchestrator becomes complex                                       โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

We use a hybrid approach: Shared Context Store + Orchestrator Mediation. The orchestrator controls execution flow while agents read/write to a shared context for accumulated knowledge.

Task Decomposition and Planning

The orchestratorโ€™s core job is to transform natural language into an executable plan:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   TASK DECOMPOSITION PIPELINE                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   User Input: "Research quantum computing, then draft an email to          โ”‚
โ”‚                my team summarizing the key points"                          โ”‚
โ”‚                                                                             โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚   โ”‚  STEP 1: INTENT EXTRACTION (generateObject)                        โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ”‚  Schema: {                                                         โ”‚    โ”‚
โ”‚   โ”‚    primaryIntent: "compose_email" | "research" | "schedule" | ..., โ”‚    โ”‚
โ”‚   โ”‚    secondaryIntents: [...],                                        โ”‚    โ”‚
โ”‚   โ”‚    entities: { topic: string, recipient: string, ... },            โ”‚    โ”‚
โ”‚   โ”‚    constraints: { deadline?: Date, tone?: string, ... }            โ”‚    โ”‚
โ”‚   โ”‚  }                                                                 โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ”‚  Output: {                                                         โ”‚    โ”‚
โ”‚   โ”‚    primaryIntent: "compose_email",                                 โ”‚    โ”‚
โ”‚   โ”‚    secondaryIntents: ["research"],                                 โ”‚    โ”‚
โ”‚   โ”‚    entities: { topic: "quantum computing", recipient: "team" },    โ”‚    โ”‚
โ”‚   โ”‚    constraints: { tone: "professional" }                           โ”‚    โ”‚
โ”‚   โ”‚  }                                                                 โ”‚    โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚   โ”‚  STEP 2: AGENT SELECTION                                           โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ”‚  Agent Registry:                                                   โ”‚    โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚    โ”‚
โ”‚   โ”‚  โ”‚ Agent       โ”‚ Capabilities                                   โ”‚ โ”‚    โ”‚
โ”‚   โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚    โ”‚
โ”‚   โ”‚  โ”‚ research    โ”‚ search, read, extract, summarize               โ”‚ โ”‚    โ”‚
โ”‚   โ”‚  โ”‚ email       โ”‚ compose, send, list, search_inbox              โ”‚ โ”‚    โ”‚
โ”‚   โ”‚  โ”‚ calendar    โ”‚ schedule, check_availability, invite           โ”‚ โ”‚    โ”‚
โ”‚   โ”‚  โ”‚ code        โ”‚ review, explain, refactor, test                โ”‚ โ”‚    โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ”‚  Matching: "research" โ†’ research agent, "compose_email" โ†’ email   โ”‚    โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚   โ”‚  STEP 3: DEPENDENCY ANALYSIS                                       โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ”‚  "Research THEN email" โ†’ research must complete before email      โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ”‚  Dependency Graph:                                                 โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ”‚     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                              โ”‚    โ”‚
โ”‚   โ”‚     โ”‚   research   โ”‚                                              โ”‚    โ”‚
โ”‚   โ”‚     โ”‚   agent      โ”‚                                              โ”‚    โ”‚
โ”‚   โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                              โ”‚    โ”‚
โ”‚   โ”‚            โ”‚ output: research_results                             โ”‚    โ”‚
โ”‚   โ”‚            โ–ผ                                                      โ”‚    โ”‚
โ”‚   โ”‚     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                              โ”‚    โ”‚
โ”‚   โ”‚     โ”‚    email     โ”‚ โ—„โ”€โ”€ input: research_results                  โ”‚    โ”‚
โ”‚   โ”‚     โ”‚   agent      โ”‚                                              โ”‚    โ”‚
โ”‚   โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                              โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚                           โ”‚                                                 โ”‚
โ”‚                           โ–ผ                                                 โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚   โ”‚  STEP 4: EXECUTION PLAN GENERATION                                 โ”‚    โ”‚
โ”‚   โ”‚                                                                    โ”‚    โ”‚
โ”‚   โ”‚  {                                                                 โ”‚    โ”‚
โ”‚   โ”‚    steps: [                                                        โ”‚    โ”‚
โ”‚   โ”‚      {                                                             โ”‚    โ”‚
โ”‚   โ”‚        id: "step_1",                                               โ”‚    โ”‚
โ”‚   โ”‚        agent: "research",                                          โ”‚    โ”‚
โ”‚   โ”‚        action: "research_topic",                                   โ”‚    โ”‚
โ”‚   โ”‚        input: { topic: "quantum computing" },                      โ”‚    โ”‚
โ”‚   โ”‚        outputKey: "research_results"                               โ”‚    โ”‚
โ”‚   โ”‚      },                                                            โ”‚    โ”‚
โ”‚   โ”‚      {                                                             โ”‚    โ”‚
โ”‚   โ”‚        id: "step_2",                                               โ”‚    โ”‚
โ”‚   โ”‚        agent: "email",                                             โ”‚    โ”‚
โ”‚   โ”‚        action: "compose_email",                                    โ”‚    โ”‚
โ”‚   โ”‚        input: {                                                    โ”‚    โ”‚
โ”‚   โ”‚          content: "{{research_results}}",                          โ”‚    โ”‚
โ”‚   โ”‚          recipient: "team",                                        โ”‚    โ”‚
โ”‚   โ”‚          tone: "professional"                                      โ”‚    โ”‚
โ”‚   โ”‚        },                                                          โ”‚    โ”‚
โ”‚   โ”‚        dependsOn: ["step_1"]                                       โ”‚    โ”‚
โ”‚   โ”‚      }                                                             โ”‚    โ”‚
โ”‚   โ”‚    ]                                                               โ”‚    โ”‚
โ”‚   โ”‚  }                                                                 โ”‚    โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The key insight from โ€œArtificial Intelligence: A Modern Approachโ€ (Russell & Norvig, Ch. 2): agents are defined by their percepts (what they sense) and actions (what they can do). The orchestratorโ€™s job is to match user intent to agent capabilities.

Shared Context Stores and Memory

Effective multi-agent systems require persistent memory that survives across agent invocations:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     CONTEXT STORE ARCHITECTURE                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                      CONTEXT STORE LAYERS                            โ”‚  โ”‚
โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   LAYER 1: SESSION CONTEXT (volatile, per-request)                  โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                     โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Current task plan                                                โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Intermediate results from agents                                 โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Error states and retries                                         โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Storage: In-memory Map                                             โ”‚  โ”‚
โ”‚   โ”‚   Lifetime: Single multi-agent execution                             โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   LAYER 2: CONVERSATION CONTEXT (short-term)                        โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                         โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Recent messages (last N turns)                                   โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Current user goal                                                โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Active agent states                                              โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Storage: In-memory with optional Redis backup                     โ”‚  โ”‚
โ”‚   โ”‚   Lifetime: User session (minutes to hours)                         โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   LAYER 3: USER CONTEXT (long-term)                                 โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                  โ”‚  โ”‚
โ”‚   โ”‚   โ€ข User preferences (communication tone, email signature)          โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Learned patterns (frequently used agents, common requests)      โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Contact information, calendars                                  โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Storage: Database (SQLite, Postgres)                              โ”‚  โ”‚
โ”‚   โ”‚   Lifetime: Persistent across sessions                               โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   LAYER 4: KNOWLEDGE BASE (accumulated knowledge)                   โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                      โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Research results indexed by topic                               โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Code snippets and explanations                                  โ”‚  โ”‚
โ”‚   โ”‚   โ€ข Email templates and drafts                                       โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Storage: Vector database (for semantic search)                    โ”‚  โ”‚
โ”‚   โ”‚   Lifetime: Permanent, grows over time                              โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                             โ”‚
โ”‚   CONTEXT FLOW DURING EXECUTION:                                           โ”‚
โ”‚                                                                             โ”‚
โ”‚   User Request                                                              โ”‚
โ”‚        โ”‚                                                                    โ”‚
โ”‚        โ–ผ                                                                    โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    Load user prefs    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                  โ”‚
โ”‚   โ”‚ Orchestrator โ”‚ โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โ”‚ User Context โ”‚                  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                  โ”‚
โ”‚          โ”‚                                                                   โ”‚
โ”‚          โ”‚ Create session context                                           โ”‚
โ”‚          โ–ผ                                                                   โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                          โ”‚
โ”‚   โ”‚   Session    โ”‚                                                          โ”‚
โ”‚   โ”‚   Context    โ”‚โ—„โ”€โ”€โ”€โ”€โ”€ Intermediate results written here                  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                          โ”‚
โ”‚          โ”‚                                                                   โ”‚
โ”‚          โ”‚ Agent reads context, executes, writes results                    โ”‚
โ”‚          โ–ผ                                                                   โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     Save knowledge     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”‚
โ”‚   โ”‚    Agent     โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚  Knowledge   โ”‚                 โ”‚
โ”‚   โ”‚   Output     โ”‚                         โ”‚     Base     โ”‚                 โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

This layered approach is inspired by โ€œDesigning Data-Intensive Applicationsโ€ (Kleppmann, Ch. 11), which discusses event sourcing and state management in distributed systems.

Concurrent Streaming in Web UIs

Streaming multiple agent responses simultaneously requires careful React architecture:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   CONCURRENT STREAMING ARCHITECTURE                         โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   BROWSER                                            SERVER                 โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                            โ”€โ”€โ”€โ”€โ”€โ”€                 โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚          React Dashboard              โ”‚     โ”‚   Next.js API Route    โ”‚  โ”‚
โ”‚   โ”‚                                       โ”‚     โ”‚                        โ”‚  โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚     โ”‚  Orchestrator creates  โ”‚  โ”‚
โ”‚   โ”‚  โ”‚   AgentStreamManager            โ”‚ โ”‚     โ”‚  execution plan:       โ”‚  โ”‚
โ”‚   โ”‚  โ”‚                                 โ”‚ โ”‚     โ”‚                        โ”‚  โ”‚
โ”‚   โ”‚  โ”‚  activeStreams: Map<string,     โ”‚ โ”‚     โ”‚  Step 1: Research      โ”‚  โ”‚
โ”‚   โ”‚  โ”‚    ReadableStream>              โ”‚ โ”‚     โ”‚  Step 2: Email         โ”‚  โ”‚
โ”‚   โ”‚  โ”‚                                 โ”‚ โ”‚     โ”‚                        โ”‚  โ”‚
โ”‚   โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚ โ”‚     โ”‚  For parallel steps,   โ”‚  โ”‚
โ”‚   โ”‚  โ”‚  โ”‚ useAgentStream('research')โ”‚  โ”‚ โ”‚     โ”‚  multiple SSE streams  โ”‚  โ”‚
โ”‚   โ”‚  โ”‚  โ”‚  - text: "Searching..."   โ”‚  โ”‚โ—„โ”œโ”€โ”€โ”€โ”€โ”€โ”ค  are created           โ”‚  โ”‚
โ”‚   โ”‚  โ”‚  โ”‚  - status: "streaming"    โ”‚  โ”‚ โ”‚     โ”‚                        โ”‚  โ”‚
โ”‚   โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚ โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚   โ”‚  โ”‚                                 โ”‚ โ”‚                                  โ”‚
โ”‚   โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚ โ”‚     SSE Stream Format:          โ”‚
โ”‚   โ”‚  โ”‚  โ”‚ useAgentStream('email')   โ”‚  โ”‚ โ”‚     โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€           โ”‚
โ”‚   โ”‚  โ”‚  โ”‚  - text: ""               โ”‚  โ”‚ โ”‚     event: agent_start          โ”‚
โ”‚   โ”‚  โ”‚  โ”‚  - status: "pending"      โ”‚  โ”‚ โ”‚     data: {"agent":"research"}  โ”‚
โ”‚   โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚ โ”‚                                  โ”‚
โ”‚   โ”‚  โ”‚                                 โ”‚ โ”‚     event: agent_token           โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚     data: {"agent":"research",  โ”‚
โ”‚   โ”‚                                       โ”‚            "token":"Quantum"}   โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚                                  โ”‚
โ”‚   โ”‚  โ”‚      Render Components          โ”‚ โ”‚     event: agent_complete        โ”‚
โ”‚   โ”‚  โ”‚                                 โ”‚ โ”‚     data: {"agent":"research",  โ”‚
โ”‚   โ”‚  โ”‚  <ResearchAgentCard             โ”‚ โ”‚            "result":{...}}      โ”‚
โ”‚   โ”‚  โ”‚    stream={researchStream}      โ”‚ โ”‚                                  โ”‚
โ”‚   โ”‚  โ”‚    status="streaming" />        โ”‚ โ”‚     event: agent_start          โ”‚
โ”‚   โ”‚  โ”‚                                 โ”‚ โ”‚     data: {"agent":"email"}     โ”‚
โ”‚   โ”‚  โ”‚  <EmailAgentCard                โ”‚ โ”‚                                  โ”‚
โ”‚   โ”‚  โ”‚    stream={emailStream}         โ”‚ โ”‚     ...                          โ”‚
โ”‚   โ”‚  โ”‚    status="pending" />          โ”‚ โ”‚                                  โ”‚
โ”‚   โ”‚  โ”‚                                 โ”‚ โ”‚                                  โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚                                  โ”‚
โ”‚   โ”‚                                       โ”‚                                  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                  โ”‚
โ”‚                                                                             โ”‚
โ”‚   KEY REACT PATTERNS (from "Learning React" Ch. 8, 12):                    โ”‚
โ”‚                                                                             โ”‚
โ”‚   1. useReducer for complex stream state                                   โ”‚
โ”‚   2. useSyncExternalStore for SSE subscription                             โ”‚
โ”‚   3. Suspense boundaries for loading states                                โ”‚
โ”‚   4. Error boundaries for agent failures                                   โ”‚
โ”‚   5. React.memo for preventing unnecessary re-renders                      โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Cost Management and Rate Limiting

Production AI systems must control costs across multiple agents and providers:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     COST MANAGEMENT ARCHITECTURE                            โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                      COST TRACKING LAYERS                            โ”‚  โ”‚
โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   LAYER 1: REQUEST LEVEL                                            โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                              โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Each LLM call records:                                            โ”‚  โ”‚
โ”‚   โ”‚   {                                                                  โ”‚  โ”‚
โ”‚   โ”‚     requestId: "req_abc123",                                         โ”‚  โ”‚
โ”‚   โ”‚     agentId: "research",                                             โ”‚  โ”‚
โ”‚   โ”‚     provider: "anthropic",                                           โ”‚  โ”‚
โ”‚   โ”‚     model: "claude-opus-4",                                                โ”‚  โ”‚
โ”‚   โ”‚     inputTokens: 1500,                                               โ”‚  โ”‚
โ”‚   โ”‚     outputTokens: 800,                                               โ”‚  โ”‚
โ”‚   โ”‚     cost: 0.0234,  // calculated from token counts                   โ”‚  โ”‚
โ”‚   โ”‚     latency: 2340, // ms                                             โ”‚  โ”‚
โ”‚   โ”‚     timestamp: "2025-12-26T10:34:00Z"                                โ”‚  โ”‚
โ”‚   โ”‚   }                                                                  โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   LAYER 2: AGENT LEVEL                                              โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                               โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Aggregated per agent:                                             โ”‚  โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ Agent      โ”‚ Requests โ”‚ Tokens   โ”‚ Cost    โ”‚ Avg Latency   โ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ research   โ”‚ 145      โ”‚ 892,400  โ”‚ $12.30  โ”‚ 3.2s          โ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ email      โ”‚ 89       โ”‚ 234,500  โ”‚ $5.20   โ”‚ 1.8s          โ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ calendar   โ”‚ 67       โ”‚ 98,200   โ”‚ $2.15   โ”‚ 0.9s          โ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ code       โ”‚ 34       โ”‚ 456,700  โ”‚ $3.80   โ”‚ 4.1s          โ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   LAYER 3: BUDGET CONTROLS                                          โ”‚  โ”‚
โ”‚   โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                           โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Per-Agent Budgets:          Global Budgets:                       โ”‚  โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ Agent      โ”‚ Daily $  โ”‚   โ”‚ Daily limit:   $50.00          โ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค   โ”‚ Monthly limit: $500.00         โ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ research   โ”‚ $10.00   โ”‚   โ”‚ Alert at:      80% threshold   โ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ email      โ”‚ $5.00    โ”‚   โ”‚ Action:        Notify + degradeโ”‚   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ calendar   โ”‚ $3.00    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ code       โ”‚ $8.00    โ”‚                                        โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                        โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                             โ”‚
โ”‚   RATE LIMITING STRATEGY:                                                  โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚                                                                    โ”‚   โ”‚
โ”‚   โ”‚   Token Bucket Algorithm (per provider):                          โ”‚   โ”‚
โ”‚   โ”‚                                                                    โ”‚   โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   Bucket     โ”‚ capacity: 100 requests                         โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   โ—โ—โ—โ—โ—โ—โ—โ—โ—โ— โ”‚ refill: 10 requests/second                     โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   โ—โ—โ—โ—โ—โ—โ—    โ”‚ current: 17 tokens                             โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                โ”‚   โ”‚
โ”‚   โ”‚                                                                    โ”‚   โ”‚
โ”‚   โ”‚   When bucket empty: Queue requests OR fallback to cheaper model  โ”‚   โ”‚
โ”‚   โ”‚                                                                    โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                                             โ”‚
โ”‚   GRACEFUL DEGRADATION:                                                    โ”‚
โ”‚                                                                             โ”‚
โ”‚   Budget exceeded?                                                         โ”‚
โ”‚     โ”œโ”€โ”€ Option 1: Switch to cheaper model (gpt-4o โ†’ gpt-4o-mini)          โ”‚
โ”‚     โ”œโ”€โ”€ Option 2: Reduce max tokens                                       โ”‚
โ”‚     โ”œโ”€โ”€ Option 3: Queue non-urgent requests                               โ”‚
โ”‚     โ””โ”€โ”€ Option 4: Notify user and pause                                   โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Event-Driven Architecture for Agents

The AI SDKโ€™s telemetry and event system enables powerful observability:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    EVENT-DRIVEN AGENT ARCHITECTURE                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   "Designing Data-Intensive Applications" (Kleppmann, Ch. 11) teaches:     โ”‚
โ”‚   โ€ข Events as first-class citizens                                         โ”‚
โ”‚   โ€ข Event sourcing for auditability                                        โ”‚
โ”‚   โ€ข Stream processing for real-time analytics                              โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                        EVENT FLOW                                    โ”‚  โ”‚
โ”‚   โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   User Request                                                       โ”‚  โ”‚
โ”‚   โ”‚        โ”‚                                                             โ”‚  โ”‚
โ”‚   โ”‚        โ–ผ                                                             โ”‚  โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                    โ”‚  โ”‚
โ”‚   โ”‚   โ”‚ Orchestratorโ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–บ EVENT: task_started                        โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜        { task_id, user_input, timestamp }         โ”‚  โ”‚
โ”‚   โ”‚          โ”‚                                                           โ”‚  โ”‚
โ”‚   โ”‚          โ–ผ                                                           โ”‚  โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                    โ”‚  โ”‚
โ”‚   โ”‚   โ”‚   Planner   โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–บ EVENT: plan_created                        โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜        { task_id, steps: [...], agents: [...] }   โ”‚  โ”‚
โ”‚   โ”‚          โ”‚                                                           โ”‚  โ”‚
โ”‚   โ”‚          โ–ผ                                                           โ”‚  โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                    โ”‚  โ”‚
โ”‚   โ”‚   โ”‚   Agent     โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–บ EVENT: agent_started                       โ”‚  โ”‚
โ”‚   โ”‚   โ”‚  Executor   โ”‚        { task_id, agent_id, step_id }             โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚                                                    โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–บ EVENT: llm_request                         โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚        { agent_id, provider, model, prompt }      โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚                                                    โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–บ EVENT: llm_token (streaming)               โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚        { agent_id, token }                        โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚                                                    โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–บ EVENT: tool_called                         โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚        { agent_id, tool_name, args }              โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚                                                    โ”‚  โ”‚
โ”‚   โ”‚   โ”‚             โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–บ EVENT: agent_completed                     โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜        { agent_id, result, tokens, cost }         โ”‚  โ”‚
โ”‚   โ”‚          โ”‚                                                           โ”‚  โ”‚
โ”‚   โ”‚          โ–ผ                                                           โ”‚  โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                    โ”‚  โ”‚
โ”‚   โ”‚   โ”‚  Aggregator โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ–บ EVENT: task_completed                      โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        { task_id, total_cost, latency }           โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                             โ”‚
โ”‚   EVENT CONSUMERS:                                                         โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚
โ”‚   โ”‚   Dashboard     โ”‚  โ”‚  Cost Tracker   โ”‚  โ”‚   Log Storage   โ”‚           โ”‚
โ”‚   โ”‚   (Real-time)   โ”‚  โ”‚  (Aggregation)  โ”‚  โ”‚   (Audit)       โ”‚           โ”‚
โ”‚   โ”‚                 โ”‚  โ”‚                 โ”‚  โ”‚                 โ”‚           โ”‚
โ”‚   โ”‚ Subscribes to:  โ”‚  โ”‚ Subscribes to:  โ”‚  โ”‚ Subscribes to:  โ”‚           โ”‚
โ”‚   โ”‚ โ€ข agent_started โ”‚  โ”‚ โ€ข llm_request   โ”‚  โ”‚ โ€ข ALL events    โ”‚           โ”‚
โ”‚   โ”‚ โ€ข llm_token     โ”‚  โ”‚ โ€ข agent_completeโ”‚  โ”‚                 โ”‚           โ”‚
โ”‚   โ”‚ โ€ข agent_completeโ”‚  โ”‚                 โ”‚  โ”‚ Storage: S3,    โ”‚           โ”‚
โ”‚   โ”‚                 โ”‚  โ”‚ Computes:       โ”‚  โ”‚ ClickHouse      โ”‚           โ”‚
โ”‚   โ”‚ Updates:        โ”‚  โ”‚ โ€ข Running total โ”‚  โ”‚                 โ”‚           โ”‚
โ”‚   โ”‚ โ€ข Live streams  โ”‚  โ”‚ โ€ข Budget alerts โ”‚  โ”‚                 โ”‚           โ”‚
โ”‚   โ”‚ โ€ข Agent status  โ”‚  โ”‚ โ€ข Usage reports โ”‚  โ”‚                 โ”‚           โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Complete Project Specification

Web Dashboard Requirements

The web dashboard is the primary interface for monitoring and interacting with your AI Command Center.

Functional Requirements:

  1. Agent Status Panel
    • Display all registered agents with real-time status (idle, processing, error)
    • Show current task for active agents
    • Indicate which model/provider each agent uses
  2. Conversation Interface
    • Natural language input field
    • Display orchestratorโ€™s execution plan before running
    • Stream agent responses in real-time
    • Show handoffs between agents visually
  3. Activity Feed
    • Chronological log of all agent actions
    • Filter by agent, date, task type
    • Click to expand full details
  4. Cost Dashboard
    • Real-time cost tracking per agent
    • Daily/weekly/monthly views
    • Budget progress bars with alerts
    • Cost breakdown by provider and model
  5. Settings Panel
    • Configure agent preferences (models, system prompts)
    • Set budget limits
    • Manage API keys (securely)
    • User preferences (tone, email signature)

CLI Interface Requirements

The CLI provides power-user access to all Command Center functionality.

Commands:

# Natural language interaction
ai "Research quantum computing and email summary to team"

# Direct agent invocation
ai research "quantum computing"
ai email draft --to "team" --subject "Research Summary"
ai calendar schedule "Team meeting" --time "tomorrow 2pm"
ai code review PR#123

# System management
ai status                    # Show all agents and their status
ai logs --agent research     # View agent logs
ai cost --period month       # Show cost breakdown
ai config set research.model claude-opus-4  # Configure agents

# Interactive mode
ai interactive               # REPL for multi-turn conversations

API Endpoints

RESTful API following best practices from โ€œDesign and Build Great Web APIsโ€ (Amundsen, Ch. 3-5).

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         API ENDPOINT DESIGN                                 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   BASE: /api/v1                                                            โ”‚
โ”‚                                                                             โ”‚
โ”‚   TASKS (Orchestrated multi-agent workflows)                               โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                              โ”‚
โ”‚   POST   /tasks              Create new task (natural language input)      โ”‚
โ”‚   GET    /tasks              List all tasks (with filters)                 โ”‚
โ”‚   GET    /tasks/:id          Get task status and results                   โ”‚
โ”‚   DELETE /tasks/:id          Cancel running task                           โ”‚
โ”‚   GET    /tasks/:id/stream   SSE stream for real-time updates              โ”‚
โ”‚                                                                             โ”‚
โ”‚   AGENTS (Direct agent access)                                             โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                              โ”‚
โ”‚   GET    /agents             List all agents with capabilities             โ”‚
โ”‚   GET    /agents/:id         Get agent details and status                  โ”‚
โ”‚   POST   /agents/:id/invoke  Invoke agent directly                         โ”‚
โ”‚   GET    /agents/:id/stream  SSE stream for agent output                   โ”‚
โ”‚                                                                             โ”‚
โ”‚   CONTEXT (Shared context management)                                      โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                      โ”‚
โ”‚   GET    /context            Get current context store                     โ”‚
โ”‚   PUT    /context            Update context                                โ”‚
โ”‚   DELETE /context/:key       Remove context entry                          โ”‚
โ”‚                                                                             โ”‚
โ”‚   ANALYTICS (Cost and usage tracking)                                      โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                      โ”‚
โ”‚   GET    /analytics/costs    Cost breakdown (by agent, provider, time)     โ”‚
โ”‚   GET    /analytics/usage    Usage statistics                              โ”‚
โ”‚   GET    /analytics/logs     Event logs                                    โ”‚
โ”‚                                                                             โ”‚
โ”‚   EXAMPLE REQUEST/RESPONSE:                                                โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                 โ”‚
โ”‚                                                                             โ”‚
โ”‚   POST /api/v1/tasks                                                       โ”‚
โ”‚   Content-Type: application/json                                           โ”‚
โ”‚                                                                             โ”‚
โ”‚   {                                                                         โ”‚
โ”‚     "input": "Research quantum computing, then email summary to team",    โ”‚
โ”‚     "options": {                                                           โ”‚
โ”‚       "stream": true,                                                      โ”‚
โ”‚       "maxCost": 1.00,                                                     โ”‚
โ”‚       "priority": "normal"                                                 โ”‚
โ”‚     }                                                                       โ”‚
โ”‚   }                                                                         โ”‚
โ”‚                                                                             โ”‚
โ”‚   Response (202 Accepted):                                                 โ”‚
โ”‚   {                                                                         โ”‚
โ”‚     "taskId": "task_abc123",                                               โ”‚
โ”‚     "status": "planning",                                                  โ”‚
โ”‚     "streamUrl": "/api/v1/tasks/task_abc123/stream",                       โ”‚
โ”‚     "plan": {                                                              โ”‚
โ”‚       "steps": [                                                           โ”‚
โ”‚         { "agent": "research", "action": "research_topic" },              โ”‚
โ”‚         { "agent": "email", "action": "compose_email" }                   โ”‚
โ”‚       ],                                                                   โ”‚
โ”‚       "estimatedCost": 0.45,                                               โ”‚
โ”‚       "estimatedTime": "30s"                                               โ”‚
โ”‚     }                                                                       โ”‚
โ”‚   }                                                                         โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Agent Registry

Each agent must be registered with its capabilities, tools, and configuration:

interface AgentDefinition {
  id: string;                    // e.g., "research", "email"
  name: string;                  // Human-readable name
  description: string;           // What this agent does

  // Capabilities for orchestrator matching
  capabilities: string[];        // e.g., ["search", "summarize", "extract"]

  // Tools available to this agent
  tools: Tool[];                 // AI SDK tool definitions

  // Model configuration
  defaultModel: string;          // e.g., "claude-opus-4"
  fallbackModel?: string;        // Cheaper alternative for budget limits

  // System prompt
  systemPrompt: string;

  // Cost controls
  maxTokensPerRequest?: number;
  budgetLimit?: {
    daily: number;
    monthly: number;
  };
}

Real World Outcome

Web Dashboard in Action

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Personal AI Command Center                              [Dashboard]     โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                              โ”‚
โ”‚  ACTIVE AGENTS                                  RECENT ACTIVITY              โ”‚
โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€              โ”‚
โ”‚  Research Agent    [Idle]                    10:34 Drafted email to team  โ”‚
โ”‚  Email Agent       [Processing...]           10:32 Research completed     โ”‚
โ”‚  Calendar Agent    [Idle]                    10:28 Scheduled meeting      โ”‚
โ”‚  Code Helper       [Idle]                    10:15 Reviewed PR #234       โ”‚
โ”‚                                                                              โ”‚
โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”‚
โ”‚                                                                              โ”‚
โ”‚  CURRENT TASK: Drafting email summary of quantum research                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚                                                                      โ”‚    โ”‚
โ”‚  โ”‚  Email Agent streaming...                                         โ”‚    โ”‚
โ”‚  โ”‚                                                                      โ”‚    โ”‚
โ”‚  โ”‚  Subject: Quantum Computing Research Summary                         โ”‚    โ”‚
โ”‚  โ”‚                                                                      โ”‚    โ”‚
โ”‚  โ”‚  Hi Team,                                                            โ”‚    โ”‚
โ”‚  โ”‚                                                                      โ”‚    โ”‚
โ”‚  โ”‚  I wanted to share some exciting findings from my research on_       โ”‚    โ”‚
โ”‚  โ”‚                                                                      โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ”‚                                                                              โ”‚
โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”‚
โ”‚                                                                              โ”‚
โ”‚  COST TRACKING (This Month)                                                 โ”‚
โ”‚  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                โ”‚
โ”‚  Total: $23.45                                                              โ”‚
โ”‚  |-- Research Agent:  $12.30 (Claude Opus)                                  โ”‚
โ”‚  |-- Email Agent:     $5.20 (GPT-4)                                         โ”‚
โ”‚  |-- Calendar Agent:  $2.15 (GPT-3.5)                                       โ”‚
โ”‚  +-- Code Helper:     $3.80 (Claude Sonnet)                                 โ”‚
โ”‚                                                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

CLI Interaction

$ ai "Research quantum computing, then draft an email to my team summarizing it"

Orchestrator analyzing task...
Execution plan:
   1. Research Agent -> gather quantum computing info
   2. Email Agent -> draft summary email

[Research Agent] Starting research...
[Research Agent] Completed (12 facts gathered)

[Email Agent] Drafting email...
[Email Agent] Draft ready

Would you like me to send this email? [y/N]

API Integration Example

# Create a task via API
curl -X POST http://localhost:3000/api/v1/tasks \
  -H "Content-Type: application/json" \
  -d '{"input": "Research quantum computing and email summary to team"}'

# Stream results
curl -N http://localhost:3000/api/v1/tasks/task_abc123/stream

Solution Architecture

Full System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      AI COMMAND CENTER ARCHITECTURE                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                              โ”‚
โ”‚                              USER INTERFACES                                 โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”‚
โ”‚   โ”‚   Web Dashboard   โ”‚  โ”‚      CLI         โ”‚  โ”‚    REST API      โ”‚          โ”‚
โ”‚   โ”‚   (Next.js)       โ”‚  โ”‚   (Node.js)      โ”‚  โ”‚   (Next.js)      โ”‚          โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ”‚
โ”‚            โ”‚                     โ”‚                     โ”‚                     โ”‚
โ”‚            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                     โ”‚
โ”‚                                  โ”‚                                           โ”‚
โ”‚                                  โ–ผ                                           โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚                      ORCHESTRATION LAYER                             โ”‚   โ”‚
โ”‚   โ”‚                                                                      โ”‚   โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚   โ”‚
โ”‚   โ”‚   โ”‚  Task Planner   โ”‚  โ”‚ Agent Selector  โ”‚  โ”‚ Execution Engine โ”‚    โ”‚   โ”‚
โ”‚   โ”‚   โ”‚                 โ”‚  โ”‚                 โ”‚  โ”‚                 โ”‚    โ”‚   โ”‚
โ”‚   โ”‚   โ”‚ โ€ข Parse intent  โ”‚  โ”‚ โ€ข Match caps    โ”‚  โ”‚ โ€ข Run agents    โ”‚    โ”‚   โ”‚
โ”‚   โ”‚   โ”‚ โ€ข Extract deps  โ”‚  โ”‚ โ€ข Check budgets โ”‚  โ”‚ โ€ข Handle errors โ”‚    โ”‚   โ”‚
โ”‚   โ”‚   โ”‚ โ€ข Build plan    โ”‚  โ”‚ โ€ข Route models  โ”‚  โ”‚ โ€ข Aggregate     โ”‚    โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚   โ”‚
โ”‚   โ”‚                                                                      โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                   โ”‚                                          โ”‚
โ”‚          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚
โ”‚          โ”‚                        โ”‚                        โ”‚                โ”‚
โ”‚          โ–ผ                        โ–ผ                        โ–ผ                โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚   โ”‚  Research   โ”‚          โ”‚   Email     โ”‚          โ”‚  Calendar   โ”‚        โ”‚
โ”‚   โ”‚   Agent     โ”‚          โ”‚   Agent     โ”‚          โ”‚   Agent     โ”‚        โ”‚
โ”‚   โ”‚             โ”‚          โ”‚             โ”‚          โ”‚             โ”‚        โ”‚
โ”‚   โ”‚ Tools:      โ”‚          โ”‚ Tools:      โ”‚          โ”‚ Tools:      โ”‚        โ”‚
โ”‚   โ”‚ โ€ข search    โ”‚          โ”‚ โ€ข compose   โ”‚          โ”‚ โ€ข schedule  โ”‚        โ”‚
โ”‚   โ”‚ โ€ข read_page โ”‚          โ”‚ โ€ข send      โ”‚          โ”‚ โ€ข check     โ”‚        โ”‚
โ”‚   โ”‚ โ€ข extract   โ”‚          โ”‚ โ€ข list      โ”‚          โ”‚ โ€ข invite    โ”‚        โ”‚
โ”‚   โ”‚ โ€ข summarize โ”‚          โ”‚ โ€ข search    โ”‚          โ”‚ โ€ข cancel    โ”‚        โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚          โ”‚                        โ”‚                        โ”‚                โ”‚
โ”‚          โ”‚                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”‚                โ”‚
โ”‚          โ”‚                 โ”‚    Code     โ”‚                 โ”‚                โ”‚
โ”‚          โ”‚                 โ”‚   Helper    โ”‚                 โ”‚                โ”‚
โ”‚          โ”‚                 โ”‚             โ”‚                 โ”‚                โ”‚
โ”‚          โ”‚                 โ”‚ Tools:      โ”‚                 โ”‚                โ”‚
โ”‚          โ”‚                 โ”‚ โ€ข review    โ”‚                 โ”‚                โ”‚
โ”‚          โ”‚                 โ”‚ โ€ข explain   โ”‚                 โ”‚                โ”‚
โ”‚          โ”‚                 โ”‚ โ€ข refactor  โ”‚                 โ”‚                โ”‚
โ”‚          โ”‚                 โ”‚ โ€ข test      โ”‚                 โ”‚                โ”‚
โ”‚          โ”‚                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ”‚                โ”‚
โ”‚          โ”‚                        โ”‚                        โ”‚                โ”‚
โ”‚          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚
โ”‚                                   โ”‚                                          โ”‚
โ”‚                                   โ–ผ                                          โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚                     SHARED CONTEXT STORE                             โ”‚   โ”‚
โ”‚   โ”‚                                                                      โ”‚   โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”           โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   Session     โ”‚  โ”‚ Conversation  โ”‚  โ”‚    User       โ”‚           โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   Context     โ”‚  โ”‚   History     โ”‚  โ”‚ Preferences   โ”‚           โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”‚   โ”‚
โ”‚   โ”‚                                                                      โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                                              โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚                     PROVIDER ABSTRACTION LAYER                       โ”‚   โ”‚
โ”‚   โ”‚                                                                      โ”‚   โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚ OpenAI  โ”‚  โ”‚ Anthropic โ”‚  โ”‚  Google  โ”‚  โ”‚  Local (Ollama)  โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚         โ”‚  โ”‚           โ”‚  โ”‚          โ”‚  โ”‚                  โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚ GPT-4   โ”‚  โ”‚ Claude    โ”‚  โ”‚ Gemini   โ”‚  โ”‚ Llama, Mistral   โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚ GPT-4o  โ”‚  โ”‚ Opus/     โ”‚  โ”‚ Pro/     โ”‚  โ”‚                  โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ”‚         โ”‚  โ”‚ Sonnet    โ”‚  โ”‚ Flash    โ”‚  โ”‚                  โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚   โ”‚
โ”‚   โ”‚                                                                      โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                                              โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚   โ”‚                     OBSERVABILITY & ANALYTICS                        โ”‚   โ”‚
โ”‚   โ”‚                                                                      โ”‚   โ”‚
โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   Event     โ”‚  โ”‚    Cost     โ”‚  โ”‚    Log      โ”‚                โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   Stream    โ”‚  โ”‚   Tracker   โ”‚  โ”‚   Storage   โ”‚                โ”‚   โ”‚
โ”‚   โ”‚   โ”‚   (SSE)     โ”‚  โ”‚             โ”‚  โ”‚             โ”‚                โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚   โ”‚
โ”‚   โ”‚                                                                      โ”‚   โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚                                                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Orchestration Layer Design

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    ORCHESTRATION LAYER DETAIL                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   INPUT: "Research quantum computing, then email summary to team"          โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚  STEP 1: TASK PLANNER                                                โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  Uses generateObject with planning schema:                          โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  const planSchema = z.object({                                       โ”‚  โ”‚
โ”‚   โ”‚    intent: z.string(),                                               โ”‚  โ”‚
โ”‚   โ”‚    steps: z.array(z.object({                                         โ”‚  โ”‚
โ”‚   โ”‚      action: z.string(),                                             โ”‚  โ”‚
โ”‚   โ”‚      agentHint: z.string().optional(),                               โ”‚  โ”‚
โ”‚   โ”‚      dependsOn: z.array(z.string()).optional(),                      โ”‚  โ”‚
โ”‚   โ”‚      input: z.record(z.unknown())                                    โ”‚  โ”‚
โ”‚   โ”‚    }))                                                               โ”‚  โ”‚
โ”‚   โ”‚  });                                                                 โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  OUTPUT:                                                             โ”‚  โ”‚
โ”‚   โ”‚  {                                                                   โ”‚  โ”‚
โ”‚   โ”‚    intent: "research_and_email",                                     โ”‚  โ”‚
โ”‚   โ”‚    steps: [                                                          โ”‚  โ”‚
โ”‚   โ”‚      { action: "research", input: { topic: "quantum computing" } },  โ”‚  โ”‚
โ”‚   โ”‚      { action: "email", input: { content: "{{step_1}}" },           โ”‚  โ”‚
โ”‚   โ”‚        dependsOn: ["step_1"] }                                       โ”‚  โ”‚
โ”‚   โ”‚    ]                                                                 โ”‚  โ”‚
โ”‚   โ”‚  }                                                                   โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                        โ”‚                                    โ”‚
โ”‚                                        โ–ผ                                    โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚  STEP 2: AGENT SELECTOR                                              โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  Agent Registry:                                                    โ”‚  โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ ID           โ”‚ Capabilities                                   โ”‚  โ”‚  โ”‚
โ”‚   โ”‚  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค  โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ research     โ”‚ research, search, summarize, extract           โ”‚  โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ email        โ”‚ email, compose, send, draft                    โ”‚  โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ calendar     โ”‚ schedule, meeting, availability, invite        โ”‚  โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ code         โ”‚ review, explain, refactor, test, debug         โ”‚  โ”‚  โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  Matching: "research" action โ†’ research agent                       โ”‚  โ”‚
โ”‚   โ”‚           "email" action โ†’ email agent                              โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  Model Selection (based on budget + task complexity):               โ”‚  โ”‚
โ”‚   โ”‚  โ€ข Research (complex reasoning) โ†’ Claude Opus                       โ”‚  โ”‚
โ”‚   โ”‚  โ€ข Email (straightforward) โ†’ GPT-4o-mini                           โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                        โ”‚                                    โ”‚
โ”‚                                        โ–ผ                                    โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚  STEP 3: EXECUTION ENGINE                                           โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  Execution Plan:                                                    โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Step 1: Research      โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Agent: research       โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Model: claude-opus-4    โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Input: {topic}        โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Output โ†’ context.step1โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                          โ”‚  โ”‚
โ”‚   โ”‚              โ”‚ depends on                                           โ”‚  โ”‚
โ”‚   โ”‚              โ–ผ                                                      โ”‚  โ”‚
โ”‚   โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Step 2: Email         โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Agent: email          โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Model: gpt-4o-mini    โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Input: {context.step1}โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ”‚ Output โ†’ result       โ”‚                                          โ”‚  โ”‚
โ”‚   โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                          โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚  For each step:                                                     โ”‚  โ”‚
โ”‚   โ”‚  1. Check budget (abort if exceeded)                                โ”‚  โ”‚
โ”‚   โ”‚  2. Resolve input variables from context                            โ”‚  โ”‚
โ”‚   โ”‚  3. Invoke agent with streamText                                    โ”‚  โ”‚
โ”‚   โ”‚  4. Emit events for UI/logging                                      โ”‚  โ”‚
โ”‚   โ”‚  5. Write output to context                                         โ”‚  โ”‚
โ”‚   โ”‚  6. Handle errors (retry or abort)                                  โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Agent Registry and Discovery

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    AGENT REGISTRY DESIGN                                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   // agents/registry.ts                                                    โ”‚
โ”‚                                                                             โ”‚
โ”‚   const agentRegistry = new Map<string, AgentDefinition>();                โ”‚
โ”‚                                                                             โ”‚
โ”‚   // Registration                                                          โ”‚
โ”‚   registerAgent({                                                          โ”‚
โ”‚     id: 'research',                                                        โ”‚
โ”‚     name: 'Research Agent',                                                โ”‚
โ”‚     description: 'Searches the web and extracts information',             โ”‚
โ”‚     capabilities: ['search', 'research', 'summarize', 'extract'],         โ”‚
โ”‚     tools: [searchTool, readPageTool, extractTool],                       โ”‚
โ”‚     defaultModel: 'claude-opus-4',                                           โ”‚
โ”‚     fallbackModel: 'gpt-4o-mini',                                          โ”‚
โ”‚     systemPrompt: `You are a research assistant...`,                       โ”‚
โ”‚     budgetLimit: { daily: 10.00 }                                          โ”‚
โ”‚   });                                                                      โ”‚
โ”‚                                                                             โ”‚
โ”‚   // Discovery                                                             โ”‚
โ”‚   function findAgentForCapability(capability: string): AgentDefinition {   โ”‚
โ”‚     for (const agent of agentRegistry.values()) {                         โ”‚
โ”‚       if (agent.capabilities.includes(capability)) {                       โ”‚
โ”‚         return agent;                                                      โ”‚
โ”‚       }                                                                    โ”‚
โ”‚     }                                                                      โ”‚
โ”‚     throw new Error(`No agent found for capability: ${capability}`);       โ”‚
โ”‚   }                                                                        โ”‚
โ”‚                                                                             โ”‚
โ”‚   // Capability matching for orchestrator                                  โ”‚
โ”‚   function matchAgents(actions: string[]): Map<string, AgentDefinition> {  โ”‚
โ”‚     const matches = new Map();                                             โ”‚
โ”‚     for (const action of actions) {                                        โ”‚
โ”‚       matches.set(action, findAgentForCapability(action));                 โ”‚
โ”‚     }                                                                      โ”‚
โ”‚     return matches;                                                        โ”‚
โ”‚   }                                                                        โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

File Structure Recommendation (Monorepo)

ai-command-center/
โ”œโ”€โ”€ package.json                    # Workspace root
โ”œโ”€โ”€ turbo.json                      # Turborepo config
โ”œโ”€โ”€ pnpm-workspace.yaml
โ”‚
โ”œโ”€โ”€ apps/
โ”‚   โ”œโ”€โ”€ web/                        # Next.js dashboard
โ”‚   โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx            # Main dashboard
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ tasks/
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ route.ts    # POST /tasks
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [id]/
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ route.ts
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ stream/route.ts
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ agents/
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ route.ts
โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [id]/route.ts
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ analytics/
โ”‚   โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ route.ts
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ settings/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ page.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AgentCard.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AgentStream.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ CostDashboard.tsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ TaskInput.tsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ActivityFeed.tsx
โ”‚   โ”‚   โ””โ”€โ”€ lib/
โ”‚   โ”‚       โ””โ”€โ”€ hooks/
โ”‚   โ”‚           โ”œโ”€โ”€ useAgentStream.ts
โ”‚   โ”‚           โ””โ”€โ”€ useTaskExecution.ts
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ cli/                        # CLI application
โ”‚       โ”œโ”€โ”€ package.json
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ”‚   โ”œโ”€โ”€ index.ts            # Main entry
โ”‚       โ”‚   โ”œโ”€โ”€ commands/
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ task.ts         # ai "prompt"
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ research.ts     # ai research
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ email.ts        # ai email
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ calendar.ts     # ai calendar
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ code.ts         # ai code
โ”‚       โ”‚   โ”‚   โ”œโ”€โ”€ status.ts       # ai status
โ”‚       โ”‚   โ”‚   โ””โ”€โ”€ config.ts       # ai config
โ”‚       โ”‚   โ””โ”€โ”€ lib/
โ”‚       โ”‚       โ”œโ”€โ”€ api-client.ts   # HTTP client to API
โ”‚       โ”‚       โ””โ”€โ”€ stream.ts       # SSE handling
โ”‚       โ””โ”€โ”€ bin/
โ”‚           โ””โ”€โ”€ ai                  # Executable
โ”‚
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ core/                       # Shared core logic
โ”‚   โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ orchestrator/
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ index.ts
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ planner.ts
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ executor.ts
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ types.ts
โ”‚   โ”‚       โ”œโ”€โ”€ agents/
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ registry.ts
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ base-agent.ts
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ research-agent.ts
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ email-agent.ts
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ calendar-agent.ts
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ code-agent.ts
โ”‚   โ”‚       โ”œโ”€โ”€ context/
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ store.ts
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ types.ts
โ”‚   โ”‚       โ”œโ”€โ”€ providers/
โ”‚   โ”‚       โ”‚   โ”œโ”€โ”€ index.ts
โ”‚   โ”‚       โ”‚   โ””โ”€โ”€ model-router.ts
โ”‚   โ”‚       โ””โ”€โ”€ analytics/
โ”‚   โ”‚           โ”œโ”€โ”€ cost-tracker.ts
โ”‚   โ”‚           โ””โ”€โ”€ event-emitter.ts
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ tools/                      # Shared tool definitions
โ”‚   โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”‚   โ””โ”€โ”€ src/
โ”‚   โ”‚       โ”œโ”€โ”€ search.ts
โ”‚   โ”‚       โ”œโ”€โ”€ email.ts
โ”‚   โ”‚       โ”œโ”€โ”€ calendar.ts
โ”‚   โ”‚       โ””โ”€โ”€ code.ts
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ schemas/                    # Shared Zod schemas
โ”‚       โ”œโ”€โ”€ package.json
โ”‚       โ””โ”€โ”€ src/
โ”‚           โ”œโ”€โ”€ task.ts
โ”‚           โ”œโ”€โ”€ agent.ts
โ”‚           โ”œโ”€โ”€ plan.ts
โ”‚           โ””โ”€โ”€ analytics.ts
โ”‚
โ”œโ”€โ”€ .env.example
โ””โ”€โ”€ README.md

Phased Implementation Guide

Phase 1: Single Agent End-to-End (Week 1)

Goal: Get one agent (Research) working completely, from CLI input to streaming output.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    PHASE 1: SINGLE AGENT                                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   DELIVERABLES:                                                            โ”‚
โ”‚   โ€ข Research agent with search and summarize tools                         โ”‚
โ”‚   โ€ข Simple CLI: ai research "topic"                                        โ”‚
โ”‚   โ€ข Basic streaming output                                                 โ”‚
โ”‚                                                                             โ”‚
โ”‚   ARCHITECTURE:                                                            โ”‚
โ”‚                                                                             โ”‚
โ”‚   CLI Input                                                                โ”‚
โ”‚       โ”‚                                                                    โ”‚
โ”‚       โ–ผ                                                                    โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                             โ”‚
โ”‚   โ”‚  Research Agent โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚  AI SDK Tools   โ”‚                             โ”‚
โ”‚   โ”‚                 โ”‚     โ”‚  โ€ข search       โ”‚                             โ”‚
โ”‚   โ”‚  streamText()   โ”‚     โ”‚  โ€ข read_page    โ”‚                             โ”‚
โ”‚   โ”‚  maxSteps: 10   โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                             โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                      โ”‚
โ”‚            โ”‚                                                               โ”‚
โ”‚            โ–ผ                                                               โ”‚
โ”‚   Terminal Output (streaming)                                              โ”‚
โ”‚                                                                             โ”‚
โ”‚   IMPLEMENTATION STEPS:                                                    โ”‚
โ”‚   1. Set up monorepo with pnpm workspaces                                 โ”‚
โ”‚   2. Create packages/core with base agent class                           โ”‚
โ”‚   3. Implement research agent with 2 tools                                โ”‚
โ”‚   4. Create CLI with single command                                       โ”‚
โ”‚   5. Add basic error handling                                             โ”‚
โ”‚                                                                             โ”‚
โ”‚   SUCCESS CRITERIA:                                                        โ”‚
โ”‚   $ ai research "quantum computing"                                        โ”‚
โ”‚   > Searching for quantum computing...                                     โ”‚
โ”‚   > Found 5 sources...                                                     โ”‚
โ”‚   > Quantum computing uses quantum mechanics...                            โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Code: Base Agent Class

// packages/core/src/agents/base-agent.ts
import { streamText, CoreTool } from 'ai';

export abstract class BaseAgent {
  abstract id: string;
  abstract name: string;
  abstract systemPrompt: string;
  abstract tools: Record<string, CoreTool>;

  protected model: LanguageModelV1;

  constructor(model: LanguageModelV1) {
    this.model = model;
  }

  async *execute(input: string): AsyncGenerator<string> {
    const { textStream } = await streamText({
      model: this.model,
      system: this.systemPrompt,
      prompt: input,
      tools: this.tools,
      maxSteps: 10,
    });

    for await (const chunk of textStream) {
      yield chunk;
    }
  }
}

Phase 2: Orchestration Layer (Week 2)

Goal: Add the orchestrator that can decompose tasks and select agents.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    PHASE 2: ORCHESTRATION                                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   DELIVERABLES:                                                            โ”‚
โ”‚   โ€ข Task planner using generateObject                                      โ”‚
โ”‚   โ€ข Agent registry with capability matching                                โ”‚
โ”‚   โ€ข Execution engine for sequential steps                                  โ”‚
โ”‚   โ€ข Second agent (Email) to test multi-agent flow                         โ”‚
โ”‚                                                                             โ”‚
โ”‚   ARCHITECTURE:                                                            โ”‚
โ”‚                                                                             โ”‚
โ”‚   "Research X, then email Y"                                               โ”‚
โ”‚       โ”‚                                                                    โ”‚
โ”‚       โ–ผ                                                                    โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                      โ”‚
โ”‚   โ”‚  Task Planner   โ”‚ โ”€โ”€โ”€ generateObject(planSchema)                       โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                      โ”‚
โ”‚            โ”‚                                                               โ”‚
โ”‚            โ–ผ                                                               โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                      โ”‚
โ”‚   โ”‚ Agent Selector  โ”‚ โ”€โ”€โ”€ Match capabilities to agents                     โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                                      โ”‚
โ”‚            โ”‚                                                               โ”‚
โ”‚            โ–ผ                                                               โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                             โ”‚
โ”‚   โ”‚    Executor     โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚  Research Agent โ”‚ โ”€โ”€โ”€ Step 1                   โ”‚
โ”‚   โ”‚                 โ”‚     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                             โ”‚
โ”‚   โ”‚                 โ”‚              โ”‚ result                                โ”‚
โ”‚   โ”‚                 โ”‚              โ–ผ                                       โ”‚
โ”‚   โ”‚                 โ”‚     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                             โ”‚
โ”‚   โ”‚                 โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚   Email Agent   โ”‚ โ”€โ”€โ”€ Step 2 (uses step 1)    โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                             โ”‚
โ”‚                                                                             โ”‚
โ”‚   IMPLEMENTATION STEPS:                                                    โ”‚
โ”‚   1. Create orchestrator with generateObject planner                       โ”‚
โ”‚   2. Build agent registry with registration/discovery                     โ”‚
โ”‚   3. Implement sequential executor                                        โ”‚
โ”‚   4. Create email agent with compose tool                                 โ”‚
โ”‚   5. Wire up CLI to orchestrator                                          โ”‚
โ”‚                                                                             โ”‚
โ”‚   SUCCESS CRITERIA:                                                        โ”‚
โ”‚   $ ai "Research AI safety, then draft email to team"                      โ”‚
โ”‚   > Planning task...                                                       โ”‚
โ”‚   > Step 1: Research Agent - researching AI safety                        โ”‚
โ”‚   > Step 2: Email Agent - drafting email                                   โ”‚
โ”‚   > Done! Email draft ready.                                               โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Code: Orchestrator

// packages/core/src/orchestrator/index.ts
export class Orchestrator {
  private planner: TaskPlanner;
  private registry: AgentRegistry;
  private executor: ExecutionEngine;

  async execute(input: string): AsyncGenerator<OrchestratorEvent> {
    // Step 1: Plan
    const plan = await this.planner.plan(input);
    yield { type: 'plan_created', plan };

    // Step 2: Select agents
    const agentMap = this.registry.matchCapabilities(plan.steps);

    // Step 3: Execute
    for (const step of plan.steps) {
      const agent = agentMap.get(step.action);
      yield { type: 'agent_started', agentId: agent.id };

      for await (const token of agent.execute(step.input)) {
        yield { type: 'agent_token', agentId: agent.id, token };
      }

      yield { type: 'agent_completed', agentId: agent.id };
    }
  }
}

Phase 3: Shared Context (Week 3)

Goal: Implement context store so agents can share information.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    PHASE 3: SHARED CONTEXT                                  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   DELIVERABLES:                                                            โ”‚
โ”‚   โ€ข Multi-layer context store (session, conversation, user)               โ”‚
โ”‚   โ€ข Context injection into agent prompts                                  โ”‚
โ”‚   โ€ข Result passing between agents                                         โ”‚
โ”‚   โ€ข Context persistence (file-based initially)                            โ”‚
โ”‚                                                                             โ”‚
โ”‚   ARCHITECTURE:                                                            โ”‚
โ”‚                                                                             โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚   โ”‚                      CONTEXT STORE                                   โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Session Layer (Map)                                               โ”‚  โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ task_plan: {...}                                              โ”‚  โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ step_1_result: "Research found..."                            โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ current_step: 2                                               โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   Conversation Layer (Array)                                        โ”‚  โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ { role: "user", content: "Research..." }                      โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ { role: "assistant", content: "Found..." }                    โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ”‚   User Layer (Persistent)                                           โ”‚  โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ preferences: { tone: "formal" }                               โ”‚  โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ email_signature: "Best, John"                                 โ”‚  โ”‚
โ”‚   โ”‚                                                                      โ”‚  โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                             โ”‚
โ”‚   AGENT CONTEXT INJECTION:                                                 โ”‚
โ”‚                                                                             โ”‚
โ”‚   Research Agent                    Email Agent                            โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”‚
โ”‚   โ”‚ System Prompt + โ”‚              โ”‚ System Prompt + โ”‚                    โ”‚
โ”‚   โ”‚ User Preferencesโ”‚              โ”‚ User Preferencesโ”‚                    โ”‚
โ”‚   โ”‚                 โ”‚              โ”‚ + Step 1 Result โ”‚                    โ”‚
โ”‚   โ”‚ Input: "topic"  โ”‚              โ”‚                 โ”‚                    โ”‚
โ”‚   โ”‚                 โ”‚              โ”‚ Input: "draft"  โ”‚                    โ”‚
โ”‚   โ”‚ Output โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ–บContext         โ”‚                    โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ”‚
โ”‚                                                                             โ”‚
โ”‚   IMPLEMENTATION STEPS:                                                    โ”‚
โ”‚   1. Create context store interface                                       โ”‚
โ”‚   2. Implement session context (in-memory)                                โ”‚
โ”‚   3. Add context to agent base class                                      โ”‚
โ”‚   4. Modify executor to pass results via context                          โ”‚
โ”‚   5. Add user preferences layer with file persistence                     โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Phase 4: Web Dashboard (Week 4)

Goal: Build the Next.js dashboard with real-time streaming.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    PHASE 4: WEB DASHBOARD                                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   DELIVERABLES:                                                            โ”‚
โ”‚   โ€ข Next.js app with agent status panel                                   โ”‚
โ”‚   โ€ข SSE streaming for real-time updates                                   โ”‚
โ”‚   โ€ข Task input and execution UI                                           โ”‚
โ”‚   โ€ข Activity feed                                                          โ”‚
โ”‚                                                                             โ”‚
โ”‚   COMPONENT HIERARCHY:                                                     โ”‚
โ”‚                                                                             โ”‚
โ”‚   <Dashboard>                                                              โ”‚
โ”‚   โ”œโ”€โ”€ <AgentStatusPanel>                                                   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ <AgentCard agent={...} status={...} />                          โ”‚
โ”‚   โ”œโ”€โ”€ <TaskInterface>                                                      โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ <TaskInput onSubmit={...} />                                    โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ <ExecutionPlan plan={...} />                                    โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ <AgentStreamPanel>                                              โ”‚
โ”‚   โ”‚       โ””โ”€โ”€ <AgentStream agentId={...} stream={...} />                  โ”‚
โ”‚   โ”œโ”€โ”€ <ActivityFeed events={...} />                                       โ”‚
โ”‚   โ””โ”€โ”€ <CostDashboard costs={...} />                                       โ”‚
โ”‚                                                                             โ”‚
โ”‚   SSE STREAMING PATTERN:                                                   โ”‚
โ”‚                                                                             โ”‚
โ”‚   // app/api/tasks/[id]/stream/route.ts                                   โ”‚
โ”‚   export async function GET(req, { params }) {                            โ”‚
โ”‚     const stream = new ReadableStream({                                   โ”‚
โ”‚       async start(controller) {                                           โ”‚
โ”‚         for await (const event of orchestrator.execute()) {               โ”‚
โ”‚           controller.enqueue(                                             โ”‚
โ”‚             `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`    โ”‚
โ”‚           );                                                              โ”‚
โ”‚         }                                                                 โ”‚
โ”‚         controller.close();                                               โ”‚
โ”‚       }                                                                   โ”‚
โ”‚     });                                                                   โ”‚
โ”‚     return new Response(stream, {                                         โ”‚
โ”‚       headers: { 'Content-Type': 'text/event-stream' }                    โ”‚
โ”‚     });                                                                   โ”‚
โ”‚   }                                                                       โ”‚
โ”‚                                                                             โ”‚
โ”‚   // hooks/useAgentStream.ts                                              โ”‚
โ”‚   function useAgentStream(taskId: string) {                               โ”‚
โ”‚     const [streams, setStreams] = useState({});                           โ”‚
โ”‚     useEffect(() => {                                                     โ”‚
โ”‚       const eventSource = new EventSource(`/api/tasks/${taskId}/stream`); โ”‚
โ”‚       eventSource.onmessage = (e) => { ... };                             โ”‚
โ”‚       return () => eventSource.close();                                   โ”‚
โ”‚     }, [taskId]);                                                         โ”‚
โ”‚     return streams;                                                       โ”‚
โ”‚   }                                                                       โ”‚
โ”‚                                                                             โ”‚
โ”‚   IMPLEMENTATION STEPS:                                                    โ”‚
โ”‚   1. Set up Next.js app with Tailwind                                     โ”‚
โ”‚   2. Create API routes for tasks                                          โ”‚
โ”‚   3. Implement SSE streaming endpoint                                     โ”‚
โ”‚   4. Build React components with streaming hooks                          โ”‚
โ”‚   5. Style dashboard                                                       โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Phase 5: CLI Interface (Week 5)

Goal: Polish CLI with all commands and interactive mode.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    PHASE 5: CLI INTERFACE                                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   DELIVERABLES:                                                            โ”‚
โ”‚   โ€ข Full CLI with all agent commands                                      โ”‚
โ”‚   โ€ข Interactive REPL mode                                                 โ”‚
โ”‚   โ€ข Configuration management                                               โ”‚
โ”‚   โ€ข Status and logs commands                                               โ”‚
โ”‚                                                                             โ”‚
โ”‚   COMMAND STRUCTURE:                                                       โ”‚
โ”‚                                                                             โ”‚
โ”‚   ai                                                                       โ”‚
โ”‚   โ”œโ”€โ”€ <prompt>              Natural language task                          โ”‚
โ”‚   โ”œโ”€โ”€ research <topic>      Direct research agent                          โ”‚
โ”‚   โ”œโ”€โ”€ email                                                                โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ draft             Draft an email                                 โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ send              Send drafted email                             โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ list              List recent emails                             โ”‚
โ”‚   โ”œโ”€โ”€ calendar                                                             โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ schedule          Schedule event                                 โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ check             Check availability                             โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ list              List upcoming events                           โ”‚
โ”‚   โ”œโ”€โ”€ code                                                                 โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ review            Review code/PR                                 โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ explain           Explain code                                   โ”‚
โ”‚   โ”œโ”€โ”€ status                Show agent status                              โ”‚
โ”‚   โ”œโ”€โ”€ logs [--agent]        View logs                                      โ”‚
โ”‚   โ”œโ”€โ”€ cost [--period]       View costs                                     โ”‚
โ”‚   โ”œโ”€โ”€ config                                                               โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ get <key>         Get config value                               โ”‚
โ”‚   โ”‚   โ”œโ”€โ”€ set <key> <val>   Set config value                               โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ list              List all config                                โ”‚
โ”‚   โ””โ”€โ”€ interactive           Start REPL                                     โ”‚
โ”‚                                                                             โ”‚
โ”‚   CLI IMPLEMENTATION (using Commander.js):                                 โ”‚
โ”‚                                                                             โ”‚
โ”‚   // apps/cli/src/index.ts                                                โ”‚
โ”‚   import { Command } from 'commander';                                    โ”‚
โ”‚   import { createApiClient } from './lib/api-client';                     โ”‚
โ”‚                                                                             โ”‚
โ”‚   const program = new Command();                                          โ”‚
โ”‚   const api = createApiClient('http://localhost:3000/api/v1');            โ”‚
โ”‚                                                                             โ”‚
โ”‚   program                                                                  โ”‚
โ”‚     .name('ai')                                                           โ”‚
โ”‚     .description('Personal AI Command Center')                            โ”‚
โ”‚     .argument('[prompt]', 'Natural language task')                        โ”‚
โ”‚     .action(async (prompt) => {                                           โ”‚
โ”‚       if (prompt) {                                                       โ”‚
โ”‚         const stream = await api.createTask(prompt);                      โ”‚
โ”‚         for await (const event of stream) {                               โ”‚
โ”‚           renderEvent(event);                                             โ”‚
โ”‚         }                                                                 โ”‚
โ”‚       }                                                                   โ”‚
โ”‚     });                                                                   โ”‚
โ”‚                                                                             โ”‚
โ”‚   program                                                                  โ”‚
โ”‚     .command('research <topic>')                                          โ”‚
โ”‚     .description('Research a topic')                                      โ”‚
โ”‚     .action(async (topic) => { ... });                                    โ”‚
โ”‚                                                                             โ”‚
โ”‚   INTERACTIVE MODE:                                                        โ”‚
โ”‚                                                                             โ”‚
โ”‚   $ ai interactive                                                        โ”‚
โ”‚   AI Command Center v1.0.0                                                โ”‚
โ”‚   Type 'help' for commands, 'exit' to quit                                โ”‚
โ”‚                                                                             โ”‚
โ”‚   > Research AI safety                                                    โ”‚
โ”‚   [Research Agent] Searching...                                           โ”‚
โ”‚   ...                                                                     โ”‚
โ”‚   > Now email that to the team                                            โ”‚
โ”‚   [Email Agent] Drafting email with research context...                   โ”‚
โ”‚   ...                                                                     โ”‚
โ”‚   > exit                                                                  โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Phase 6: Cost Tracking and Polish (Week 6+)

Goal: Add production-ready cost management, testing, and polish.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    PHASE 6: PRODUCTION POLISH                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   DELIVERABLES:                                                            โ”‚
โ”‚   โ€ข Cost tracking with budget alerts                                      โ”‚
โ”‚   โ€ข Rate limiting per provider                                             โ”‚
โ”‚   โ€ข Graceful degradation                                                   โ”‚
โ”‚   โ€ข Comprehensive error handling                                           โ”‚
โ”‚   โ€ข Telemetry and logging                                                  โ”‚
โ”‚   โ€ข Documentation                                                          โ”‚
โ”‚                                                                             โ”‚
โ”‚   COST TRACKING IMPLEMENTATION:                                            โ”‚
โ”‚                                                                             โ”‚
โ”‚   // packages/core/src/analytics/cost-tracker.ts                          โ”‚
โ”‚   export class CostTracker {                                               โ”‚
โ”‚     private costs: Map<string, AgentCosts> = new Map();                    โ”‚
โ”‚     private limits: BudgetLimits;                                         โ”‚
โ”‚                                                                             โ”‚
โ”‚     recordUsage(event: LLMUsageEvent) {                                   โ”‚
โ”‚       const cost = this.calculateCost(event);                             โ”‚
โ”‚       this.updateAgentCosts(event.agentId, cost);                         โ”‚
โ”‚       this.checkBudgetLimits();                                           โ”‚
โ”‚       this.emit('cost_recorded', { agentId, cost });                      โ”‚
โ”‚     }                                                                      โ”‚
โ”‚                                                                             โ”‚
โ”‚     private calculateCost(event: LLMUsageEvent): number {                 โ”‚
โ”‚       const rates = PROVIDER_RATES[event.provider][event.model];          โ”‚
โ”‚       return (event.inputTokens * rates.input / 1000) +                   โ”‚
โ”‚              (event.outputTokens * rates.output / 1000);                  โ”‚
โ”‚     }                                                                      โ”‚
โ”‚                                                                             โ”‚
โ”‚     private checkBudgetLimits() {                                         โ”‚
โ”‚       const today = this.getTodayCosts();                                 โ”‚
โ”‚       if (today > this.limits.daily * 0.8) {                              โ”‚
โ”‚         this.emit('budget_warning', { percent: 80 });                     โ”‚
โ”‚       }                                                                    โ”‚
โ”‚       if (today >= this.limits.daily) {                                   โ”‚
โ”‚         this.emit('budget_exceeded', { type: 'daily' });                  โ”‚
โ”‚       }                                                                    โ”‚
โ”‚     }                                                                      โ”‚
โ”‚   }                                                                        โ”‚
โ”‚                                                                             โ”‚
โ”‚   GRACEFUL DEGRADATION:                                                    โ”‚
โ”‚                                                                             โ”‚
โ”‚   orchestrator.on('budget_warning', async () => {                         โ”‚
โ”‚     // Switch expensive agents to fallback models                         โ”‚
โ”‚     agentRegistry.get('research').useModel = 'fallback';                  โ”‚
โ”‚   });                                                                      โ”‚
โ”‚                                                                             โ”‚
โ”‚   orchestrator.on('budget_exceeded', async () => {                        โ”‚
โ”‚     // Notify user, pause non-critical tasks                              โ”‚
โ”‚     await notifyUser('Daily budget exceeded');                            โ”‚
โ”‚     orchestrator.pause();                                                 โ”‚
โ”‚   });                                                                      โ”‚
โ”‚                                                                             โ”‚
โ”‚   TELEMETRY (using AI SDK built-in):                                      โ”‚
โ”‚                                                                             โ”‚
โ”‚   const { text } = await generateText({                                   โ”‚
โ”‚     model,                                                                โ”‚
โ”‚     prompt,                                                               โ”‚
โ”‚     experimental_telemetry: {                                             โ”‚
โ”‚       isEnabled: true,                                                    โ”‚
โ”‚       functionId: 'research-agent',                                       โ”‚
โ”‚       metadata: { agentId: 'research', taskId }                           โ”‚
โ”‚     }                                                                      โ”‚
โ”‚   });                                                                      โ”‚
โ”‚                                                                             โ”‚
โ”‚   FINAL CHECKLIST:                                                        โ”‚
โ”‚   [ ] All agents working with tools                                       โ”‚
โ”‚   [ ] Orchestration handles complex multi-agent tasks                     โ”‚
โ”‚   [ ] Context persists across conversation                                โ”‚
โ”‚   [ ] Web dashboard streams in real-time                                  โ”‚
โ”‚   [ ] CLI provides full functionality                                     โ”‚
โ”‚   [ ] Cost tracking accurate and alerts work                              โ”‚
โ”‚   [ ] Errors handled gracefully                                           โ”‚
โ”‚   [ ] Tests pass                                                          โ”‚
โ”‚   [ ] Documentation complete                                              โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Testing Strategy

Agent Isolation Testing

Test each agent independently before integration:

// __tests__/agents/research-agent.test.ts
describe('ResearchAgent', () => {
  let agent: ResearchAgent;
  let mockModel: MockLanguageModel;

  beforeEach(() => {
    mockModel = createMockModel();
    agent = new ResearchAgent(mockModel);
  });

  test('should search and summarize a topic', async () => {
    mockModel.setResponses([
      { toolCalls: [{ name: 'search', args: { query: 'quantum' } }] },
      { text: 'Quantum computing uses quantum mechanics...' }
    ]);

    const result = await collectStream(agent.execute('Research quantum computing'));

    expect(result).toContain('quantum');
    expect(mockModel.toolCalls).toHaveLength(1);
  });

  test('should handle search failures gracefully', async () => {
    mockModel.setToolError('search', new Error('Network error'));

    const result = await collectStream(agent.execute('Research X'));

    expect(result).toContain('Unable to search');
  });
});

Orchestration Testing

Test the planning and execution flow:

// __tests__/orchestrator/planner.test.ts
describe('TaskPlanner', () => {
  test('should decompose multi-step task', async () => {
    const planner = new TaskPlanner(mockModel);

    const plan = await planner.plan(
      'Research quantum computing, then email summary to team'
    );

    expect(plan.steps).toHaveLength(2);
    expect(plan.steps[0].action).toBe('research');
    expect(plan.steps[1].action).toBe('email');
    expect(plan.steps[1].dependsOn).toContain('step_1');
  });
});

// __tests__/orchestrator/executor.test.ts
describe('ExecutionEngine', () => {
  test('should execute steps in dependency order', async () => {
    const executor = new ExecutionEngine(registry, contextStore);
    const executionOrder: string[] = [];

    for await (const event of executor.execute(plan)) {
      if (event.type === 'agent_started') {
        executionOrder.push(event.agentId);
      }
    }

    expect(executionOrder).toEqual(['research', 'email']);
  });

  test('should pass context between agents', async () => {
    const events = await collectEvents(executor.execute(plan));

    const emailStartEvent = events.find(
      e => e.type === 'agent_started' && e.agentId === 'email'
    );

    expect(emailStartEvent.context.step_1_result).toBeDefined();
  });
});

End-to-End Multi-Agent Testing

Test complete workflows:

// __tests__/e2e/multi-agent-flow.test.ts
describe('Multi-Agent E2E', () => {
  let orchestrator: Orchestrator;
  let server: TestServer;

  beforeAll(async () => {
    server = await startTestServer();
    orchestrator = new Orchestrator(realProviders);
  });

  test('research then email workflow', async () => {
    const events: OrchestratorEvent[] = [];

    for await (const event of orchestrator.execute(
      'Research TypeScript best practices, then email summary to me'
    )) {
      events.push(event);
    }

    // Verify plan was created
    const planEvent = events.find(e => e.type === 'plan_created');
    expect(planEvent.plan.steps).toHaveLength(2);

    // Verify research completed
    const researchComplete = events.find(
      e => e.type === 'agent_completed' && e.agentId === 'research'
    );
    expect(researchComplete.result).toBeDefined();

    // Verify email used research context
    const emailComplete = events.find(
      e => e.type === 'agent_completed' && e.agentId === 'email'
    );
    expect(emailComplete.result.draft).toContain('TypeScript');
  }, 60000); // Long timeout for real API calls
});

Common Pitfalls and Debugging

Pitfall 1: Context Explosion

Problem: Context grows unbounded as agents accumulate results.

Session starts: 1KB
After 5 tasks: 50KB
After 20 tasks: 500KB โ†’ Exceeds model context limit!

Solution: Implement context compression and eviction:

class ContextStore {
  private maxSize = 50000; // tokens

  addResult(key: string, value: string) {
    if (this.getTokenCount() > this.maxSize * 0.8) {
      this.compressOldestEntries();
    }
    this.store.set(key, value);
  }

  private compressOldestEntries() {
    // Summarize old results instead of keeping full text
    const oldest = this.getOldestEntries(5);
    for (const entry of oldest) {
      const summary = await summarize(entry.value);
      this.store.set(entry.key, `[Summary] ${summary}`);
    }
  }
}

Pitfall 2: Agent Loops

Problem: Agent gets stuck calling the same tool repeatedly.

Solution: Implement loop detection:

class AgentExecutor {
  async execute(agent: Agent, input: string) {
    const toolCallHistory: string[] = [];

    for await (const step of agent.run(input)) {
      if (step.type === 'tool_call') {
        const signature = `${step.name}:${JSON.stringify(step.args)}`;

        if (toolCallHistory.filter(h => h === signature).length >= 3) {
          throw new AgentLoopError(`Agent stuck calling ${step.name}`);
        }

        toolCallHistory.push(signature);
      }
    }
  }
}

Pitfall 3: Race Conditions in Parallel Execution

Problem: Multiple agents writing to shared context simultaneously.

Solution: Use proper synchronization:

class ContextStore {
  private lock = new AsyncLock();

  async write(key: string, value: any) {
    await this.lock.acquire('context', async () => {
      this.store.set(key, value);
    });
  }
}

Pitfall 4: Streaming Backpressure

Problem: Web client cannot consume tokens as fast as server sends them.

Solution: Implement flow control:

// Server-side
const stream = new ReadableStream({
  async pull(controller) {
    // Only send when client is ready
    const event = await eventQueue.dequeue();
    controller.enqueue(formatSSE(event));
  }
});

// Client-side
const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  // Process at client's pace
  await processChunk(decoder.decode(value));
}

Pitfall 5: Cost Estimation Inaccuracy

Problem: Estimated costs differ significantly from actual.

Solution: Track and calibrate:

class CostEstimator {
  private calibrationFactor = new Map<string, number>();

  estimate(agentId: string, input: string): number {
    const baseEstimate = this.calculateBaseEstimate(input);
    const factor = this.calibrationFactor.get(agentId) || 1.0;
    return baseEstimate * factor;
  }

  recordActual(agentId: string, estimated: number, actual: number) {
    const ratio = actual / estimated;
    const current = this.calibrationFactor.get(agentId) || 1.0;
    // Exponential moving average
    this.calibrationFactor.set(agentId, current * 0.9 + ratio * 0.1);
  }
}

Pitfall 6: Tool Argument Validation

Problem: LLM generates invalid tool arguments that pass Zod but fail at runtime.

Solution: Runtime validation layer:

const searchTool = tool({
  description: 'Search the web',
  parameters: z.object({
    query: z.string().min(1).max(200),
  }),
  execute: async ({ query }) => {
    // Additional runtime checks
    if (query.includes('..') || query.includes('<script>')) {
      throw new InvalidToolArgumentError('Query contains invalid characters');
    }
    return await search(query);
  }
});

Pitfall 7: Memory Leaks in Long-Running Sessions

Problem: Event listeners and streams accumulate over time.

Solution: Proper cleanup:

class TaskExecution {
  private cleanupFns: Array<() => void> = [];

  async run() {
    const eventSource = new EventSource(url);
    this.cleanupFns.push(() => eventSource.close());

    const interval = setInterval(heartbeat, 30000);
    this.cleanupFns.push(() => clearInterval(interval));

    // ... execution
  }

  cleanup() {
    for (const fn of this.cleanupFns) {
      fn();
    }
    this.cleanupFns = [];
  }
}

Extensions and Challenges

Extension 1: Plugin System for Custom Agents

Create a plugin architecture so users can add their own agents:

// Plugin interface
interface AgentPlugin {
  id: string;
  name: string;
  description: string;
  capabilities: string[];
  createAgent: (config: AgentConfig) => BaseAgent;
}

// Plugin loader
class PluginLoader {
  async loadFromDirectory(dir: string) {
    const files = await glob(`${dir}/*.plugin.js`);
    for (const file of files) {
      const plugin = await import(file);
      this.registry.registerPlugin(plugin.default);
    }
  }
}

// Example plugin: Slack Agent
export default {
  id: 'slack',
  name: 'Slack Agent',
  capabilities: ['message', 'notify', 'channel_summary'],
  createAgent: (config) => new SlackAgent(config)
} satisfies AgentPlugin;

Extension 2: Voice Interface

Add voice input/output using Web Speech API:

// Voice input
const recognition = new webkitSpeechRecognition();
recognition.onresult = async (event) => {
  const transcript = event.results[0][0].transcript;
  await orchestrator.execute(transcript);
};

// Voice output (stream TTS)
async function speakStream(textStream: AsyncIterable<string>) {
  const utterance = new SpeechSynthesisUtterance();
  let buffer = '';

  for await (const chunk of textStream) {
    buffer += chunk;
    if (buffer.match(/[.!?]\s/)) {
      utterance.text = buffer;
      speechSynthesis.speak(utterance);
      buffer = '';
    }
  }
}

Extension 3: Multi-User Support

Transform from personal to team command center:

// User context isolation
class MultiTenantOrchestrator {
  private userContexts = new Map<string, ContextStore>();

  async execute(userId: string, input: string) {
    const context = this.getOrCreateContext(userId);
    const orchestrator = new Orchestrator({ context });
    return orchestrator.execute(input);
  }
}

// Shared knowledge base with access control
class SharedKnowledgeBase {
  async query(userId: string, query: string) {
    const accessibleDocs = await this.getAccessibleDocuments(userId);
    return this.vectorSearch(query, { filter: accessibleDocs });
  }
}

Extension 4: Workflow Templates

Create reusable multi-agent workflows:

# workflows/weekly-report.yaml
name: Weekly Report
description: Generate weekly status report and email to team
triggers:
  - schedule: "0 9 * * FRI"
  - command: "generate weekly report"

steps:
  - id: gather_tasks
    agent: calendar
    action: list_events
    input:
      period: last_week

  - id: gather_code
    agent: code
    action: summarize_commits
    input:
      period: last_week

  - id: draft_report
    agent: research
    action: synthesize
    input:
      calendar: "{{gather_tasks.result}}"
      code: "{{gather_code.result}}"
      template: weekly_report

  - id: send_email
    agent: email
    action: send
    input:
      to: team
      subject: "Weekly Report - {{current_date}}"
      body: "{{draft_report.result}}"

Resources

Books

Topic Book Relevant Chapters
Event-Driven Architecture โ€œDesigning Data-Intensive Applicationsโ€ by Martin Kleppmann Ch. 11 (Stream Processing) - for event sourcing and agent communication
Multi-Agent Systems โ€œArtificial Intelligence: A Modern Approachโ€ by Russell & Norvig Ch. 2 (Intelligent Agents) - agent architecture and design
API Design โ€œDesign and Build Great Web APIsโ€ by Mike Amundsen Ch. 3-5 - RESTful design, hypermedia, versioning
React Patterns โ€œLearning React, 2nd Editionโ€ by Eve Porcello Ch. 8, 12 - hooks, suspense, concurrent features

Official Documentation

  • LangGraph - Graph-based agent orchestration
  • AutoGPT - Autonomous agent framework
  • CrewAI - Multi-agent collaboration framework

Self-Assessment Checklist

Use this checklist to verify your understanding. You should be able to answer โ€œyesโ€ to all questions.

Architecture Understanding

  • Can you explain why we chose the Centralized Orchestrator pattern over Peer-to-Peer?
  • Can you draw the data flow from user input to agent output from memory?
  • Can you explain the tradeoffs between message passing and shared context stores?
  • Can you describe how the provider abstraction layer enables model flexibility?

Implementation Skills

  • Can you implement a new agent from scratch (e.g., a โ€œNotesโ€ agent)?
  • Can you add a new tool to an existing agent?
  • Can you modify the orchestrator to support parallel agent execution?
  • Can you implement rate limiting for a specific provider?

Multi-Agent Concepts

  • Can you explain how the orchestrator decomposes โ€œResearch X, then email Yโ€?
  • Can you describe how context flows from the research agent to the email agent?
  • Can you explain what happens when an agent in the middle of a chain fails?
  • Can you describe how to test a multi-agent workflow?

Production Readiness

  • Can you implement budget alerts that trigger graceful degradation?
  • Can you explain how to debug a failing multi-agent task?
  • Can you add a new agent without modifying existing code (plugin pattern)?
  • Can you implement context compression to prevent context explosion?

Integration Points

  • Can you explain how the CLI and Web dashboard share the same core logic?
  • Can you describe the SSE event format for streaming agent output?
  • Can you implement a new API endpoint following the existing patterns?
  • Can you add telemetry to track agent performance?

Synthesis Questions

  • How does this project use concepts from Project 1 (Expense Tracker)?
    • Answer: Schema-based structured output for task planning
  • How does this project use concepts from Project 2 (Document Summarizer)?
    • Answer: Real-time streaming for agent output display
  • How does this project use concepts from Project 3 (Code Review Agent)?
    • Answer: Tool calling and agent loops for autonomous execution
  • How does this project use concepts from Project 4 (Model Router)?
    • Answer: Provider abstraction for routing agents to optimal models
  • How does this project use concepts from Project 5 (Research Agent)?
    • Answer: Memory and context persistence across agent interactions

Connections to Previous Projects

This synthesis project ties together everything you have learned:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    PROJECT KNOWLEDGE SYNTHESIS                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                             โ”‚
โ”‚   PROJECT 1: Expense Tracker CLI                                           โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                             โ”‚
โ”‚   โ€ข generateObject for structured task planning                            โ”‚
โ”‚   โ€ข Zod schemas for type-safe agent definitions                            โ”‚
โ”‚   โ€ข CLI patterns with Commander.js                                         โ”‚
โ”‚                   โ”‚                                                         โ”‚
โ”‚                   โ–ผ                                                         โ”‚
โ”‚   PROJECT 2: Document Summarizer                                           โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                            โ”‚
โ”‚   โ€ข streamText for real-time agent output                                  โ”‚
โ”‚   โ€ข React hooks for consuming streams                                      โ”‚
โ”‚   โ€ข SSE patterns for web dashboard                                         โ”‚
โ”‚                   โ”‚                                                         โ”‚
โ”‚                   โ–ผ                                                         โ”‚
โ”‚   PROJECT 3: Code Review Agent                                             โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                              โ”‚
โ”‚   โ€ข Tool definitions for each agent                                        โ”‚
โ”‚   โ€ข Agent loops (maxSteps, stopWhen)                                       โ”‚
โ”‚   โ€ข Error handling for tool failures                                       โ”‚
โ”‚                   โ”‚                                                         โ”‚
โ”‚                   โ–ผ                                                         โ”‚
โ”‚   PROJECT 4: Multi-Provider Router                                         โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                          โ”‚
โ”‚   โ€ข Provider abstraction layer                                             โ”‚
โ”‚   โ€ข Model selection based on task/cost                                     โ”‚
โ”‚   โ€ข Fallback and retry patterns                                            โ”‚
โ”‚                   โ”‚                                                         โ”‚
โ”‚                   โ–ผ                                                         โ”‚
โ”‚   PROJECT 5: Autonomous Research Agent                                     โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                      โ”‚
โ”‚   โ€ข Memory and context persistence                                         โ”‚
โ”‚   โ€ข Vector storage for knowledge base                                      โ”‚
โ”‚   โ€ข Complex multi-step agent workflows                                     โ”‚
โ”‚                   โ”‚                                                         โ”‚
โ”‚                   โ–ผ                                                         โ”‚
โ”‚   PROJECT 6: AI COMMAND CENTER (This Project)                              โ”‚
โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                               โ”‚
โ”‚   All skills combined into a production multi-agent system                 โ”‚
โ”‚                                                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

When you complete this project, you will have:

  • Built a complete AI application from scratch
  • Implemented multi-agent orchestration
  • Created production-ready streaming interfaces
  • Managed costs across multiple providers
  • Designed for extensibility with plugins

This is the culmination of your AI SDK learning journey. The patterns and principles you learn here will transfer to any AI application you build in the future.