Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

llamaindex-tool-policy

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.1rc4

Demonstrates 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.

What this example demonstrates

  • Initializing Agent Assembly with init_assembly().
  • Registering the native LlamaIndexAdapter against a local policy interceptor.
  • Running an allowed tool call (query_index) through the patched FunctionTool.call.
  • Running another allowed tool call (summarize_docs).
  • Running a denied tool call (execute_sql — blocked by deny_arbitrary_execution); its body never runs.

Prerequisites

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.

Setup

cd python/llamaindex-tool-policy
uv sync --extra dev

Run

uv run python src/main.py

Expected output

==============================================================
  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'. ...

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 credentials.
  3. Let init_assembly() auto-detect and register the LlamaIndex adapter against the live gateway interceptor instead of the local LocalPolicyEngine — the tool-call code does not change; only the policy source does.

Troubleshooting

Problem Fix
ModuleNotFoundError: agent_assembly Run uv sync first
ModuleNotFoundError: llama_index Run uv syncllama-index-core is a required dependency
ImportError: cannot import name 'LlamaIndexAdapter' Your installed SDK predates the LlamaIndex adapter — upgrade agent-assembly

Links