Skip to content

About

Production-ready autonomous multi-agent intelligence swarm built with LangGraph, LangChain Core, LangSmith observability, and Human-in-the-Loop governance.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

⚑ Nexus: Autonomous Multi-Agent Intelligence Swarm

Live Demo Python Version LangChain Core LangGraph LangSmith Persistence Tests Docker Notebook Code Style: Ruff License: MIT

🌐 Interactive Web Showcase & Simulator: phlppgdfry.github.io/langgraph-multi-agent-system

A production-grade, stateful multi-agent intelligence swarm built with LangGraph, LangChain Core, LangSmith observability, reflection-driven self-correction, SQLite state persistence, and Human-in-the-Loop governance.


πŸ“Œ Executive Overview

In real-world enterprise deployments, single-turn LLM chains fail because they lack state persistence, cyclical feedback, verifiable audit trails, and human oversight.

Nexus demonstrates how to build an enterprise-grade autonomous multi-agent system utilizing LangGraph's cyclically directed state graphs and LangChain's unified tool abstractions. The system coordinates a team of specialized agents that gather live intelligence, extract quantitative KPIs, cross-verify assertions, execute reflection self-correction loops, and generate executive-ready decision briefings.

Full distributed tracing, token consumption, and run trees are piped directly to LangSmith for enterprise observability and latency profiling.

       [Objective / Prompt]
                 β”‚
                 β–Ό
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚ 🧭 Supervisor     │◄───────────────────┐
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
                 β”‚ (Dynamic Planning & Routing) β”‚ (Self-Correction & Updates)
                 β–Ό                              β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”‚
       β”‚ πŸ”¬ Researcher     │─────────────────────
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
                 β–Ό                              β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”‚
       β”‚ πŸ“ˆ Data Analyst   │─────────────────────
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
                 β–Ό                              β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                    β”‚
       β”‚ βš–οΈ Critic Agent   │────[Score < 80]β”€β”€β”€β”€β”˜
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚ [Score >= 80]
                 β–Ό
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚ πŸ›‘οΈ Human Gate     β”‚ (Checkpointed Approval / State Rewind)
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β–Ό
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚ ✍️ Executive Writerβ”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β–Ό
       [πŸ“Š Strategic Briefing .md]

πŸ—οΈ Multi-Agent Architecture

flowchart TD
    START([Start / User Objective]) --> Supervisor[🧭 Supervisor Agent]

    subgraph Swarm ["Nexus Agent Swarm (LangGraph StateGraph)"]
        Supervisor -->|Route: Research| Researcher[πŸ”¬ Researcher Agent]
        Researcher -->|Emit: research_notes| Supervisor

        Supervisor -->|Route: Analysis| Analyst[πŸ“ˆ Data Analyst Agent]
        Analyst -->|Emit: quantitative_data| Supervisor

        Supervisor -->|Route: Quality Audit| Critic[βš–οΈ Critic / Fact-Checker]
        Critic -->|Reflection Rejection < 80| Supervisor
        Critic -->|Verification Passed >= 80| Supervisor

        Supervisor -->|Route: Governance Check| HumanGate{πŸ›‘οΈ Human-in-the-Loop Gate}
        HumanGate -->|Approved| Writer[✍️ Executive Writer Agent]
        HumanGate -->|Revision Requested| Supervisor
    end

    Writer --> FinalReport([πŸ“Š Executive Briefing Markdown])
    FinalReport --> END([End])

    classDef agent fill:#0f172a,stroke:#38bdf8,stroke-width:2px,color:#ffffff;
    classDef gate fill:#2e1065,stroke:#c084fc,stroke-width:2px,color:#ffffff;
    classDef terminus fill:#022c22,stroke:#4ade80,stroke-width:2px,color:#ffffff;
    class Supervisor,Researcher,Analyst,Critic,Writer agent;
    class HumanGate gate;
    class START,END,FinalReport terminus;
Loading

Specialized Agents

