# tanlinru/langgraph-agent-v2 architecture

> Architecture diagram of the GitHub repository tanlinru/langgraph-agent-v2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanlinru/langgraph-agent-v2
- Repository: https://github.com/tanlinru/langgraph-agent-v2

## Overview

#### Purpose and entry points
This is a local-first multi-agent platform built on LangChain/LangGraph and FastAPI. It supports single-agent chat, supervised multi-agent orchestration, JSON-defined workflows, external ACP coding agents, persistent memory, and offline regression evaluation.

Primary entry points:
- HTTP/SSE server: `server.py`, `src/agent/main.py`
- CLI chat: `python -m src.agent.main`
- Vue client: `ui/src/main.ts`, `ui/src/App.vue`
- Backend runtime configuration: `src/agent/config.py`, `config/agents.json`

#### API and streaming boundary
FastAPI exposes chat, orchestration, workflow, session, memory/file, ACP, and eval APIs. Backend execution is normalized into structured SSE events, forming the principal contract with the UI: thinking, tool calls, plans, task updates, interrupts, messages, metrics, errors, and completion.

Relevant paths:
- `server.py`
- `src/agent/events.py`
- `ui/src/utils/api/sse.ts`

The frontend consumes streams through centralized message and stream management rather than components directly owning transport state:
- `ui/src/utils/messageManager.ts`
- `ui/src/utils/streamManager.ts`
- `ui/src/stores/chat.ts`

#### Single-agent execution
The direct chat path runs a LangChain ReAct-style agent with configured model, prompts, skills, context, and built-in tools. It is appropriate for tasks that do not need explicit decomposition or agent coordination.

Core boundaries:
- Agent loop: `src/agent/agent/core.py`
- Model resolution and settings: `src/agent/models.py`, `src/agent/config.py`
- Prompt and skill injection: `src/agent/prompts/system_prompt.py`, `src/agent/skills.py`
- Local tools: `src/agent/tools/execute_code.py`, `src/agent/tools/file_ops.py`, `src/agent/tools/search.py`

#### Multi-agent orchestrator
The orchestration path is a LangGraph `StateGraph` that plans work, pauses for human review, dispatches dependency-aware subagents, synthesizes output, and reflects/audits results. The planner produces structured steps; dispatch resolves agent assignments and passes upstream outputs into dependent tasks.

Core implementation:
- Graph lifecycle: `src/agent/orchestrator/core.py`
- Plan schema and planning helpers: `src/agent/orchestrator/planner.py`
- Subagent and ACP dispatch tools: `src/agent/orchestrator/tools.py`
- Agent node execution: `src/agent/orchestrator/agent_node.py`

The HITL review boundary is surfaced as an SSE interrupt and resumed through the orchestration review API.

#### Configurable workflow engine
A separate workflow subsystem executes JSON DAGs containing agent, approval, and finish nodes. It supports reusable workflow definitions, command routing, context propagation, and subgraph construction; this is distinct from the supervisor-generated orchestration plan.

Relevant paths:
- JSON workflow definitions: `config/workflows.json`
- Graph configuration access: `src/agent/workflow/graph_config_manager.py`
- Subgraph construction: `src/agent/workflow/subgraph_factory.py`
- Workflow command routing/context: `src/agent/workflow/command_dispatcher.py`, `src/agent/workflow/context_manager.py`

#### Persistence, context, and external agents
SQLite persists sessions, messages, task/tool metadata, compaction data, and evaluation records. Context management combines persisted conversational memory with ChromaDB vector retrieval and optional LLM compression. Audit logs are stored separately as JSONL.

Relevant paths:
- SQLite connection and repositories: `src/agent/db/connection.py`, `src/agent/db/sessions.py`, `src/agent/db/messages.py`
- Context compression/memory: `src/agent/context/compression.py`, `src/agent/context/memory.py`
- Audit logging: `src/agent/audit_logger.py`
- ACP JSON-RPC-over-stdio integration: `src/agent/acp/client.py`, `src/agent/acp_agent.py`
- ACP definitions: `config/acp_agents.json`

