# cayu-dev/cayu architecture

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

- Interactive diagram: https://gitdiagram.com/cayu-dev/cayu
- Repository: https://github.com/cayu-dev/cayu
- Video tour (about a minute): https://gitdiagram.com/cayu-dev/cayu/video

## Overview

Cayu is a Python framework and runtime for building long-running agents. The main workflow composes an application and agent, runs resumable sessions through model and tool calls, and records durable state; policy, approvals, budgets, tasks, and recovery support that execution. Separate branches cover collaboration, knowledge, artifacts, evaluation, and operations. Edges use README capability descriptions or the supplied source references; unsampled internals are represented only where documented, not as inferred call chains.

Main entry points: [`src/cayu/runtime/_session_engine.py`](https://github.com/cayu-dev/cayu/blob/main/src/cayu/runtime/_session_engine.py) (Session orchestration), [`src/cayu/applications.py`](https://github.com/cayu-dev/cayu/blob/main/src/cayu/applications.py) (Application composition), [`src/cayu/tasks/contracts.py`](https://github.com/cayu-dev/cayu/blob/main/src/cayu/tasks/contracts.py) (Background tasks), [`src/cayu/approvals/tools.py`](https://github.com/cayu-dev/cayu/blob/main/src/cayu/approvals/tools.py) (Tool approval policy)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Agent runtime"]
  node_application["Application composition<br/>[applications.py]"]
  node_session["Session orchestration<br/>[_session_engine.py]"]
  node_session_records["Session records<br/>[records.py]"]
  node_events["Runtime events<br/>[events.py]"]
  node_storage[("Application stores<br/>[application.py]")]
  node_provider["Model providers"]
  node_context["Context and output"]
  node_validation["Input validation<br/>[_validation.py]"]
  node_exceptions["Failure handling"]
end

subgraph group_controls["Authority and work"]
  node_approvals["Human approvals<br/>[review.py]"]
  node_approval_tools["Tool approval policy<br/>[tools.py]"]
  node_user_input["Human input<br/>[user_input.py]"]
  node_budgets["Spend limits<br/>[base.py]"]
  node_pricing["Model pricing<br/>[pricing.py]"]
  node_usage["Usage accounting<br/>[usage.py]"]
  node_tasks["Background tasks<br/>[contracts.py]"]
  node_task_records["Task records<br/>[records.py]"]
  node_task_wait["Task waiting<br/>[_task_wait.py]"]
end

subgraph group_capabilities["Agent capabilities"]
  node_collaboration["Agent collaboration"]
  node_knowledge["Reviewed knowledge"]
  node_artifacts["Artifacts and workspaces"]
end

subgraph group_operations["Evaluation and operations"]
  node_evals["Evaluation and replay"]
  node_server["Control-plane API<br/>[routes.py]"]
  node_dashboard["Operator dashboard<br/>[main.tsx]"]
  node_cli["Developer CLI"]
end

node_developer(("Application developer"))
node_operator(("Agent operator"))

node_developer -->|"composes"| node_application
node_application -->|"runs sessions"| node_session
node_session -->|"calls models"| node_provider
node_session -->|"assembles context"| node_context
node_session -->|"persists state"| node_storage
node_session -.->|"tracks sessions"| node_session_records
node_session -->|"records events"| node_events
node_application -->|"validates inputs"| node_validation
node_session -.->|"handles failures"| node_exceptions
node_session -->|"checks tool policy"| node_approval_tools
node_approval_tools -->|"requests review"| node_approvals
node_session -->|"awaits input"| node_user_input
node_session -->|"checks spend"| node_budgets
node_budgets -.->|"prices calls"| node_pricing
node_session -->|"accounts usage"| node_usage
node_application -->|"dispatches work"| node_tasks
node_tasks -.->|"uses records"| node_task_records
node_tasks -.->|"waits for work"| node_task_wait
node_session -->|"supports delegation"| node_collaboration
node_application -->|"offers knowledge"| node_knowledge
node_application -->|"supports artifacts"| node_artifacts
node_developer -->|"evaluates agents"| node_evals
node_operator -->|"operates runtime"| node_server
node_server -->|"serves operations UI"| node_dashboard
node_operator -->|"uses CLI"| node_cli

click node_application "https://github.com/cayu-dev/cayu/blob/main/src/cayu/applications.py"
click node_session "https://github.com/cayu-dev/cayu/blob/main/src/cayu/runtime/_session_engine.py"
click node_session_records "https://github.com/cayu-dev/cayu/blob/main/src/cayu/sessions/records.py"
click node_events "https://github.com/cayu-dev/cayu/blob/main/src/cayu/events.py"
click node_storage "https://github.com/cayu-dev/cayu/blob/main/src/cayu/storage/application.py"
click node_provider "https://github.com/cayu-dev/cayu/tree/main/src/cayu/providers"
click node_context "https://github.com/cayu-dev/cayu/blob/main/src/cayu/context/structured_output.py"
click node_validation "https://github.com/cayu-dev/cayu/blob/main/src/cayu/_validation.py"
click node_exceptions "https://github.com/cayu-dev/cayu/blob/main/src/cayu/_exception_groups.py"
click node_approvals "https://github.com/cayu-dev/cayu/blob/main/src/cayu/approvals/review.py"
click node_approval_tools "https://github.com/cayu-dev/cayu/blob/main/src/cayu/approvals/tools.py"
click node_user_input "https://github.com/cayu-dev/cayu/blob/main/src/cayu/approvals/user_input.py"
click node_budgets "https://github.com/cayu-dev/cayu/blob/main/src/cayu/budgets/base.py"
click node_pricing "https://github.com/cayu-dev/cayu/blob/main/src/cayu/budgets/pricing.py"
click node_usage "https://github.com/cayu-dev/cayu/blob/main/src/cayu/budgets/usage.py"
click node_tasks "https://github.com/cayu-dev/cayu/blob/main/src/cayu/tasks/contracts.py"
click node_task_records "https://github.com/cayu-dev/cayu/blob/main/src/cayu/tasks/records.py"
click node_task_wait "https://github.com/cayu-dev/cayu/blob/main/src/cayu/_task_wait.py"
click node_collaboration "https://github.com/cayu-dev/cayu/tree/main/src/cayu/collaboration"
click node_knowledge "https://github.com/cayu-dev/cayu/tree/main/src/cayu/knowledge"
click node_artifacts "https://github.com/cayu-dev/cayu/tree/main/src/cayu/artifacts"
click node_evals "https://github.com/cayu-dev/cayu/tree/main/src/cayu/evals"
click node_server "https://github.com/cayu-dev/cayu/blob/main/src/cayu/server/routes.py"
click node_dashboard "https://github.com/cayu-dev/cayu/blob/main/dashboard/src/main.tsx"
click node_cli "https://github.com/cayu-dev/cayu/tree/main/src/cayu/cli"

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_application,node_session,node_session_records,node_events,node_storage,node_provider,node_context,node_validation,node_exceptions toneBlue
class node_approvals,node_approval_tools,node_user_input,node_budgets,node_pricing,node_usage,node_tasks,node_task_records,node_task_wait toneAmber
class node_collaboration,node_knowledge,node_artifacts toneMint
class node_evals,node_server,node_dashboard,node_cli toneRose
class node_developer,node_operator toneIndigo
```

## Components

### Agent runtime

- [Application composition](https://github.com/cayu-dev/cayu/blob/main/src/cayu/applications.py): `src/cayu/applications.py`
- [Session orchestration](https://github.com/cayu-dev/cayu/blob/main/src/cayu/runtime/_session_engine.py): `src/cayu/runtime/_session_engine.py`
- [Session records](https://github.com/cayu-dev/cayu/blob/main/src/cayu/sessions/records.py): `src/cayu/sessions/records.py`
- [Runtime events](https://github.com/cayu-dev/cayu/blob/main/src/cayu/events.py): `src/cayu/events.py`
- [Application stores](https://github.com/cayu-dev/cayu/blob/main/src/cayu/storage/application.py): `src/cayu/storage/application.py`
- [Model providers](https://github.com/cayu-dev/cayu/tree/main/src/cayu/providers): `src/cayu/providers`
- [Context and output](https://github.com/cayu-dev/cayu/blob/main/src/cayu/context/structured_output.py): `src/cayu/context/structured_output.py`
- [Input validation](https://github.com/cayu-dev/cayu/blob/main/src/cayu/_validation.py): `src/cayu/_validation.py`
- [Failure handling](https://github.com/cayu-dev/cayu/blob/main/src/cayu/_exception_groups.py): `src/cayu/_exception_groups.py`

### Authority and work

- [Human approvals](https://github.com/cayu-dev/cayu/blob/main/src/cayu/approvals/review.py): `src/cayu/approvals/review.py`
- [Tool approval policy](https://github.com/cayu-dev/cayu/blob/main/src/cayu/approvals/tools.py): `src/cayu/approvals/tools.py`
- [Human input](https://github.com/cayu-dev/cayu/blob/main/src/cayu/approvals/user_input.py): `src/cayu/approvals/user_input.py`
- [Spend limits](https://github.com/cayu-dev/cayu/blob/main/src/cayu/budgets/base.py): `src/cayu/budgets/base.py`
- [Model pricing](https://github.com/cayu-dev/cayu/blob/main/src/cayu/budgets/pricing.py): `src/cayu/budgets/pricing.py`
- [Usage accounting](https://github.com/cayu-dev/cayu/blob/main/src/cayu/budgets/usage.py): `src/cayu/budgets/usage.py`
- [Background tasks](https://github.com/cayu-dev/cayu/blob/main/src/cayu/tasks/contracts.py): `src/cayu/tasks/contracts.py`
- [Task records](https://github.com/cayu-dev/cayu/blob/main/src/cayu/tasks/records.py): `src/cayu/tasks/records.py`
- [Task waiting](https://github.com/cayu-dev/cayu/blob/main/src/cayu/_task_wait.py): `src/cayu/_task_wait.py`

### Agent capabilities

- [Agent collaboration](https://github.com/cayu-dev/cayu/tree/main/src/cayu/collaboration): `src/cayu/collaboration`
- [Reviewed knowledge](https://github.com/cayu-dev/cayu/tree/main/src/cayu/knowledge): `src/cayu/knowledge`
- [Artifacts and workspaces](https://github.com/cayu-dev/cayu/tree/main/src/cayu/artifacts): `src/cayu/artifacts`

### Evaluation and operations

- [Evaluation and replay](https://github.com/cayu-dev/cayu/tree/main/src/cayu/evals): `src/cayu/evals`
- [Control-plane API](https://github.com/cayu-dev/cayu/blob/main/src/cayu/server/routes.py): `src/cayu/server/routes.py`
- [Operator dashboard](https://github.com/cayu-dev/cayu/blob/main/dashboard/src/main.tsx): `dashboard/src/main.tsx`
- [Developer CLI](https://github.com/cayu-dev/cayu/tree/main/src/cayu/cli): `src/cayu/cli`

### Other components

- **Application developer**
- **Agent operator**

## Connections

- Application developer → Application composition: composes
- Application composition → Session orchestration: runs sessions
- Session orchestration → Model providers: calls models
- Session orchestration → Context and output: assembles context
- Session orchestration → Application stores: persists state
- Session orchestration → Session records: tracks sessions
- Session orchestration → Runtime events: records events
- Application composition → Input validation: validates inputs (evidence: `src/cayu/applications.py`)
- Session orchestration → Failure handling: handles failures (evidence: `src/cayu/runtime/_session_engine.py`)
- Session orchestration → Tool approval policy: checks tool policy (evidence: `src/cayu/runtime/_session_engine.py`)
- Tool approval policy → Human approvals: requests review (evidence: `src/cayu/approvals/tools.py`)
- Session orchestration → Human input: awaits input (evidence: `src/cayu/runtime/_session_engine.py`)
- Session orchestration → Spend limits: checks spend
- Spend limits → Model pricing: prices calls (evidence: `src/cayu/budgets/base.py`)
- Session orchestration → Usage accounting: accounts usage
- Application composition → Background tasks: dispatches work
- Background tasks → Task records: uses records (evidence: `src/cayu/tasks/records.py`)
- Background tasks → Task waiting: waits for work
- Session orchestration → Agent collaboration: supports delegation
- Application composition → Reviewed knowledge: offers knowledge
- Application composition → Artifacts and workspaces: supports artifacts (evidence: `src/cayu/applications.py`)
- Application developer → Evaluation and replay: evaluates agents
- Agent operator → Control-plane API: operates runtime
- Control-plane API → Operator dashboard: serves operations UI
- Agent operator → Developer CLI: uses CLI
