Demonstrates how to integrate Agent Assembly with LangGraph to enforce governance policy on the tools a graph's nodes call — before any tool executes.
- Initializing Agent Assembly with
init_assembly()in offlinesdk-onlymode. - Installing node-level governance hooks with
LangGraphAdapter, which wraps a compiledStateGraph's nodes. - Routing tool calls through LangChain's
AssemblyCallbackHandlerso each tool is checked against policy. - A linear graph
START → research → report → ENDwhere:researchcalls an allowed tool (get_weather).reportcalls a denied tool (delete_files— blocked by policy).
- How
ToolExecutionBlockedErrorhalts 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.
| 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.
cd python/langgraph
uv sync --extra devuv run python src/main.py==============================================================
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.
uv run pytest tests/ -v- Start an Agent Assembly gateway or use your SaaS workspace URL.
- Copy
.env.exampleto.envand fill in your credentials. - Run with gateway environment variables:
AGENT_ASSEMBLY_GATEWAY_URL=http://localhost:8080 \
AGENT_ASSEMBLY_API_KEY=your-key \
uv run python src/main.pyIn 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.
| Problem | Fix |
|---|---|
ModuleNotFoundError: agent_assembly |
Run uv sync first |
ModuleNotFoundError: langgraph |
Run uv sync — langgraph is a required dependency |
ToolExecutionBlockedError in tests |
Expected — the deny/pending policy rules are intentional |