---
title: "anlyon-agent-loop"
description: "The Agent Skill for handling what an Anlyon call returns inside an agent loop: waiting for approvals, connect prompts, refusals, unknown outcomes and idempotent retries."
---

`anlyon-agent-loop` teaches your coding agent what to do with each result an action call can return, in your code, in Vercel AI SDK tools and over MCP. The point is the moves an agent must not make: invoking a parked call again, retrying an outcome that may already have happened, or treating a `200` as success when the body says the call was refused.

## What it teaches

- **A table of every status and grade**, with the next move for each: report, wait, ask the user to connect, tell the user why it was refused, or stop and hand an `unknown` to a person.
- **A loop in TypeScript** that invokes with an idempotency key tied to your business operation, waits with `approvals.waitForDecision`, then reads the invocation.
- **The AI SDK results** from `@anlyonhq/ai-sdk`: `pending_approval`, `connect_required`, refusal codes and limits, and `anlyon_check_request` after the user decides.
- **The MCP flow:** `list_actions`, `action_<name>`, `wait_for_approval` until the decision arrives, and `request_approval` for a step that is not an action.
- **Retrying on purpose:** `retryOf` with a new key after a `failed`, reconciling an `unknown` before anything else, and the two idempotency conflicts.

## When it loads

When code or prompts deal with `actions.invoke`, `waitForDecision`, `wait_for_approval` or `check_approval`, `anlyon_check_request`, AI SDK tool results, idempotency keys, or an invocation that is `pending_approval`, `failed`, `unknown`, `denied` or `expired`.

## What's inside

| File | Holds |
| --- | --- |
| [`SKILL.md`](https://docs.anlyon.com/skills/anlyon-agent-loop/SKILL.md) | The result table, the loop, the AI SDK and MCP flows, retries |
| [`references/results.md`](https://docs.anlyon.com/skills/anlyon-agent-loop/references/results.md) | The invoke response, receipts, AI SDK and MCP result shapes |
| [`LICENSE`](https://docs.anlyon.com/skills/anlyon-agent-loop/LICENSE) | MIT |

Download: [anlyon-agent-loop.zip](https://docs.anlyon.com/skills/anlyon-agent-loop.zip).

## Install

```bash
npx skills add https://docs.anlyon.com --skill anlyon-agent-loop
```

## Try it

> Our worker calls `refund-order` through Anlyon. Make it wait for the approval, and make sure a restart can never refund twice.

> When the Anlyon tool says the user has to connect Slack, show a Connect button in the chat instead of an error.

> Write the system prompt section that tells our agent how to treat Anlyon results.
