Demonstrates how to integrate Agent Assembly with LangChain to enforce governance policy on tool calls before execution.
- Initializing Agent Assembly with
init_assembly(). - Wrapping LangChain tools with
AssemblyCallbackHandler+ a governance interceptor. - Running an allowed tool call (
get_weather). - Running a denied tool call (
delete_files— blocked by a policy rule). - Running a pending tool call (
send_email— requires human approval; auto-denied in offline mode). - How
ToolExecutionBlockedErroris raised when a tool is blocked.
| 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/langchain-basic-agent
uv sync --extra devuv run python src/main.py==============================================================
Agent Assembly — LangChain Basic Agent Demo
==============================================================
Initializing Agent Assembly (gateway: http://localhost:8080, sdk-only mode)...
Agent: langchain-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
Running governed tool calls:
--------------------------------------------
→ get_weather({"city": "London"})
✅ ALLOWED — 🌤 Weather in {"city": "London"}: 22°C, partly cloudy (mock response)
→ delete_files({"path": "/etc/passwd"})
❌ BLOCKED — Tool 'delete_files' is blocked by policy rule 'deny_destructive_operations'.
→ send_email({"to": "all@company.com", "subject": "Hello", "body": "World"})
❌ BLOCKED — Tool 'send_email' requires approval, but no approver is available in offline mode.
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, remove the mode="sdk-only" argument from init_assembly() and replace LocalPolicyEngine with the gateway-backed interceptor. The SDK will enforce policy rules configured in the gateway automatically.
| Problem | Fix |
|---|---|
ModuleNotFoundError: agent_assembly |
Run uv sync first |
ModuleNotFoundError: langchain_core |
Run uv sync — langchain-core is a required dependency |
ToolExecutionBlockedError in tests |
Expected — the deny/pending policy rules are intentional |