Learning resourcesReviewed · OpenRouter

OpenRouter Agent SDK: Doom-Loop Detection

OpenRouter’s doom-loop detection guide helps developers limit repetitive AI-agent runs, but it detects matching repetitions rather than proving that an agent is making progress. It explains optional callModel safeguards, including observation, steering, temporary model escalation, blocking and stopping, with tool-specific matching and support for saved conversations.

Researched 13 Nov 2026

In short.

This OpenRouter documentation guide teaches AI-agent developers to control repetitive runs, but its matching rules can miss loops with changing inputs or wording. Detection is disabled by default; doomLoop: true enables observation at 2, blocking at 3 and stopping at 6. Developers can customize matching, exempt legitimate repetition and request temporary model or advisor help. Server-tool and text repetitions cannot be blocked, and saved conversations retain detection state only when detection is enabled again on resume. SDK compatibility, detection accuracy, actual savings and runtime behavior were not assessed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete selected page at [https://openrouter.ai/docs/agent-sdk/call-model/doom-loop-detection.md], including its examples, action table, notes and limitations. The documentation-index notice and links to lifecycle hooks, MCP tools and async tools refer to destinations outside this scope; those pages are excluded. No code was executed. Installation, SDK compatibility, detection accuracy, external model availability and realized costs were not assessed.

The overview

identity

Doom-Loop Detection is an OpenRouter Agent SDK documentation page about safeguards inside the callModel tool loop. The original page is [https://openrouter.ai/docs/agent-sdk/call-model/doom-loop-detection.md]. It is a guide to an SDK feature, with inline TypeScript examples.

assessment

The guide is useful for developers whose agents repeatedly retry the same operation, repeat a server-side search or produce identical text. It gives concrete configuration options and explains exceptions that affect integration. Its usefulness depends on whether repeated inputs are a good signal of failure in the application: legitimate polling may need an exemption, while ineffective calls with changing arguments may require custom matching.

users

The primary audience is developers building or maintaining agents with OpenRouter’s callModel API. Beginners get an explanation of repeated-call failures and a short enablement example, but the page assumes familiarity with model calls and tool definitions. Experienced developers get details about lifecycle hooks, malformed calls, MCP tool metadata and conversation persistence.

capabilities

The detector watches repeated calls to application-defined tools, including malformed requests; repeated requests to OpenRouter server tools; and exact text repetition. Available responses are observation through the DoomLoopDetected hook, a steering message, temporary escalation, blocking and stopping. The strongest action whose threshold has been reached takes precedence.

Blocking prevents a repeated application-tool call from executing and returns an explanatory error to the model. Text and server-tool repetitions have already happened, so a block verdict falls back to the strongest enabled weaker action. Stopping ends the session with reason doom_loop and supplies error outputs for unfinished tool calls so the conversation remains valid for resumption.

Using it

requirements

The examples assume an existing OpenRouter SDK integration with a model, input and any relevant tool definitions. Detection must be explicitly enabled through doomLoop. Escalation additionally requires an escalation configuration. The page does not establish installation commands, authentication setup, supported runtimes or a minimum SDK version.

mechanism

The documentation describes deterministic counting: the same transcript produces the same result. A repeat requires the model to have seen the result before trying again; identical calls issued together count once. Using other tools between retries does not reset a tool’s streak. By default, matching compares all inputs while tolerating JSON key-order and formatting differences.

A tool’s loopKey can normalize inputs, select relevant fields or disable counting. A function can return null to exclude one call; returning undefined, throwing or producing an unhashable value triggers full-input matching and a warning. A field-name array can survive caching and travel through _meta['openrouter/loopKey']. MCP tools accept matching configuration through markMcp or createMCPTools.

Streaks are stored in conversation state and survive saving and resuming when the resumed call also supplies doomLoop. A fresh user message can clear a stop verdict without clearing the streaks.

setup

Set doomLoop: true in callModel to use the documented defaults: observe at 2, block at 3 and stop at 6. Steering and escalation are disabled by default. A configuration object can change the action thresholds and text detection. Retrieve a detection verdict through await result.getDoomLoopVerdict().

For temporary help, configure an escalation threshold plus a replacement model, an advisor consult or both. The next turn receives that help before normal operation resumes. maxEscalations limits escalation events across the conversation, including resumes. A DoomLoopDetected hook can override an event’s action; the last handler’s override wins.

example

The search-tool example uses loopKey: ({ query }) => query.trim().toLowerCase(). That makes Cats and a space-padded lowercase cats count as the same search. This illustrates how to ignore superficial variation that would otherwise prevent matching.

The bash example identifies calls by command and working directory while ignoring a verbose flag; the equivalent field-array form is loopKey: ['command', 'cwd']. A status-polling tool uses loopKey: false because repeating its request is expected. These are documentation examples; their runtime behavior was not assessed.

Assessment & evidence

limitations

Changing inputs can evade default tool matching, and paraphrasing can evade exact-text detection. A suitable loopKey can address irrelevant input variation, but the page does not establish semantic detection of equivalent wording or unproductive behavior generally.

Matching examines inputs before PreToolUse hooks rewrite them. Manual and client-executed calls are excluded, and built-in task-tool calls are exempt. A block action cannot prevent text or server-tool activity that has already occurred.

Threshold choices can also weaken protection. The SDK warns about unreachable weaker actions and blocking without a stopping threshold. Exempting a tool or choosing an overly broad matching key requires care because it changes which repetitions can trigger intervention.

reasoning

The documented rules support using this feature as one guard against repetitive agent behavior. Matching can make intervention predictable, and custom keys can adapt it to application tools. It should not be treated as proof of progress or a complete spending limit, because changing inputs, exempt calls and repeated blocked attempts can remain outside effective protection.

alternatives

The page offers several response strategies within the same SDK: observe repetitions, steer the model, request temporary help, block calls or stop the run. It also mentions stopWhen as a separate bound on continued retries. It provides no comparison with other SDKs or external loop detectors, so their relative cost and effectiveness are unknown.

evidence

The evidence is the complete OpenRouter documentation page, including configuration examples, the action table, persistence behavior and stated exclusions. It provides descriptive API guidance but no benchmark results, detection-accuracy measurements, cost measurements or runtime test output. Those outcomes remain unassessed.

Access & freshness

costs

The page provides no feature price, model rates, advisor charges or measured savings. Actual cost is unknown. Detection is presented as a way to limit waste from repetition, but the evidence does not quantify that benefit.

Temporary model escalation or advisor consultation may affect spending. maxEscalations limits how often escalation happens; it does not establish a monetary ceiling. Blocking without stopping can leave an agent retrying indefinitely unless stopWhen bounds the run.

rights

The page supplies no explicit licence or redistribution terms for the documentation, inline examples or SDK. Permission to redistribute those materials is unknown from this evidence.

freshness

The page was captured on 13 November 2026 at 08:05:07 UTC. It states no publication date, last-updated date or supported SDK release. Model identifiers in the examples do not establish their current availability, pricing or suitability for a particular application.

actions

For an existing callModel integration, start by reviewing which repeated operations indicate failure and which are expected. Enable detection, retain a stopping threshold and define loopKey rules where superficial argument changes would hide repetition.

Before relying on the feature, evaluate repeated valid and malformed calls, legitimate polling, text repetition, server-tool behavior and saved-conversation resumption in a development environment. Confirm SDK compatibility and actual model or advisor charges separately. These are suggested evaluation steps, not completed tests.

Evidence for this report

selected-page.txtselected · checked 2026-11-13