Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

langgraph-governed-agent

Demonstrates how to integrate Agent Assembly with LangGraph to enforce governance policy on the tools a graph's nodes call — before any tool executes.

What this example demonstrates

  • Initializing Agent Assembly with init_assembly() in offline sdk-only mode.
  • Installing node-level governance hooks with LangGraphAdapter, which wraps a compiled StateGraph's nodes.
  • Routing tool calls through LangChain's AssemblyCallbackHandler so each tool is checked against policy.
  • A linear graph START → research → report → END where:
    • research calls an allowed tool (get_weather).
    • report calls a denied tool (delete_files — blocked by policy).
  • How ToolExecutionBlockedError halts the graph the moment a blocked tool is reached.

The example runs fully offline: the graph is driven with deterministic nodes, so no LLM, API key, or running gateway is required.

Prerequisites

Requirement Version
Python >= 3.12
uv latest
Agent Assembly Python SDK >= 0.0.1b2

No running Agent Assembly gateway is required for the offline demo.

Setup

cd python/langgraph
uv sync --extra dev

Run

uv run python src/main.py

Expected output

==============================================================
  Agent Assembly — LangGraph Governed Agent Demo
==============================================================

Initializing Agent Assembly (gateway: http://localhost:8080, sdk-only mode)...
  Agent:    langgraph-demo-agent
  Gateway:  http://localhost:8080
  Mode:     sdk-only (offline demo)

Policy rules (local simulation of gateway policy):
  DENY    — delete_files, write_file  (destructive operations)
  PENDING — send_email                (requires human approval)
  ALLOW   — everything else

Invoking governed graph: START → research → report → END
--------------------------------------------
  → research node: get_weather
     ✅ ALLOWED  — gathered notes (mock response)
  → report node: delete_files
     ❌ BLOCKED  — Tool 'delete_files' is blocked by policy rule 'deny_destructive_operations'.

Assembly context shut down.

Run tests

uv run pytest tests/ -v

Switching to production mode

  1. Start an Agent Assembly gateway or use your SaaS workspace URL.
  2. Copy .env.example to .env and fill in your credentials.
  3. Run with gateway environment variables:
AGENT_ASSEMBLY_GATEWAY_URL=http://localhost:8080 \
AGENT_ASSEMBLY_API_KEY=your-key \
uv run python src/main.py

In production, init_assembly() auto-detects LangGraph and registers the adapter automatically, and the gateway enforces the policy rules — replace LocalPolicyEngine with the gateway-backed interceptor.

Troubleshooting

Problem Fix
ModuleNotFoundError: agent_assembly Run uv sync first
ModuleNotFoundError: langgraph Run uv synclanggraph is a required dependency
ToolExecutionBlockedError in tests Expected — the deny/pending policy rules are intentional

Links