# ADR-0003: Multi-Agent AI System

**Date**: 2025-09-25  
**Status**: Accepted  
**Deciders**: AI Platform Team

## Context

Generating high-quality responses requires multiple specialized capabilities:

- Information retrieval (sources, citations)
- Teaching/instruction (persona style, pedagogy)
- Safety moderation (content policies)
- Audio narration (SSML preparation)

A single monolithic prompt cannot effectively handle all concerns.

## Decision

Implement a **Multi-Agent System (MAS)** where specialized agents collaborate:

### Agents

| Agent         | Responsibility                     |
| ------------- | ---------------------------------- |
| **Librarian** | Query planning, source retrieval   |
| **Teacher**   | Response generation, persona style |
| **Safety**    | Pre/post moderation                |
| **Narrator**  | SSML preparation for TTS           |

### Orchestration Pattern

1. **Parallel Phase**: Librarian + Safety pre-check run concurrently
2. **Generation Phase**: Teacher generates with sources
3. **Moderation Phase**: Safety post-check
4. **Narration Phase**: Narrator prepares SSML (if audio)

## Rationale

### Why Multi-Agent

- **Separation of concerns**: Each agent optimized for its task
- **Parallel execution**: Reduces latency
- **Modularity**: Agents can be updated independently
- **Testability**: Each agent tested in isolation

### Why This Agent Set

- Librarian: Specialized for retrieval-augmented queries
- Teacher: Focus on pedagogical quality
- Safety: Dedicated to policy enforcement
- Narrator: TTS-specific optimizations

## Alternatives Considered

1. **Single Large Prompt**: Too complex, hard to maintain
2. **Sequential Pipeline**: Higher latency
3. **Router-only**: Missing collaboration benefits

## Consequences

### Positive

- Better response quality
- Lower latency through parallelism
- Easier maintenance and testing
- Flexible agent composition

### Negative

- Coordination complexity
- More LLM calls (cost)
- Debug complexity

### Mitigations

- Comprehensive logging with correlation IDs
- Agent-level metrics
- Cost optimization through caching

## Related

- [Algorithms - Multi-Agent Orchestration](../algorithms.md#2-multi-agent-orchestration)
- AI Service: `services/ai/`