Agent Core Responsibility Capabilities & Tools
🧭 Supervisor Dynamic Workflow Orchestration Task decomposition, 4-phase planning, state routing, and revision cycle tracking.
πŸ”¬ Researcher Primary Intelligence Gathering Web search (search_web), snippet curation, source triangulation, and fact retrieval.
πŸ“ˆ Analyst Quantitative & Metric Extraction Financial KPI parsing (extract_metrics), latency/accuracy calculations, and scorecarding.
βš–οΈ Critic Reflection & Quality Assurance Multi-source verification (verify_claim), rigor scoring (0-100), and self-correction loops.
πŸ›‘οΈ Human Gate Governance & Checkpoint Oversight Human-in-the-loop interruption via SQLite SqliteSaver checkpoints before publication.
✍️ Writer Executive Briefing Synthesis C-suite markdown reporting with TL;DR, methodology, quantitative scorecards, and citations.

πŸ” LangSmith Tracing & Observability

Nexus is pre-instrumented for LangSmith out-of-the-box. Every agent action, tool invocation, token spend, latency metric, and reflection cycle is captured in an auditable trace tree.

Run: nexus-multi-agent-system [Status: SUCCESS]
β”œβ”€β”€ supervisor [ChatOpenAI] (latency: 142ms, tokens: 380)
β”‚   └── Input: "Analyze enterprise multi-agent adoption..."
β”‚   └── Output: "[Supervisor] Plan initialized: 4 steps..."
β”œβ”€β”€ researcher (latency: 410ms)
β”‚   └── Tool: search_web(query="...") [HTTP 200 OK]
β”œβ”€β”€ analyst (latency: 88ms)
β”‚   └── Tool: extract_metrics(...) [4 benchmarks extracted]
β”œβ”€β”€ critic (latency: 165ms)
β”‚   └── Tool: verify_claim(...) [Quality Score: 96/100, PASSED]
└── writer [ChatOpenAI] (latency: 520ms, tokens: 1,120)
    └── Output: "# Strategic Intelligence Briefing..."

Quick Setup:

Run the interactive configuration wizard:

uv run python -m langgraph_multi_agent_system.cli --configure

Or set .env:

LANGCHAIN_TRACING_V2=true
LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
LANGCHAIN_API_KEY=lsv2_pt_your_langsmith_api_key_here
LANGCHAIN_PROJECT="nexus-multi-agent-system"

Read the complete LangSmith Observability Guide.


⚑ Quickstart

1. Prerequisites

  • Python 3.11+
  • uv (recommended ultra-fast package manager)

2. Clone & Sync

git clone https://github.com/phlppgdfry/langgraph-multi-agent-system.git
cd langgraph-multi-agent-system

# Install dependencies in under 2 seconds with uv
uv sync

3. Run via Rich Interactive CLI

# Run with default enterprise research prompt:
uv run python -m langgraph_multi_agent_system.cli

# Or specify a custom strategic prompt:
uv run python -m langgraph_multi_agent_system.cli "Analyze AI Agent ROI in Multimodal Freight Logistics"

# Enable Human-in-the-Loop checkpoint review before report publication:
uv run python -m langgraph_multi_agent_system.cli "Enterprise Agentic FinOps" --human-approval

# Save the generated markdown briefing:
uv run python -m langgraph_multi_agent_system.cli "LangGraph vs Linear Chains" -o briefing.md

4. Run via Streamlit Web Dashboard

uv run streamlit run src/langgraph_multi_agent_system/app.py

Open http://localhost:8501 to interact with the swarm in real-time, view live node progression, inspect critique scores, and download executive briefings.

5. Inspect in LangGraph Studio

Native integration via langgraph.json:

langgraph dev

6. Human-in-the-Loop Interrupt & Resume Lifecycle

Nexus implements true checkpoint interruption. When an operator enables --human-approval, execution halts before the executive writer, stores state in SQLite, and can be resumed out-of-process hours later:

# 1. Start pipeline with approval gate
uv run python -m langgraph_multi_agent_system.cli "Evaluate Demurrage Risk" --human-approval

# 2. In a new process or session, inspect and resume:
uv run python -m langgraph_multi_agent_system.cli --resume <THREAD_ID> --approve
# Or request revision:
uv run python -m langgraph_multi_agent_system.cli --resume <THREAD_ID> --reject --feedback "Deepen financial metrics"

