Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Agent Reliability: A Production-Grade Run Loop

    1

    An agent loop is a distributed system with a non-deterministic component in the middle.

    $12

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Agent Reliability: A Production-Grade Run Loop

    Agent Reliability: A Production-Grade Run Loop

    Example session with this skill installed

    Here is our agent loop (a while True around messages.create that runs each tool and appends one tool_result message per call). It sometimes runs forever, sometimes refunds a customer twice after a crash, and it treats truncated answers as final. Rewrite it production-grade in loop.py.

    • Read your context and instructions
    • Compiled the agent reliability

    loop.py: Budget(max_steps=25, max_output_tokens, max_wall_seconds) checked each iteration with distinct statuses; explicit branches for end_turn, tool_use, pause_turn, refusal, max_tokens (status 'truncated', never executed) and unknown; transient errors retried with jittered backoff, permanent ones fail fast; tool calls with timeouts and exceptions turned into is_error results, all returned in one user message; the refund tool runs sequentially, its result is checkpointed atomically by tool_use id and sent with an idempotency key run_id:tool_use_id, so a resumed run never refunds twice.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    An agent loop is a distributed system with a non-deterministic component in the middle. It needs the same engineering as any production job (bounded work, retries, timeouts, idempotency, durable state) plus LLM-specific failure modes. This skill gives your agent both, and a tested reference loop to adapt.

    What your agent does with it

    • Every stop reason handled explicitly: end_turn, tool_use, pause_turn, max_tokens (never success), refusal, and unknown values that stop the run instead of guessing.
    • Budgets in code: steps, output tokens or money, wall-clock, tool calls per step, tool result size, each with a distinct status so dashboards can tell "finished" from "ran out".
    • Retries that classify first: backoff with jitter for rate limits, overload and 5xx; fail fast on 4xx; circuit breakers for shared dependencies; SDK retries accounted for.
    • Tool execution: per-tool timeouts, exceptions returned as error results, reads in parallel, writes in order, all results of a turn in one message, bounded output.
    • Idempotency and resume: atomic checkpoints after every step, write results recorded by tool-use id so a crash never refunds a customer twice, idempotency keys for external writes.
    • Output validation, fallbacks and concurrency limits, plus a review checklist and failure-injection test list.

    Included: SKILL.md, agent_loop.py (about 350 lines: provider-neutral core with an optional Anthropic adapter), and an eval case with a naive loop to harden.

    Part of the Production AI Agents series. Pair with Agent Guardrails (policy hook) and Agent Observability (events); start free with Agent Architecture.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for LLM Ops.

    Python reference implementation; port the structure to other languages. Provider-specific parameters in the adapter (effort, caching, fallbacks) change over time; check your SDK version. Does not decide which actions are allowed (see Agent Guardrails).

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 1 day ago

    Software
    Python 3.10+
    Optional
    anthropic Python SDK (adapter only)

    Permissions

    Allowed Hosts

    api.anthropic.com (only if you run the optional demo/adapter)

    File Scopes

    Your
    project
    folder
    (loop
    code
    checkpoint
    files)

    The core loop has no network dependency; only the optional Anthropic adapter calls the API, with your own credentials.

    Listed1 day ago

    What's inside

    Frequently Asked Questions

    Yes. Reuse the structure: the runner's per-turn hooks can host the budget checks, policy hook, checkpointing and stop-reason handling.

    Only for the optional adapter and demo. The core loop works with any client that returns a stop reason, content blocks and usage.

    New in LLM Ops