# ai-evals-course/cartwheel-homeworks architecture

> Architecture diagram of the GitHub repository ai-evals-course/cartwheel-homeworks, 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/ai-evals-course/cartwheel-homeworks
- Repository: https://github.com/ai-evals-course/cartwheel-homeworks

## Overview

Cartwheel is both a fictional commerce-support agent and a course project for evaluating and improving agents. The main workflow is a shopper, merchant, or support user entering through the CLI or server; the agent applies identity and safety checks, uses support tools and seeded commerce data, then replies or escalates. Separate course workflows analyze traces, replay evaluation cases, monitor scores, and optimize agent behavior. Some links reflect README-documented capabilities; unsampled modules are represented only where their purpose is documented or indexed.

Main entry points: [`agent/agent.py`](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/agent.py) (Support agent), [`agent/tools.py`](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/tools.py) (Support tools), [`replay/rollout.py`](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/replay/rollout.py) (Case replay), [`server/app.py`](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/server/app.py) (Session API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Support agent"]
  node_cli["Chat CLI<br/>[cli.py]"]
  node_server["Session API<br/>[app.py]"]
  node_agent["Support agent<br/>[agent.py]"]
  node_tools["Support tools<br/>[tools.py]"]
  node_auth["Access control<br/>[auth.py]"]
  node_guards["Safety guards<br/>[guards.py]"]
  node_approvals["Refund approvals<br/>[approvals.py]"]
  node_review["Human review<br/>[review.py]"]
end

subgraph group_world["Commerce world"]
  node_helpcenter["Policy search<br/>[helpcenter.py]"]
  node_database[("Commerce data<br/>[db.py]")]
  node_seed["World generator<br/>[generate.py]"]
end

subgraph group_analysis["Trace analysis"]
  node_analysis_ui["Analysis interface<br/>[server.py]"]
  node_analysis_tools["Analysis workflow<br/>[tools.py]"]
  node_trace_io["Trace and label I/O<br/>[langfuse_io.py]"]
end

subgraph group_evaluation["Evaluation and improvement"]
  node_replay["Case replay<br/>[rollout.py]"]
  node_harness["Replay harness<br/>[harness.py]"]
  node_monitoring["Evaluation monitoring<br/>[run_judges.py]"]
  node_optimization["Agent optimization<br/>[workflow.py]"]
  node_harbor["Harbor export<br/>[export.py]"]
end

subgraph group_integrations["External integrations"]
  node_tracing["Trace instrumentation<br/>[instrument.py]"]
  node_langfuse["Langfuse"]
end

node_shopper(("User"))

node_shopper -->|"starts chat"| node_cli
node_shopper -->|"sends requests"| node_server
node_cli -->|"runs agent"| node_agent
node_server -->|"routes messages"| node_agent
node_server -->|"builds identity"| node_auth
node_server -->|"configures tracing"| node_tracing
node_agent -->|"registers tools"| node_tools
node_agent -->|"uses guards"| node_guards
node_agent -->|"instruments runs"| node_tracing
node_tools -->|"checks permissions"| node_auth
node_tools -->|"reads and writes"| node_database
node_tools -->|"searches policies"| node_helpcenter
node_tools -.->|"requests approval"| node_approvals
node_review -->|"reviews requests"| node_approvals
node_seed -->|"populates world"| node_database
node_agent -->|"loads configuration"| node_database
node_analysis_ui -->|"exposes workflow"| node_analysis_tools
node_analysis_tools -->|"loads traces"| node_trace_io
node_trace_io -->|"reads and labels"| node_langfuse
node_tracing -->|"exports spans"| node_langfuse
node_replay -->|"runs cases"| node_agent
node_replay -->|"resets world"| node_seed
node_harness -->|"repeats rollouts"| node_replay
node_monitoring -->|"runs judges"| node_agent
node_monitoring -->|"uses judge tools"| node_analysis_tools
node_optimization -->|"evaluates changes"| node_replay
node_harbor -->|"exports cases"| node_replay

click node_cli "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/cli.py"
click node_server "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/server/app.py"
click node_agent "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/agent.py"
click node_tools "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/tools.py"
click node_auth "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/auth.py"
click node_guards "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/guards.py"
click node_approvals "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/approvals.py"
click node_review "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/review.py"
click node_helpcenter "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/helpcenter.py"
click node_database "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/db.py"
click node_seed "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/seed/generate.py"
click node_tracing "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/observability/instrument.py"
click node_analysis_ui "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/analysis/server.py"
click node_analysis_tools "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/analysis/helpers/tools.py"
click node_trace_io "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/analysis/helpers/langfuse_io.py"
click node_replay "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/replay/rollout.py"
click node_harness "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/replay/harness.py"
click node_monitoring "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/monitoring/run_judges.py"
click node_optimization "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/optimize/workflow.py"
click node_harbor "https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/harbor_adapter/export.py"

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_server,node_agent,node_tools,node_auth,node_guards,node_approvals,node_review,node_shopper toneBlue
class node_helpcenter,node_database,node_seed toneAmber
class node_analysis_ui,node_analysis_tools,node_trace_io toneMint
class node_replay,node_harness,node_monitoring,node_optimization,node_harbor toneRose
class node_tracing,node_langfuse toneIndigo
```

## Components

### Support agent

- [Chat CLI](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/cli.py): `agent/cli.py`
- [Session API](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/server/app.py): `server/app.py`
- [Support agent](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/agent.py): `agent/agent.py`
- [Support tools](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/tools.py): `agent/tools.py`
- [Access control](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/auth.py): `agent/auth.py`
- [Safety guards](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/guards.py): `agent/guards.py`
- [Refund approvals](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/approvals.py): `agent/approvals.py`
- [Human review](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/review.py): `agent/review.py`

### Commerce world

- [Policy search](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/helpcenter.py): `agent/helpcenter.py`
- [Commerce data](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/agent/db.py): `agent/db.py`
- [World generator](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/seed/generate.py): `seed/generate.py`

### Trace analysis

- [Analysis interface](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/analysis/server.py): `analysis/server.py`
- [Analysis workflow](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/analysis/helpers/tools.py): `analysis/helpers/tools.py`
- [Trace and label I/O](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/analysis/helpers/langfuse_io.py): `analysis/helpers/langfuse_io.py`

### Evaluation and improvement

- [Case replay](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/replay/rollout.py): `replay/rollout.py`
- [Replay harness](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/replay/harness.py): `replay/harness.py`
- [Evaluation monitoring](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/monitoring/run_judges.py): `monitoring/run_judges.py`
- [Agent optimization](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/optimize/workflow.py): `optimize/workflow.py`
- [Harbor export](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/harbor_adapter/export.py): `harbor_adapter/export.py`

### External integrations

- [Trace instrumentation](https://github.com/ai-evals-course/cartwheel-homeworks/blob/main/observability/instrument.py): `observability/instrument.py`
- **Langfuse**

### Other components

- **User**

## Connections

- User → Chat CLI: starts chat (evidence: `README.md`)
- User → Session API: sends requests (evidence: `README.md`)
- Chat CLI → Support agent: runs agent (evidence: `README.md`)
- Session API → Support agent: routes messages (evidence: `server/app.py`)
- Session API → Access control: builds identity (evidence: `server/app.py`)
- Session API → Trace instrumentation: configures tracing (evidence: `server/app.py`)
- Support agent → Support tools: registers tools (evidence: `agent/agent.py`)
- Support agent → Safety guards: uses guards (evidence: `agent/agent.py`)
- Support agent → Trace instrumentation: instruments runs (evidence: `agent/agent.py`)
- Support tools → Access control: checks permissions (evidence: `agent/tools.py`)
- Support tools → Commerce data: reads and writes (evidence: `agent/tools.py`)
- Support tools → Policy search: searches policies (evidence: `agent/tools.py`)
- Support tools → Refund approvals: requests approval
- Human review → Refund approvals: reviews requests (evidence: `agent/review.py`)
- World generator → Commerce data: populates world (evidence: `seed/generate.py`)
- Support agent → Commerce data: loads configuration (evidence: `agent/agent.py`)
- Analysis interface → Analysis workflow: exposes workflow (evidence: `analysis/server.py`)
- Analysis workflow → Trace and label I/O: loads traces (evidence: `analysis/helpers/tools.py`)
- Trace and label I/O → Langfuse: reads and labels (evidence: `analysis/helpers/langfuse_io.py`)
- Trace instrumentation → Langfuse: exports spans (evidence: `README.md`)
- Case replay → Support agent: runs cases (evidence: `replay/rollout.py`)
- Case replay → World generator: resets world (evidence: `replay/rollout.py`)
- Replay harness → Case replay: repeats rollouts (evidence: `replay/harness.py`)
- Evaluation monitoring → Support agent: runs judges (evidence: `monitoring/run_judges.py`)
- Evaluation monitoring → Analysis workflow: uses judge tools (evidence: `monitoring/run_judges.py`)
- Agent optimization → Case replay: evaluates changes (evidence: `optimize/workflow.py`)
- Harbor export → Case replay: exports cases (evidence: `harbor_adapter/export.py`)
