Skip to content
Back to skills

Agent Loop

ASecurity

Build a minimal agent loop that streams, calls tools, and repeats until done

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 3, 2026
ai-agentsgoapi

Works with

  • api

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add black141312/ada --skill agent-loop --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Agent Loop?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Agent Loop
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/black141312-agent-loop/badge)](https://www.skillsdirectory.com/skills/black141312-agent-loop)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: agent-loop
description: Build a minimal agent loop that streams, calls tools, and repeats until done
category: agent-llm
---

# Agent Loop

Reach for this to implement the core "model decides, tools run, repeat" cycle that turns a chat completion into an agent.

1. Seed a message list with a system prompt (role, tools available, stop conditions) and the user's request.
2. Call the model with the messages and the tool schemas; stream tokens to the user as they arrive.
3. If the response contains tool calls, append the assistant turn, execute each tool, and append a tool-result message per call.
4. Loop back to step 2 with the appended results; if the response has no tool calls, it's the final answer — stop.
5. Cap iterations (e.g. max 10) and total tokens to prevent runaway loops; surface a clear message when a cap is hit.
6. Handle errors per tool — return the error text as the tool result so the model can retry or change approach, rather than crashing the loop.

## Rules
- Always append the assistant's tool-call turn BEFORE the tool results, in the order the API expects, or the next call rejects the history.
- Execute independent tool calls concurrently, but preserve result ordering when appending them back.
- Enforce a hard iteration cap and a wall-clock/token budget; an agent with no brake will spin.
- Make tool execution idempotent or guard destructive actions, since the model may retry after a transient error.
- Stream text deltas but buffer tool-call arguments until complete — partial JSON is not parseable.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…