7. Run 6-Baseline Comparative Study (Single vs Multi-Agent)

Objectively compare Single-Agent Direct, Tool-Augmented, Sequential, Parallel Map-Reduce, and Nexus Swarm across latency, token spend, and factual grounding:

uv run python -m langgraph_multi_agent_system.cli --benchmark-compare

πŸ“Š Dual-Mode Empirical Architecture Benchmark

The benchmarking suite (src/langgraph_multi_agent_system/evals/comparative_benchmark.py) provides two scientifically separated modes:

  • Mode A (Deterministic Simulation): Uses MockChatModel to isolate pure LangGraph StateGraph engine latency, state routing, checkpoint writing, and reflection cycle overhead from network jitter.
  • Mode B (Real Agent Performance): Runs live with genuine LLM providers (gpt-4o-mini, claude-3-5-haiku) and real tools, measuring end-to-end network roundtrips and token spend.

Mode A: Engine Overhead & Objective Grounding Telemetry

Architecture Baseline Avg Engine Latency Sources Analyzed KPIs Parsed Factual Grounding (Objective) Token Spend Est. Cost ($) Architectural Trade-Off Profile
Baseline A: Single-Agent Direct 0.9 ms 0.0 0.0 0.0% ~31 $0.00006 Zero citations; high hallucination risk.
Baseline B: Single-Agent + Tools 80.2 ms 2.0 3.3 32.7% ~222 $0.00045 Single search pass; no reflection or critique.
Baseline C: Sequential Multi-Agent 5.5 ms 2.0 3.3 72.0% ~609 $0.00122 Linear pipeline; errors cascade to writer.
Baseline D: Parallel Map-Reduce 8.8 ms 6.0 7.3 85.0% ~1,475 $0.00295 3x evidence density; lacks self-correction.
Baseline F: Nexus Swarm (Reflection) 26.9 ms 6.0 7.3 100.0% ~2,694 $0.00539 100% grounding & citations; higher token spend.

(Note: Live LLM execution in Mode B exhibits ~3,500 ms total latency dominated by model inference and search HTTP roundtrips; engine overhead is < 30 ms).


πŸ“‘ Independent Principal Validation & Architecture Reports

All claims in this repository are backed by 12 independent engineering audits and technical reports:

Document Focus & Coverage
πŸ”¬ Final Principal AI Audit Independent findings register (AUD-001–015), code references, and objective capability matrix.
πŸ“Š Benchmark Methodology Review Forensic separation of simulation vs live benchmarks and objective grounding formulations.
⚑ Real Agent Performance Evaluation Engine overhead profiling vs live LLM roundtrips and token consumption.
πŸ’Ύ Memory Persistence Audit Thread-safe RLock, atomic write protocol (NamedTemporaryFile + os.replace), and tenant isolation.
πŸ›‘οΈ HITL Reliability Report Out-of-process SQLite interrupt/resume, idempotency verification, and structured JSONL audit trail.
πŸ” LangSmith Cloud Validation Live EU endpoint audit across Distributed Tracing, Datasets, Queues, and Prompt Hub.
πŸ” Agentic Security Threat Model OWASP Top 10 for LLMs, SSRF private IP validation, and regex prompt injection sanitization.
πŸ§ͺ Agent Evaluation Framework 4-dimensional evaluation rubric: Grounding, Quantitative Density, Structure, and FinOps.
πŸ”„ Continuous Improvement Design Autonomous flywheel connecting flagged low scores, annotation queues, and dynamic prompt templates.
🚒 Enterprise Reference Scenario Parametric cost-benefit modeling and feasibility analysis for operational document logistics.
πŸ’Ό Final Portfolio Readiness Recruiter and architectural assessment with a 5-minute live demonstration script.
⚠️ Remaining Risks & Limitations Transparent disclosure of technical constraints and prioritized engineering roadmap.
πŸ“‘ Observability Architecture P50/P95 latencies, FinOps token accounting, and alert thresholds.
πŸš€ Production Readiness Runbook Non-root Docker, health checks, SQLite disaster recovery.
🌟 Portfolio Showcase Guide Narrative for technical directors and hiring managers.
πŸ—ΊοΈ Architectural Roadmap MCP integration, Command state updates, and semantic caching.

