How tanlinru/langgraph-agent-v2 works
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: agent/core.py ReAct agent loop · server.py FastAPI server · orchestrator/core.py Supervisor StateGraph · events.py Structured SSE events
Components 23
Client and API
- Vue client
ui/src/App.vue - Stream and chat state · Centralizes SSE consumption and message state.
ui/src/utils/streamManager.ts - FastAPI server · Exposes chat, orchestration, workflow, session, memory, ACP, and eval APIs.
server.py - Structured SSE events · Normalizes execution into UI-facing lifecycle events.
src/agent/events.py
Agent Runtime
- ReAct agent loop
src/agent/agent/core.py - Model resolution
src/agent/models.py - Prompts and skills
src/agent/prompts/system_prompt.py - Local tools · Code execution, file operations, and search.
src/agent/tools/execute_code.py - Supervisor StateGraph · Coordinates planning, review, dispatch, synthesis, and audit.
src/agent/orchestrator/core.py - Structured planner
src/agent/orchestrator/planner.py - Dependency-aware dispatch · Assigns agents and passes upstream task outputs.
src/agent/orchestrator/tools.py - Subagent execution
src/agent/orchestrator/agent_node.py - JSON workflow engine · Executes separate reusable agent, approval, and finish-node workflows.
src/agent/workflow/subgraph_factory.py - Workflow routing and context
src/agent/workflow/command_dispatcher.py
State and Integrations
- Dynamic runtime config · Reloads agent, tool, and skill behavior.
src/agent/config_manager.py - Memory and compression · Combines persisted memory, vector retrieval, and optional compression.
src/agent/context/memory.py - SQLite repositories · Stores sessions, messages, task metadata, compaction, and eval records.
src/agent/db/connection.py - JSONL audit log
src/agent/audit_logger.py - ACP agent bridge · Invokes locally installed coding agents.
src/agent/acp/client.py - Model providers · OpenAI-compatible or Anthropic model APIs.
Offline Evaluation
- Evaluation runner · Reruns historical cases against real or mock orchestration.
src/agent/eval/runner.py - Session-derived cases
src/agent/eval/case_builder.py - Assertions and analysis · Checks emitted SSE events and suggests configuration changes.
src/agent/eval/analyzer.py
Connections 30
- 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