agent-loop-safety

agent-loop-safety is a skill for Claude Code, Codex from zorost/AI-Engineering-Lab. It costs 41 tokens per session (1,051 once invoked), scanned A, original, MIT.

A safety checklist for AI agents that repeatedly call tools to complete a task.

In plain words
What is it for?
It helps review or build tool-using agents with step limits, cost caps, action-risk labels, approval gates, and traces.
Why use it?
It limits runaway loops and spending, requires approval for irreversible actions, and records what happened.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/zorost/ai-engineering-lab/agent-loop-safety
Any agent
npx skills add zorost/AI-Engineering-Lab --skill agent-loop-safety
Clone the repo
git clone --depth 1 https://github.com/zorost/AI-Engineering-Lab

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for agent-loop-safety

README.md
[![agentmods](https://agentmods.dev/badge/skills/zorost/ai-engineering-lab/agent-loop-safety.svg)](https://agentmods.dev/skills/zorost/ai-engineering-lab/agent-loop-safety)
Your own site
<a href="https://agentmods.dev/skills/zorost/ai-engineering-lab/agent-loop-safety"><img src="https://agentmods.dev/badge/skills/zorost/ai-engineering-lab/agent-loop-safety.svg" alt="Measured on agentmods" height="20"></a>
Per session 41 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,051 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00041 $0.01051
Opus 5 $0.00020 $0.00526
Sonnet 5 $0.00008 $0.00210
Haiku 4.5 $0.00004 $0.00105

Measured 6d ago against content hash cd70ddd1e48c, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

agent-loop-safety scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

reference/skills/agent-skills/agent-loop-safety/SKILL.md · 93 lines

How it starts

The opening of the file, as written. The whole thing — 93 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Agent Loop Safety

1 · Purpose

Ensure an agent can fail safely: bounded in steps and spend, gated on irreversible actions, and fully traceable when it misbehaves.

2 · When to use

  • Building any agent loop (ReAct or framework-based) that calls tools.
  • Reviewing someone else's agent before it gets credentials or write access.

Do not skip this because "the tools are read-only." Read-only agents still loop forever, spend money, and leak data into places you did not intend.

3 · Inputs

  • The agent's tool list with each tool's side effects (read / write / send / spend).
  • The task class and its expected step count (from a manual run).
  • The cost ceiling the owner accepts per run.

4 · Procedure

  1. Classify every tool by blast radius: read-only, reversible-write, irreversible-write (delete, send, pay, publish). Write the classification next to the tool definition.
  2. Set the step cap. Take the steps a careful human used, multiply by 3, set max_steps to that. An agent past the cap is stuck, not thorough.
  3. Set the cost cap. max_cost_usd per run, enforced in the loop, not a dashboard you check later. Trip = halt with a report.
  4. Gate the irreversibles. Every irreversible-write tool requires human approval at call time (or a signed approval token for unattended runs). No exceptions for "the model was confident".
  5. Treat tool output as data. Strip or flag instruction-shaped text from tool results before re-entering the model's context. Tool output never becomes instructions (see Week 6's injection rule).
  6. Log the trace. Every step: thought, tool call + arguments, result summary, token and dollar counters. One file per run, kept.
  7. Write the halt behavior. On cap-trip, tool-error-streak (3), or refusal: stop, write the trace, report what was attempted and what was not done.
  8. Test the guardrails like features. Three adversarial runs: a task designed to loop (watch the step cap fire), a request to skip approval (watch refusal), an injected instruction inside tool data (watch it treated as data). A guardrail never fired in testing does not exist.

Read the full file on GitHub · 93 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 93 lines · 41 tokens per session scan A cd70ddd1e48c

Subscribe to this mod's changes

agent-loop-safety is a skill published in the GitHub repository zorost/AI-Engineering-Lab (309 stars, last pushed 19d ago), licensed MIT. It adds 41 tokens to every session and 1,051 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

fine-tuning-os

Use this skill when conducting a professional LLM fine-tuning engagement in Zero-Data mode via the MCP server fine-tuning-os. Triggers on: prestation de fine-tuning LLM, livraison de modèle affiné, pipeline Zero-Data, orchestration des 64 outils fine-tuning-os, cycle de vie entraînement (préparation / données…

Casius999/fine-tuning-os · 125 tokens

ai-engineering-toolkit

6 production-ready AI engineering workflows: prompt evaluation (8-dimension scoring), context budget planning, RAG pipeline design, agent security audit (65-point checklist), eval harness building, and product sense coaching.

sickn33/agentic-awesome-skills · 47 tokens

find-your-level

Interactive quiz that maps your AI/ML knowledge to a starting point in the 523-lesson, 20-phase AI Engineering from Scratch curriculum. Trigger phrases: "where should I start", "find my level", "what do I know", "which phase", "assess my knowledge", "placement test", "skip ahead".

rohitg00/ai-engineering-from-scratch · 71 tokens

learn

Interactive lesson tutor for the AI Engineering from Scratch curriculum. Reads LEARNING.md, fetches the next lesson, teaches it section by section in the terminal, quizzes at the end, and records progress. Works cloned or entirely over raw.githubusercontent.com — no setup required. Trigger phrases: "next lesson"…

rohitg00/ai-engineering-from-scratch · 80 tokens

start-learning

One-time onboarding for the AI Engineering from Scratch curriculum (523 lessons, 20 phases). Interviews the learner, runs the placement quiz, and writes LEARNING.md, a persistent study plan the learn skill drives. Trigger phrases: "start learning", "set up the course", "begin the curriculum", "onboard me", "create my…

rohitg00/ai-engineering-from-scratch · 74 tokens

course-guide

Topic router for the AI Engineering from Scratch curriculum. Give it a topic, a question, or a bug you are fighting, and it points at the exact lessons that teach it, plus the right next command. Trigger phrases: "where do I learn", "which lesson covers", "course guide", "I'm stuck on", "what should I do next", "teach…

rohitg00/ai-engineering-from-scratch · 96 tokens