# nthangarajan/12-factor-agents architecture

> Architecture diagram of the GitHub repository nthangarajan/12-factor-agents, 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/nthangarajan/12-factor-agents
- Repository: https://github.com/nthangarajan/12-factor-agents

## Overview

This repository is a practical guide to building reliable LLM applications, with workshop code that evolves a calculator agent into a threaded service with human interaction. The runtime example accepts a message, runs an agent loop, stores thread state, and exposes status and response endpoints; the later example adds HumanLayer contact and webhook handling. The graph emphasizes those demonstrated stages and the documented agent-design capabilities. Evidence is limited to the README and sampled files; unsampled workshop implementations are not assumed to have identical wiring.

Main entry points: [`workshops/2025-05/final/src/server.ts`](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/final/src/server.ts) (Thread API), [`workshops/2025-05-17/sections/03-tool-loop/src/agent.ts`](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05-17/sections/03-tool-loop/src/agent.ts) (Tool-loop agent), [`workshops/2025-05/sections/11-humanlayer-approval/src/agent.ts`](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/sections/11-humanlayer-approval/src/agent.ts) (Approval agent), [`workshops/2025-05/final/src/agent.ts`](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/final/src/agent.ts) (Agent loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_curriculum["Agent progression"]
  node_early_agent["Tool-loop agent<br/>[agent.ts]"]
  node_approval_agent["Approval agent<br/>[agent.ts]"]
end

subgraph group_runtime["Thread runtime"]
  node_service["Thread API<br/>[server.ts]"]
  node_agent["Agent loop<br/>[agent.ts]"]
  node_thread_store[("Thread store<br/>[state.ts]")]
end

subgraph group_human["Human interaction"]
  node_humanlayer{{"HumanLayer"}}
  node_webhook_service["Webhook example<br/>[server.ts]"]
end

node_developer(("User"))
node_http_client(("HTTP client"))
node_human_reviewer(("Human reviewer"))

node_http_client -->|"sends requests"| node_service
node_service -->|"runs loop"| node_agent
node_service -->|"reads and writes"| node_thread_store
node_developer -.->|"tries examples"| node_early_agent
node_developer -.->|"tries approval flow"| node_approval_agent
node_service -->|"creates contact"| node_humanlayer
node_humanlayer -.->|"requests input"| node_human_reviewer
node_humanlayer -.->|"posts completion"| node_webhook_service

click node_early_agent "https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05-17/sections/03-tool-loop/src/agent.ts"
click node_approval_agent "https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/sections/11-humanlayer-approval/src/agent.ts"
click node_service "https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/final/src/server.ts"
click node_agent "https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/final/src/agent.ts"
click node_thread_store "https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/final/src/state.ts"
click node_webhook_service "https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/sections/final/src/server.ts"

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_early_agent,node_approval_agent,node_developer,node_http_client,node_human_reviewer toneBlue
class node_service,node_agent,node_thread_store toneAmber
class node_humanlayer,node_webhook_service toneMint
```

## Components

### Agent progression

- [Tool-loop agent](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05-17/sections/03-tool-loop/src/agent.ts): `workshops/2025-05-17/sections/03-tool-loop/src/agent.ts`
- [Approval agent](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/sections/11-humanlayer-approval/src/agent.ts): `workshops/2025-05/sections/11-humanlayer-approval/src/agent.ts`

### Thread runtime

- [Thread API](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/final/src/server.ts): `workshops/2025-05/final/src/server.ts`
- [Agent loop](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/final/src/agent.ts): `workshops/2025-05/final/src/agent.ts`
- [Thread store](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/final/src/state.ts): `workshops/2025-05/final/src/state.ts`

### Human interaction

- **HumanLayer**
- [Webhook example](https://github.com/nthangarajan/12-factor-agents/blob/main/workshops/2025-05/sections/final/src/server.ts): `workshops/2025-05/sections/final/src/server.ts`

### Other components

- **User**
- **HTTP client**
- **Human reviewer**

## Connections

- HTTP client → Thread API: sends requests (evidence: `workshops/2025-05/final/src/server.ts`)
- Thread API → Agent loop: runs loop (evidence: `workshops/2025-05/final/src/server.ts`)
- Thread API → Thread store: reads and writes (evidence: `workshops/2025-05/final/src/server.ts`)
- User → Tool-loop agent: tries examples (evidence: `README.md`)
- User → Approval agent: tries approval flow (evidence: `README.md`)
- Thread API → HumanLayer: creates contact
- HumanLayer → Human reviewer: requests input
- HumanLayer → Webhook example: posts completion
