Skip to main content
Glama

iteration_state

Manage retry tracking for individual modules in forge runs. Track attempt counts, scores, and stagnation flags to decide between retrying or escalating failed modules.

Instructions

Read, update, or reset the per-module retry state for a forge run. Tracks attempt count, score history, last status, last root cause from the debugger, and a stagnation flag. In v0.4.0+ state is scoped per run via runId so attempt counts don't accumulate across unrelated forge runs that happen to share a moduleId (pre-v0.4.0 a brand-new m1 in a fresh plan could see attempt: 21 because 20 prior runs had also used "m1" — stagnation detection would then escalate a module that had just started).

Behaviour:

  • READ (get), MUTATION (update, reset).

  • State files live at .forge/iterations/<runId>/<moduleId>.json when runId is provided, or .forge/iterations/<moduleId>.json for legacy callers.

  • runId is guarded against path traversal via the _RUN_ID_PATTERN regex (/^[\w.-]{1,128}$/) — invalid values return a structured error, never a traversal attempt.

  • No authentication, no network, no rate limits.

  • get on an unknown module returns a clean empty-state object { attempts: [], scores: [], stagnant: false } rather than throwing.

Use when:

  • The orchestrator wants to know how many times module m3 has been retried so far and whether the stagnation flag has flipped — drives the decision between RETRY and ESCALATE.

  • A debugger agent wants to inspect the last root cause before proposing a new approach.

  • Resetting: a plan has finished and the next run should start fresh even if moduleIds are reused. Or a human has manually cleared a stuck module and wants the counter zeroed.

Do NOT use for:

  • Cross-module reasoning or run-wide progress — that is session_state.

  • Recording the result of a single validation attempt — that is done automatically by validate on every call.

  • Inspecting validation results without side effects — get is safe, but update bumps counters and flags.

Returns (get): The full state object { attempts: [...], scores: [...], stagnant: bool, lastStatus, lastRootCause }. Returns (update): { updated: true, attempt: N, stagnant: bool }. Returns (reset): A confirmation string.

Example: iteration_state({ moduleId: "m3", action: "get", runId: "2026-04-15-1" }) → { "attempts": [ { "timestamp": "...", "status": "failed", "score": 0.4, "issues": [...] }, { "timestamp": "...", "status": "failed", "score": 0.6, "issues": [...] } ], "scores": [0.4, 0.6], "stagnant": false }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
moduleIdYesModule ID (e.g. m1)
runIdNoOptional run ID (plan slug). Scopes state to the current forge run. Without it, falls back to legacy global-state behavior.
actionYesget = read state, update = add attempt, reset = clear state
updateNoData for update action
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and delivers comprehensive behavioral disclosure. It details the three action types (READ, MUTATION), file storage locations, runId validation with regex pattern, security guarantees against path traversal, authentication/network/rate limit status, and get behavior for unknown modules. It also explains version differences in state scoping and distinguishes safe vs side-effect operations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, behavior, usage guidelines, returns, example) and every sentence adds value. While comprehensive, it's appropriately sized for a complex tool with multiple operations. The front-loaded purpose statement immediately communicates core functionality, though some behavioral details could be more condensed.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex tool with 4 parameters, no annotations, and no output schema, the description provides exceptional completeness. It covers purpose, behavior, usage scenarios, exclusions, security aspects, version differences, return formats for all three actions, and includes a concrete example. The description fully compensates for the lack of structured metadata, making the tool's functionality and constraints completely understandable.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the baseline is 3. The description adds meaningful context beyond the schema by explaining the runId's purpose in scoping state to forge runs and legacy behavior implications, clarifying that update action bumps counters and flags, and providing concrete examples of moduleId values. However, it doesn't elaborate on specific parameter interactions or edge cases beyond what the schema already documents.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states the tool's purpose as 'Read, update, or reset the per-module retry state for a forge run' with specific details about what it tracks (attempt count, score history, last status, last root cause, stagnation flag). It clearly distinguishes this from sibling tools by contrasting with session_state for cross-module reasoning and validate for recording validation attempts.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit 'Use when' scenarios with three concrete examples (orchestrator retry decisions, debugger inspection, resetting for fresh runs) and 'Do NOT use for' guidance that names specific alternative tools (session_state for cross-module reasoning, validate for recording attempts). This gives clear context for when to choose this tool versus alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TT-Wang/forge'

If you have feedback or need assistance with the MCP directory API, please join our Discord server