# ericthz/zebra architecture

> Architecture diagram of the GitHub repository ericthz/zebra, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ericthz/zebra
- Repository: https://github.com/ericthz/zebra

## Overview

Zebra is a pure-Go AI-agent reference implementation, exposed through an interactive CLI, an HTTP API, and a standalone MCP server. The primary workflow accepts a user request, runs an agent conversation with model routing and optional tools, skills, memory, and knowledge retrieval, then returns a response. The repository also documents multiple agent modes and capabilities such as voice, asynchronous tasks, and shadow evaluation. Connections reflect the shown excerpts and README; unsampled implementation details are represented only where documented.

Main entry points: [`internal/agent/agent.go`](https://github.com/ericthz/zebra/blob/dev/internal/agent/agent.go) (Agent engine), [`internal/server/server.go`](https://github.com/ericthz/zebra/blob/dev/internal/server/server.go) (HTTP API), [`cmd/server/main.go`](https://github.com/ericthz/zebra/blob/dev/cmd/server/main.go) (Server assembly), [`cmd/zebra/main.go`](https://github.com/ericthz/zebra/blob/dev/cmd/zebra/main.go) (Interactive CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["Interactive CLI<br/>[main.go]"]
  node_api["HTTP API<br/>[server.go]"]
  node_server_boot["Server assembly<br/>[main.go]"]
  node_mcp_boot["MCP entrypoint<br/>[main.go]"]
end

subgraph group_runtime["Agent runtime"]
  node_agent["Agent engine<br/>[agent.go]"]
  node_agent_modes["Agent modes<br/>[plan.go]"]
  node_supervisor["Worker routing<br/>[supervisor.go]"]
end

subgraph group_context["Context capabilities"]
  node_rag["Knowledge retrieval<br/>[index.go]"]
  node_skills["Skill injection<br/>[retrieve.go]"]
  node_memory["Conversation memory<br/>[memory.go]"]
  node_context_window["Context budgeting<br/>[context.go]"]
end

subgraph group_service["Service features"]
  node_voice["Voice interaction<br/>[voice.go]"]
  node_tasks["Async tasks<br/>[tasks.go]"]
  node_shadow["Shadow evaluation<br/>[shadow.go]"]
  node_env["Environment inventory<br/>[env.go]"]
  node_inventory["Capability inventory<br/>[inventory.go]"]
  node_feedback["User feedback<br/>[feedback.go]"]
end

subgraph group_integration["Model and tools"]
  node_provider["Model routing<br/>[router.go]"]
  node_tools["Tool execution<br/>[registry.go]"]
  node_mcp["MCP server<br/>[server.go]"]
end

node_cli_user(("CLI user"))
node_http_user(("HTTP client"))

node_cli_user -->|"enters requests"| node_cli
node_http_user -->|"posts chat"| node_api
node_cli -->|"runs conversation"| node_agent
node_cli -->|"selects mode"| node_agent_modes
node_api -->|"builds agent"| node_agent
node_server_boot -->|"assembles service"| node_api
node_agent -->|"requests completion"| node_provider
node_agent -->|"executes tool calls"| node_tools
node_agent -->|"retrieves context"| node_rag
node_agent -->|"injects skills"| node_skills
node_agent -->|"uses memory"| node_memory
node_agent -->|"trims messages"| node_context_window
node_agent_modes -->|"reuses engine"| node_agent
node_supervisor -->|"builds workers"| node_agent
node_supervisor -->|"routes requests"| node_provider
node_server_boot -->|"loads documents"| node_rag
node_rag -->|"embeds chunks"| node_memory
node_mcp_boot -->|"starts transport"| node_mcp
node_mcp_boot -->|"registers tools"| node_tools
node_api -->|"serves task routes"| node_tasks
node_tasks -->|"runs task"| node_agent
node_server_boot -.->|"configures optionally"| node_voice
node_api -.->|"supports evaluation"| node_shadow
node_server_boot -.->|"configures evaluator"| node_shadow
node_api -->|"serves feedback routes"| node_feedback
node_cli -->|"prints capabilities"| node_inventory
node_server_boot -->|"loads configuration"| node_env

click node_cli "https://github.com/ericthz/zebra/blob/dev/cmd/zebra/main.go"
click node_api "https://github.com/ericthz/zebra/blob/dev/internal/server/server.go"
click node_server_boot "https://github.com/ericthz/zebra/blob/dev/cmd/server/main.go"
click node_mcp_boot "https://github.com/ericthz/zebra/blob/dev/cmd/mcp/main.go"
click node_agent "https://github.com/ericthz/zebra/blob/dev/internal/agent/agent.go"
click node_agent_modes "https://github.com/ericthz/zebra/blob/dev/internal/agent/plan.go"
click node_supervisor "https://github.com/ericthz/zebra/blob/dev/internal/supervisor/supervisor.go"
click node_provider "https://github.com/ericthz/zebra/blob/dev/internal/provider/router.go"
click node_tools "https://github.com/ericthz/zebra/blob/dev/internal/tool/registry.go"
click node_mcp "https://github.com/ericthz/zebra/blob/dev/internal/mcp/server.go"
click node_rag "https://github.com/ericthz/zebra/blob/dev/internal/rag/index.go"
click node_skills "https://github.com/ericthz/zebra/blob/dev/internal/skill/retrieve.go"
click node_memory "https://github.com/ericthz/zebra/blob/dev/internal/memory/memory.go"
click node_context_window "https://github.com/ericthz/zebra/blob/dev/internal/agent/context.go"
click node_voice "https://github.com/ericthz/zebra/blob/dev/internal/provider/voice.go"
click node_tasks "https://github.com/ericthz/zebra/blob/dev/internal/server/tasks.go"
click node_shadow "https://github.com/ericthz/zebra/blob/dev/internal/eval/shadow.go"
click node_env "https://github.com/ericthz/zebra/blob/dev/internal/observe/env.go"
click node_inventory "https://github.com/ericthz/zebra/blob/dev/internal/observe/inventory.go"
click node_feedback "https://github.com/ericthz/zebra/blob/dev/internal/server/feedback.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_api,node_server_boot,node_mcp_boot,node_cli_user,node_http_user toneBlue
class node_agent,node_agent_modes,node_supervisor toneAmber
class node_rag,node_skills,node_memory,node_context_window toneMint
class node_voice,node_tasks,node_shadow,node_env,node_inventory,node_feedback toneRose
class node_provider,node_tools,node_mcp toneIndigo
```

## Components

### Entry points

- [Interactive CLI](https://github.com/ericthz/zebra/blob/dev/cmd/zebra/main.go): `cmd/zebra/main.go`
- [HTTP API](https://github.com/ericthz/zebra/blob/dev/internal/server/server.go): `internal/server/server.go`
- [Server assembly](https://github.com/ericthz/zebra/blob/dev/cmd/server/main.go): `cmd/server/main.go`
- [MCP entrypoint](https://github.com/ericthz/zebra/blob/dev/cmd/mcp/main.go): `cmd/mcp/main.go`

### Agent runtime

- [Agent engine](https://github.com/ericthz/zebra/blob/dev/internal/agent/agent.go): `internal/agent/agent.go`
- [Agent modes](https://github.com/ericthz/zebra/blob/dev/internal/agent/plan.go): `internal/agent/plan.go`
- [Worker routing](https://github.com/ericthz/zebra/blob/dev/internal/supervisor/supervisor.go): `internal/supervisor/supervisor.go`

### Context capabilities

- [Knowledge retrieval](https://github.com/ericthz/zebra/blob/dev/internal/rag/index.go): `internal/rag/index.go`
- [Skill injection](https://github.com/ericthz/zebra/blob/dev/internal/skill/retrieve.go): `internal/skill/retrieve.go`
- [Conversation memory](https://github.com/ericthz/zebra/blob/dev/internal/memory/memory.go): `internal/memory/memory.go`
- [Context budgeting](https://github.com/ericthz/zebra/blob/dev/internal/agent/context.go): `internal/agent/context.go`

### Service features

- [Voice interaction](https://github.com/ericthz/zebra/blob/dev/internal/provider/voice.go): `internal/provider/voice.go`
- [Async tasks](https://github.com/ericthz/zebra/blob/dev/internal/server/tasks.go): `internal/server/tasks.go`
- [Shadow evaluation](https://github.com/ericthz/zebra/blob/dev/internal/eval/shadow.go): `internal/eval/shadow.go`
- [Environment inventory](https://github.com/ericthz/zebra/blob/dev/internal/observe/env.go): `internal/observe/env.go`
- [Capability inventory](https://github.com/ericthz/zebra/blob/dev/internal/observe/inventory.go): `internal/observe/inventory.go`
- [User feedback](https://github.com/ericthz/zebra/blob/dev/internal/server/feedback.go): `internal/server/feedback.go`

### Model and tools

- [Model routing](https://github.com/ericthz/zebra/blob/dev/internal/provider/router.go): `internal/provider/router.go`
- [Tool execution](https://github.com/ericthz/zebra/blob/dev/internal/tool/registry.go): `internal/tool/registry.go`
- [MCP server](https://github.com/ericthz/zebra/blob/dev/internal/mcp/server.go): `internal/mcp/server.go`

### Other components

- **CLI user**
- **HTTP client**

## Connections

- CLI user → Interactive CLI: enters requests (evidence: `README.md`)
- HTTP client → HTTP API: posts chat (evidence: `README.md`)
- Interactive CLI → Agent engine: runs conversation (evidence: `cmd/zebra/main.go`)
- Interactive CLI → Agent modes: selects mode (evidence: `cmd/zebra/main.go`)
- HTTP API → Agent engine: builds agent
- Server assembly → HTTP API: assembles service (evidence: `README.md`)
- Agent engine → Model routing: requests completion (evidence: `internal/agent/agent.go`)
- Agent engine → Tool execution: executes tool calls (evidence: `internal/agent/agent.go`)
- Agent engine → Knowledge retrieval: retrieves context (evidence: `internal/agent/agent.go`)
- Agent engine → Skill injection: injects skills (evidence: `internal/agent/agent.go`)
- Agent engine → Conversation memory: uses memory (evidence: `internal/agent/agent.go`)
- Agent engine → Context budgeting: trims messages (evidence: `internal/agent/agent.go`)
- Agent modes → Agent engine: reuses engine (evidence: `internal/agent/agent.go`)
- Worker routing → Agent engine: builds workers
- Worker routing → Model routing: routes requests (evidence: `internal/supervisor/supervisor.go`)
- Server assembly → Knowledge retrieval: loads documents (evidence: `cmd/server/main.go`)
- Knowledge retrieval → Conversation memory: embeds chunks (evidence: `internal/rag/index.go`)
- MCP entrypoint → MCP server: starts transport (evidence: `cmd/mcp/main.go`)
- MCP entrypoint → Tool execution: registers tools (evidence: `cmd/mcp/main.go`)
- HTTP API → Async tasks: serves task routes (evidence: `internal/server/server.go`)
- Async tasks → Agent engine: runs task (evidence: `internal/server/tasks.go`)
- Server assembly → Voice interaction: configures optionally (evidence: `cmd/server/main.go`)
- HTTP API → Shadow evaluation: supports evaluation (evidence: `internal/server/server.go`)
- Server assembly → Shadow evaluation: configures evaluator (evidence: `cmd/server/main.go`)
- HTTP API → User feedback: serves feedback routes (evidence: `internal/server/server.go`)
- Interactive CLI → Capability inventory: prints capabilities (evidence: `internal/observe/inventory.go`)
- Server assembly → Environment inventory: loads configuration (evidence: `cmd/server/main.go`)
