You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: python/custom-tool-policy/README.md
+41-12Lines changed: 41 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Demonstrates how to add [Agent Assembly](https://github.com/ai-agent-assembly/ex
27
27
- Two **allowed** tool calls (`compute_sum`, `fetch_stock_price`).
28
28
- Two **denied** tool calls (`send_http_request`, `write_to_disk` — blocked by policy).
29
29
- That the wrapped function body **never executes** when governance denies it.
30
-
-The `governed()` pattern as the building block for the `GovernedToolRunner` shown in the `llamaindex-tool-policy` example.
30
+
-How this `governed()` pattern relates to the framework path: the `llamaindex-tool-policy` example governs tool calls by registering the native `LlamaIndexAdapter` (auto-wired by `init_assembly()`) instead of wrapping each callable.
31
31
32
32
## Prerequisites
33
33
@@ -90,22 +90,51 @@ Running governed tool calls:
90
90
uv run pytest tests/ -v
91
91
```
92
92
93
-
## Switching to production mode
94
-
95
-
Replace `LocalPolicyEngine` with `ctx.client` (the gateway-backed interceptor):
93
+
## Production mode — governing real tool calls
94
+
95
+
`LocalPolicyEngine` is a stand-in for the gateway: it answers the
96
+
`check_tool_start` contract (the `GovernanceInterceptor` protocol in
97
+
`agent_assembly.adapters`) in-process so this demo runs fully offline. Reaching
98
+
the real gateway in production is **not** a matter of passing `ctx.client` to
99
+
`governed()`.
100
+
101
+
> ⚠️ **Do not pass `ctx.client` as the interceptor.**`ctx.client` is a bare
102
+
> `GatewayClient` — it has **no**`check_tool_start` method. Wire it into
103
+
> `governed()` and `AssemblyCallbackHandler.on_tool_start` finds no check,
104
+
> returns without raising, and **allows every tool**: governance is silently
105
+
> disabled (fail-open). `ctx.client` is for agent metadata and audit emission,
106
+
> not pre-execution policy checks.
107
+
108
+
**The supported production path is a framework adapter.** Run your tools through
109
+
a supported AI framework (LangChain, LlamaIndex, CrewAI, …). On startup
110
+
`init_assembly()` auto-detects the installed adapter and wires the real
111
+
gateway-backed interceptor into that framework's tool-execution path, so every
112
+
tool call is checked against the gateway with no per-tool wrapper and no
113
+
interceptor argument of your own. The `llamaindex-tool-policy` example shows
114
+
this end to end — it registers the native `LlamaIndexAdapter` and lets
115
+
`init_assembly()` supply the live interceptor:
96
116
97
117
```python
98
118
from agent_assembly import init_assembly
99
-
from agent_assembly.adapters.langchain import AssemblyCallbackHandler
100
-
101
-
with init_assembly(gateway_url="http://localhost:8080", agent_id="my-agent") as ctx:
0 commit comments