Most agent demos stop at five tool calls. Ask for a 100-step server upgrade and the same framework starts repeating commands, forgetting what it did ten steps ago, or claiming a step finished when it did not.
The model is not the problem there. The model generates a response and proposes an action. The gap between "the model said to run this" and "this actually ran on your infrastructure" is where the failures live. Prompt injection, permission sprawl, and the quiet question "what did it actually do?" all sit in that gap.
That gap is a governance problem, not a model problem. Fine-tuning the weights does not fix an untrusted input that changes what the agent does next.
The pattern
The separation that has worked for us is simple to state and harder to build:
- The model generates a response and proposes an action.
- The agent identifies the intended operation and the tools it needs.
- A policy layer evaluates that proposed action against the organization's own written rules.
- Permissions and any required approvals are checked.
- Only then does the action execute.
- The decision and the result are recorded.
In one line: the model generates, the agent acts, and a separate layer governs.
How it holds up on a long task
A hard "no" in the middle of a 100-call sequence is where naive frameworks stall. Try, fail, try, fail, loop.
SAFi's gate returns one of two verdicts: approve, or block with a reason attached. If the agent proposes rm -rf /var/log/* and policy protects that path, the block reason goes back to the model, and its next proposal is the safer command, like rm -f /var/log/*.log. That proposal is audited like any other, and one rewrite-and-re-audit pass is allowed before the system stops rather than ship something unapproved. The agent gets a path forward instead of a dead end, which is what keeps a 150-call scan and patch sequence moving.
Two other decisions matter for long-horizon work:
- Per-action authorization. Each action is evaluated on its own against the current state and the rule: the tool, its parameters, the risk class, the allow list. The gate does not need the last 50 commands to decide if this one is allowed, so the model's working memory stays small and the history lives in the runtime, not in the model's context window.
- The audit trail for operators. Every turn is written to a local, tamper-evident, hash-chained log with the decision, the reason, and the scores behind it. The model does not get that history as context; it gets at most a short coaching note from the previous turn. On step 80 of a task, you can open the ledger and replay what was attempted, allowed, or blocked in the 79 steps before, which beats reconstructing it from a raw context window.
The agents also run in a workspace-isolated CLI, so file system state stays consistent across calls. If a command fails, the workspace is preserved for inspection. The agent reads the error, adjusts the next command, and continues.