External dependencies include OpenAI-compatible or Anthropic model APIs, locally installed ACP CLI agents, SQLite, and ChromaDB.

#### Offline evaluation and operational configuration
The eval subsystem derives cases from historical sessions, reruns them through real or mock orchestration, asserts against emitted SSE events, persists runs, and generates heuristic configuration suggestions. It is intentionally decoupled from orchestration internals through the event stream.

Relevant paths:
- Evaluation models/storage: `src/agent/eval/models.py`, `src/agent/eval/storage.py`
- Case generation and execution: `src/agent/eval/case_builder.py`, `src/agent/eval/runner.py`
- Assertions and analysis: `src/agent/eval/assertions.py`, `src/agent/eval/analyzer.py`

Runtime behavior is dynamically controlled by JSON configuration reloads:
- `src/agent/config_manager.py`
- `config/agents.json`
- `config/tools.json`
- `config/skills.json`

Main entry points: [`src/agent/agent/core.py`](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/agent/core.py) (ReAct agent loop), [`server.py`](https://github.com/tanlinru/langgraph-agent-v2/blob/main/server.py) (FastAPI server), [`src/agent/orchestrator/core.py`](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/core.py) (Supervisor StateGraph), [`src/agent/events.py`](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/events.py) (Structured SSE events)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client and API"]
  node_ui["Vue client<br/>frontend<br/>[App.vue]"]
  node_stream_state["Stream and chat state<br/>frontend state<br/>[streamManager.ts]"]
  node_api["FastAPI server<br/>HTTP/SSE API<br/>[server.py]"]
  node_events["Structured SSE events<br/>stream contract<br/>[events.py]"]
end

subgraph group_runtime["Agent Runtime"]
  node_single_agent["ReAct agent loop<br/>LangChain agent<br/>[core.py]"]
  node_models["Model resolution<br/>model settings<br/>[models.py]"]
  node_prompts_skills["Prompts and skills<br/>agent context<br/>[system_prompt.py]"]
  node_local_tools["Local tools<br/>tool suite<br/>[execute_code.py]"]
  node_orchestrator["Supervisor StateGraph<br/>LangGraph orchestrator<br/>[core.py]"]
  node_planner["Structured planner<br/>plan schema<br/>[planner.py]"]
  node_dispatch["Dependency-aware dispatch<br/>subagent dispatcher<br/>[tools.py]"]
  node_agent_nodes["Subagent execution<br/>graph node<br/>[agent_node.py]"]
  node_workflow["JSON workflow engine<br/>DAG runtime"]
  node_workflow_routing["Workflow routing and context<br/>workflow control"]
end

subgraph group_state["State and Integrations"]
  node_config["Dynamic runtime config<br/>JSON config reload<br/>[config_manager.py]"]
  node_context["Memory and compression<br/>context management<br/>[memory.py]"]
  node_sqlite[("SQLite repositories<br/>persistent store<br/>[connection.py]")]
  node_audit["JSONL audit log<br/>audit store<br/>[audit_logger.py]"]
  node_acp["ACP agent bridge<br/>JSON-RPC stdio<br/>[client.py]"]
  node_model_apis{{"Model providers<br/>external APIs"}}
end

subgraph group_evaluation["Offline Evaluation"]
  node_eval_runner["Evaluation runner<br/>regression execution<br/>[runner.py]"]
  node_eval_cases["Session-derived cases<br/>case builder<br/>[case_builder.py]"]
  node_eval_analysis["Assertions and analysis<br/>event evaluator<br/>[analyzer.py]"]
end

node_ui -->|"chat actions"| node_stream_state
node_stream_state -->|"HTTP and SSE"| node_api
node_api -->|"direct chat"| node_single_agent
node_api -->|"supervised tasks"| node_orchestrator
node_api -->|"workflow runs"| node_workflow
node_api -->|"emits"| node_events
node_events -->|"SSE contract"| node_stream_state
node_single_agent -->|"resolves model"| node_models
node_single_agent -->|"injects"| node_prompts_skills
node_single_agent -->|"uses"| node_local_tools
node_orchestrator -->|"creates plan"| node_planner
node_planner -->|"structured steps"| node_dispatch
node_dispatch -->|"assigns tasks"| node_agent_nodes
node_agent_nodes -->|"runs agents"| node_single_agent
node_dispatch -->|"external coding tasks"| node_acp
node_orchestrator -->|"updates and interrupts"| node_events
node_workflow -->|"routes commands"| node_workflow_routing
node_workflow_routing -->|"agent nodes"| node_agent_nodes
node_config -.->|"runtime behavior"| node_single_agent
node_config -.->|"agent definitions"| node_orchestrator
node_single_agent -->|"reads and updates"| node_context
node_context -->|"persisted memory"| node_sqlite
node_api -->|"sessions and messages"| node_sqlite
node_orchestrator -->|"audit trail"| node_audit
node_models -->|"inference"| node_model_apis
node_eval_cases -->|"historical sessions"| node_sqlite
node_eval_cases -->|"cases"| node_eval_runner
node_eval_runner -->|"observes runs"| node_events
node_events -->|"assertions input"| node_eval_analysis
node_eval_analysis -->|"stores results"| node_sqlite

click node_ui "https://github.com/tanlinru/langgraph-agent-v2/blob/main/ui/src/App.vue"
click node_stream_state "https://github.com/tanlinru/langgraph-agent-v2/blob/main/ui/src/utils/streamManager.ts"
click node_api "https://github.com/tanlinru/langgraph-agent-v2/blob/main/server.py"
click node_events "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/events.py"
click node_single_agent "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/agent/core.py"
click node_models "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/models.py"
click node_prompts_skills "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/prompts/system_prompt.py"
click node_local_tools "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/tools/execute_code.py"
click node_orchestrator "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/core.py"
click node_planner "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/planner.py"
click node_dispatch "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/tools.py"
click node_agent_nodes "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/agent_node.py"
click node_workflow "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/workflow/subgraph_factory.py"
click node_workflow_routing "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/workflow/command_dispatcher.py"
click node_config "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/config_manager.py"
click node_context "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/context/memory.py"
click node_sqlite "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/db/connection.py"
click node_audit "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/audit_logger.py"
click node_acp "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/acp/client.py"
click node_eval_runner "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/eval/runner.py"
click node_eval_cases "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/eval/case_builder.py"
click node_eval_analysis "https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/eval/analyzer.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_ui,node_stream_state,node_api,node_events toneBlue
class node_single_agent,node_models,node_prompts_skills,node_local_tools,node_orchestrator,node_planner,node_dispatch,node_agent_nodes,node_workflow,node_workflow_routing toneAmber
class node_config,node_context,node_sqlite,node_audit,node_acp,node_model_apis toneMint
class node_eval_runner,node_eval_cases,node_eval_analysis toneRose
```

## Components

### Client and API

- [Vue client](https://github.com/tanlinru/langgraph-agent-v2/blob/main/ui/src/App.vue): frontend · `ui/src/App.vue`
- [Stream and chat state](https://github.com/tanlinru/langgraph-agent-v2/blob/main/ui/src/utils/streamManager.ts): frontend state · Centralizes SSE consumption and message state. · `ui/src/utils/streamManager.ts`
- [FastAPI server](https://github.com/tanlinru/langgraph-agent-v2/blob/main/server.py): HTTP/SSE API · Exposes chat, orchestration, workflow, session, memory, ACP, and eval APIs. · `server.py`
- [Structured SSE events](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/events.py): stream contract · Normalizes execution into UI-facing lifecycle events. · `src/agent/events.py`

### Agent Runtime

- [ReAct agent loop](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/agent/core.py): LangChain agent · `src/agent/agent/core.py`
- [Model resolution](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/models.py): model settings · `src/agent/models.py`
- [Prompts and skills](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/prompts/system_prompt.py): agent context · `src/agent/prompts/system_prompt.py`
- [Local tools](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/tools/execute_code.py): tool suite · Code execution, file operations, and search. · `src/agent/tools/execute_code.py`
- [Supervisor StateGraph](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/core.py): LangGraph orchestrator · Coordinates planning, review, dispatch, synthesis, and audit. · `src/agent/orchestrator/core.py`
- [Structured planner](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/planner.py): plan schema · `src/agent/orchestrator/planner.py`
- [Dependency-aware dispatch](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/tools.py): subagent dispatcher · Assigns agents and passes upstream task outputs. · `src/agent/orchestrator/tools.py`
- [Subagent execution](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/orchestrator/agent_node.py): graph node · `src/agent/orchestrator/agent_node.py`
- [JSON workflow engine](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/workflow/subgraph_factory.py): DAG runtime · Executes separate reusable agent, approval, and finish-node workflows. · `src/agent/workflow/subgraph_factory.py`
- [Workflow routing and context](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/workflow/command_dispatcher.py): workflow control · `src/agent/workflow/command_dispatcher.py`

### State and Integrations

- [Dynamic runtime config](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/config_manager.py): JSON config reload · Reloads agent, tool, and skill behavior. · `src/agent/config_manager.py`
- [Memory and compression](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/context/memory.py): context management · Combines persisted memory, vector retrieval, and optional compression. · `src/agent/context/memory.py`
- [SQLite repositories](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/db/connection.py): persistent store · Stores sessions, messages, task metadata, compaction, and eval records. · `src/agent/db/connection.py`
- [JSONL audit log](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/audit_logger.py): audit store · `src/agent/audit_logger.py`
- [ACP agent bridge](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/acp/client.py): JSON-RPC stdio · Invokes locally installed coding agents. · `src/agent/acp/client.py`
- **Model providers**: external APIs · OpenAI-compatible or Anthropic model APIs.

### Offline Evaluation

- [Evaluation runner](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/eval/runner.py): regression execution · Reruns historical cases against real or mock orchestration. · `src/agent/eval/runner.py`
- [Session-derived cases](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/eval/case_builder.py): case builder · `src/agent/eval/case_builder.py`
- [Assertions and analysis](https://github.com/tanlinru/langgraph-agent-v2/blob/main/src/agent/eval/analyzer.py): event evaluator · Checks emitted SSE events and suggests configuration changes. · `src/agent/eval/analyzer.py`

## Connections

- Vue client → Stream and chat state: chat actions
- Stream and chat state → FastAPI server: HTTP and SSE
- FastAPI server → ReAct agent loop: direct chat
- FastAPI server → Supervisor StateGraph: supervised tasks
- FastAPI server → JSON workflow engine: workflow runs
- FastAPI server → Structured SSE events: emits
- Structured SSE events → Stream and chat state: SSE contract
- ReAct agent loop → Model resolution: resolves model
- ReAct agent loop → Prompts and skills: injects
- ReAct agent loop → Local tools: uses
- Supervisor StateGraph → Structured planner: creates plan
- Structured planner → Dependency-aware dispatch: structured steps
- Dependency-aware dispatch → Subagent execution: assigns tasks
- Subagent execution → ReAct agent loop: runs agents
- Dependency-aware dispatch → ACP agent bridge: external coding tasks
- Supervisor StateGraph → Structured SSE events: updates and interrupts
- JSON workflow engine → Workflow routing and context: routes commands
- Workflow routing and context → Subagent execution: agent nodes
- Dynamic runtime config → ReAct agent loop: runtime behavior
- Dynamic runtime config → Supervisor StateGraph: agent definitions
- ReAct agent loop → Memory and compression: reads and updates
- Memory and compression → SQLite repositories: persisted memory
- FastAPI server → SQLite repositories: sessions and messages
- Supervisor StateGraph → JSONL audit log: audit trail
- Model resolution → Model providers: inference
- Session-derived cases → SQLite repositories: historical sessions
- Session-derived cases → Evaluation runner: cases
- Evaluation runner → Structured SSE events: observes runs
- Structured SSE events → Assertions and analysis: assertions input
- Assertions and analysis → SQLite repositories: stores results
