Expand description
Per-turn tool-call guardrails.
Sits alongside the existing recent_tool_call_keys circuit breaker (which
short-circuits identical-(tool,args) calls after N repeats). This module
adds two finer-grained signals from hermes-agent’s tool_guardrails.py:
- Idempotent no-progress: if a read-only tool returns the same result hash N times for the same args, append a guidance suffix to the tool result asking the model to use what it already has instead of repeating.
- Same-tool failure streak: if any tool fails N times this turn — with ANY args — append guidance suggesting a different approach.
Both signals only emit warnings (the result still goes back to the model); they never block execution. The existing duplicate-call circuit breaker handles the blocking case for identical (tool, args) repeats.
The Controller is reset per turn by the agent loop.
Structs§
- Guardrail
Controller - Tool
Grant Rule - Tool
Policy Config - Config-driven pre-tool-call policy (
tool_policyin config.yaml).
Enums§
- Policy
Decision - Outcome of evaluating one pending tool call against the policy.
- Tool
Policy Mode - Pre-tool-call policy mode.
Offpreserves historical behavior (no policy evaluation at all);Warnlogs violations to the audit trail but lets the call run;Blockshort-circuits the call with an error tool_result.
Functions§
- evaluate_
tool_ policy - Evaluate
tool_nameagainst the configured policy. Pure — callers handle audit logging and short-circuiting. - evaluate_
tool_ policy_ for_ auth - Evaluate the global policy and the caller’s least-privilege capability grants. A grant never weakens a global block.
- evaluate_
tool_ policy_ for_ auth_ with_ risk - Like
evaluate_tool_policy_for_authbut with the tool’s effective risk supplied by the caller (registration-time overrides such as MCP server trust tiers). - evaluate_
tool_ policy_ with_ risk - Like
evaluate_tool_policybut with the tool’s effective risk supplied by the caller — used when a registration-time override (e.g. an MCP server trust tier) replaces the name-derived risk.