Skip to main content
Wrap a smolagents agent’s tools with infy governance and gain deny-by-default policy, risk tiering, human approval, and a tamper-evident audit trail. The agent’s code does not change. The governed tools are drop-in replacements for the originals.

How it works

smolagents runs a tool through Tool.__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 example READ, EXECUTE, or DB.
  • risk_tier: low, medium, high, or critical.
  • side_effect: whether the tool changes state.
Any tool not listed in risk gets the default profile, which is {"verb": "EXECUTE", "risk_tier": "high", "side_effect": True}. This is conservative on purpose: an unprofiled tool is treated as a high-risk, side-effecting action, so governance fails safe rather than waving it through. Override it with the default parameter if you need different behavior.

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:
The model sees this as the tool output and must adapt its next step. It does not execute the blocked action.

Reading the audit trail

Every decision, allowed or denied, lands in the AuditLog. 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.