Skip to main content
Loop guardrails cap how many tool calls an agent can make in a single turn, stopping runaway loops from broken or chatty tools.
The user sends a request; the guardrail stops the turn once tool-call limits are reached.

Quick Start

1

Default Protection

Every agent gets automatic loop protection:
The user starts a workflow loop; guardrails cap iterations and stop runaway tool calls.
2

Custom Limit

Adjust the limit for your use case:

How It Works

The agent tracks tool_call_count across iterations within a single chat turn:
  1. Before each batch: Checks if tool_call_count >= max_tool_calls_per_turn
  2. At limit: Stops execution with clear message
  3. Batch trimming: If a batch would exceed the limit, it is trimmed before the assistant turn is recorded, so every declared tool_call_id still gets a reply.
  4. Reset: Counter resets for each new chat turn
When a batch hits the cap, it is trimmed before the assistant turn is recorded, so every tool_call_id the model declared gets exactly one tool reply. The follow-up LLM request stays a valid conversation — no "tool_use ids were found without tool_result blocks" 400s from OpenAI or Anthropic. The guarantee holds across sync start(), async astart(), the streaming fallback, and the sync and async Responses-API branches — see PraisonAI PR #6203 / issue #6202. The Responses-API branch also now labels each tool reply with its own tool name.

When the limit is hit

The agent stops cleanly instead of burning tokens indefinitely.

Choosing a limit


Common Patterns

Pattern 1: Protecting Experimental Tools

Pattern 2: Complex Research Agent


Best Practices

Use the default limit (10) unless you have a specific reason to change it. It handles most use cases well.
Set 3-5 calls when testing new or potentially buggy tools to prevent token waste.
Increase to 20-30 for agents that need multiple tool calls for complex, multi-step tasks.
If agents hit the limit frequently on legitimate tasks, increase it. If they waste tokens on broken tools, decrease it.

ExecutionConfig

Configure all execution limits

Autonomy Mode

DoomLoop protection for autonomous agents