How it works
smolagents runs a tool throughTool.__call__, which calls Tool.forward. The adapter in infy.integrations.smolagents wraps each tool in a GovernedTool whose forward first asks governance whether the action is allowed.
1
Governance runs before the tool
GovernedTool.forward calls governance.before_tool(...) with the tool’s metadata and the call arguments.2
Denied actions never execute
If the decision is not allowed, the inner tool is never called. The model receives the block reason as the tool result and must adapt.
3
Allowed actions run, then are recorded
If allowed, the inner tool runs and
governance.after_tool(...) records the result.4
Every decision is audited
Allowed or denied, each decision is written to the tamper-evident audit chain that
verify() confirms.The govern function
govern takes your list of smolagents tools, a Governance instance, and a risk map. It returns a new list of governed tools.
Parameters
The risk map
Each entry maps a tool name to a small dict:verb: the action category, for exampleREAD,EXECUTE, orDB.risk_tier:low,medium,high, orcritical.side_effect: whether the tool changes state.
Full example with a ToolCallingAgent
This mirrors examples/smolagents_governance_demo.py. Reads run, the destructive action is denied by policy and never executes, and the high-risk deploy pauses for a human before it is allowed.
The governed tools are drop-in replacements, so point any real model at them (
OpenAIServerModel, LiteLLMModel, and so on) and the agent behaves identically. The demo file uses a scripted model so it runs deterministically without an API key.What a denied action returns
When governance blocks a call, the inner tool never runs.GovernedTool.forward returns a string to the agent’s model:
Reading the audit trail
Every decision, allowed or denied, lands in theAuditLog. Iterate its events and confirm the chain was not altered with verify().
Try it
Run the full demo, which needs only smolagents installed:Governance overview
Policy, risk tiering, approval, and the audit chain in depth.
Human approval
How
require_approval and approvers gate high-risk actions.