| Requirement | Version |
|---|---|
| Agent Assembly Python SDK (agent-assembly) | >= 0.0.1rc4 |
Install:
uv add agent-assembly==0.0.1rc4
# or
pip install agent-assembly==0.0.1rc4Demonstrates Agent Assembly governance for LlamaIndex tool calls using the native LlamaIndex adapter.
LlamaIndex has a native Agent Assembly adapter (agent_assembly.adapters.llamaindex). It monkey-patches the concrete FunctionTool.call / acall execution methods, so once the adapter's hooks are registered, every LlamaIndex tool call is governed automatically — the exact method a FunctionAgent / ReActAgent invokes to run a tool. A denied tool's body never executes; the adapter returns a ToolOutput flagged is_error=True carrying a [BLOCKED by governance policy] message so the agent loop can react instead of crashing.
- Initializing Agent Assembly with
init_assembly(). - Registering the native
LlamaIndexAdapteragainst a local policy interceptor. - Running an allowed tool call (
query_index) through the patchedFunctionTool.call. - Running another allowed tool call (
summarize_docs). - Running a denied tool call (
execute_sql— blocked bydeny_arbitrary_execution); its body never runs.
| Requirement | Version |
|---|---|
| Python | >= 3.12 |
| uv | latest |
| Agent Assembly Python SDK | >= 0.0.1rc3 (with the LlamaIndex adapter) |
No API key or running gateway is required for the offline demo.
cd python/llamaindex-tool-policy
uv sync --extra devuv run python src/main.py==============================================================
Agent Assembly — LlamaIndex Tool Policy Demo
==============================================================
Initializing Agent Assembly (gateway: http://localhost:8080, sdk-only mode)...
Agent: llamaindex-demo-agent
Gateway: http://localhost:8080
Mode: sdk-only (offline demo)
Policy rules (local simulation of gateway policy):
DENY — execute_sql, run_shell_command (arbitrary execution)
ALLOW — everything else
Registering the native LlamaIndex governance adapter...
FunctionTool.call / acall are now governed by Agent Assembly.
Running governed tool calls:
--------------------------------------------
→ query_index({'query': 'what is Agent Assembly?'})
✅ ALLOWED — 📚 Index results for 'what is Agent Assembly?': ...
→ summarize_docs({'topic': 'policy enforcement'})
✅ ALLOWED — 📝 Summary for 'policy enforcement': Agent Assembly provides governance...
→ execute_sql({'sql': 'DROP TABLE users; --'})
❌ BLOCKED — [BLOCKED by governance policy] Tool 'execute_sql' is blocked by policy rule 'deny_arbitrary_execution'. ...
uv run pytest tests/ -v- Start an Agent Assembly gateway or use your SaaS workspace URL.
- Copy
.env.exampleto.envand fill in credentials. - Let
init_assembly()auto-detect and register the LlamaIndex adapter against the live gateway interceptor instead of the localLocalPolicyEngine— the tool-call code does not change; only the policy source does.
| Problem | Fix |
|---|---|
ModuleNotFoundError: agent_assembly |
Run uv sync first |
ModuleNotFoundError: llama_index |
Run uv sync — llama-index-core is a required dependency |
ImportError: cannot import name 'LlamaIndexAdapter' |
Your installed SDK predates the LlamaIndex adapter — upgrade agent-assembly |