πŸ§ͺ Testing & Code Quality

The repository maintains 100% pass rates across unit tests and linter checks:

# Run full pytest test suite (45 unit & integration tests)
make test
# or
uv run pytest -v

# Run ruff code linter
make lint

πŸ“‚ Repository Structure

langgraph-multi-agent-system/
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml              # Multi-Python (3.11, 3.12, 3.13) GitHub Actions CI
β”œβ”€β”€ data/
β”‚   └── swarm_checkpoints.db    # SQLite persistence database (thread replay)
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ ARCHITECTURE.md         # Deep-dive into StateGraph, routing & memory
β”‚   β”œβ”€β”€ LANGSMITH_GUIDE.md      # Tracing setup, eval runs & latency analysis
β”‚   └── HUMAN_IN_THE_LOOP.md    # Checkpointing, interruption gates & state rewind
β”œβ”€β”€ examples/
β”‚   └── reports/                # Pre-generated sample executive briefings
β”œβ”€β”€ src/
β”‚   └── langgraph_multi_agent_system/
β”‚       β”œβ”€β”€ __init__.py         # Package exports
β”‚       β”œβ”€β”€ state.py            # TypedDict global state schema (MessagesState)
β”‚       β”œβ”€β”€ tools.py            # Search, metric extraction & verification tools
β”‚       β”œβ”€β”€ checkpoint.py       # Unified SQLite & MemorySaver checkpointer
β”‚       β”œβ”€β”€ graph.py            # StateGraph topology & conditional routers
β”‚       β”œβ”€β”€ cli.py              # Interactive Rich terminal runner & config wizard
β”‚       β”œβ”€β”€ app.py              # Interactive Streamlit Web UI
β”‚       β”œβ”€β”€ agents/
β”‚       β”‚   β”œβ”€β”€ supervisor.py   # Master orchestration agent
β”‚       β”‚   β”œβ”€β”€ researcher.py   # Research & source gathering
β”‚       β”‚   β”œβ”€β”€ analyst.py      # Quantitative extraction
β”‚       β”‚   β”œβ”€β”€ critic.py       # Reflection & self-correction scoring
β”‚       β”‚   β”œβ”€β”€ human_gate.py   # Human-in-the-loop checkpoint gate
β”‚       β”‚   └── writer.py       # Executive report generator
β”‚       └── evals/
β”‚           └── run_evals.py    # Automated LangSmith evaluation suite
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_graph.py           # Integration, persistence & execution tests
β”‚   └── test_tools.py           # Tool unit tests
β”œβ”€β”€ scripts/
β”‚   └── export_graph.py         # Mermaid topology exporter
β”œβ”€β”€ langgraph.json              # LangGraph Studio configuration
β”œβ”€β”€ pyproject.toml              # Modern uv / pip project metadata
β”œβ”€β”€ .env.example                # Environment variable configuration guide
β”œβ”€β”€ LICENSE                     # MIT License
└── README.md                   # Project documentation

πŸ’‘ Key Architectural Patterns

  1. Stateful Graph Orchestration (StateGraph): Replaces linear chains with inspectable, cyclical state machines.
  2. Reflection & Self-Correction: Factual scoring that redirects deficient outputs back to researchers before user delivery.
  3. Deterministic Zero-Key Demo Mode: Built with resilient fallbacks so reviewers can clone and run tests/demos without needing paid API credits.
  4. State Persistence (SqliteSaver): Checkpointed state transitions allowing step replay, thread resumption, and human intervention.
  5. Observability First: Deep LangSmith tracing for enterprise auditability and latency profiling.

πŸ‘€ Author

Philippe Godfroy


πŸ“„ License

This project is licensed under the MIT License.

About

Production-ready autonomous multi-agent intelligence swarm built with LangGraph, LangChain Core, LangSmith observability, and Human-in-the-Loop governance.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages