For agentic platforms
Safeguard autonomous agents from catastrophic execution recursion.
Agents fail by repeating themselves, and each repetition re-sends the whole context. PALM SOUQ watches the shape of every run in the request path and halts loops in under 50 ms, before the invoice is written.
- 14:02:11.204step 9 tool=git.merge args#a91c 1,412 ms
- 14:02:13.880step 10 tool=run_tests exit=1
- 14:02:14.102step 11 tool=git.merge args#a91c identical x13
- 14:02:17.540step 12 tool=run_tests exit=1
- 14:02:17.911step 13 tool=git.merge args#a91c identical x14
- 14:02:20.367step 14 tool=git.merge args#a91c identical x15
- 14:02:20.391HTTP 429 circuit_breaker_triggered +24 ms
- 14:02:20.392run cost $7.20 envelope $25.00
The unique risks
Four ways an agent spends money doing nothing.
Rate limits count volume. Agent loops are often modest in volume and endless in duration. Each risk below maps to a heuristic that recognises its shape.
Read the agent loop taxonomy- 01
Multi-step reasoning loops
The planner re-plans after every failed step and the plan never changes. Each iteration re-sends the full context, so cost per step grows as the transcript grows.
Semantic echosimilarity(plan[n], plan[n-1]) > 0.93 for 5 steps - 02
Sub-agent spawning
An orchestrator delegates to a sub-agent, which delegates again. Without a depth limit the tree grows until a budget or a provider limit stops it.
Max step and recursion depthdepth > 4 or steps > 300 per run - 03
Self-reflection cycles
Critique, revise, critique again. Useful at two or three rounds, ruinous at forty, and it rarely spikes request rate enough to trip a rate limit.
Token velocity surge> 50k tokens/s over a 10 s window - 04
Web-browsing tool thrashing
A browser tool hits the same paywall, the same 404 or the same selector, and the agent retries with identical arguments.
Cyclical tool thrashing15 identical tool calls in 10 min
Multi-agent hierarchy governance
Give the parent a budget envelope. Let it cascade.
Every run gets an envelope, and every sub-agent gets a share of it. A child that loops exhausts its own share, not the run, and the depth breaker stops spawning at the level you choose.
Try it: switch to the spawn loop scenario, then turn the depth breaker off. Each researcher call here costs $0.42 on Claude Sonnet 4.5 at list price.
- Envelopes per run, per agent path, per tenant
- Pause and ask for approval instead of failing a run
- Trips logged with step, tool fingerprint and spend
- orchestrator envelope $50
- └ plannerrunning$2.75 / $5.00
- └ researcherhalted at depth 4$10.08 / $20.00
- └ coderrunning$12.42 / $17.50
- └ reviewerrunning$3.00 / $7.50
researcher spawned sub-agents to depth 4: 24 calls x $0.42 = $10.08 HTTP 429 X-PalmSouq-Reason: circuit_breaker_triggered (max_recursion_depth=4)
Worked example
A merge-conflict loop, priced both ways.
An unhandled exception leaves a coding agent retrying a merge. It fires 2,500 calls to Claude Sonnet 4.5 in 45 minutes before a step limit stops it.
Cost per call
$0.48
150k x $3/M + 2k x $15/M
Without a breaker
$1,200
2,500 calls x $0.48
Breaker at 15 identical calls
$7.20
15 calls x $0.48
In margin terms: on a $30 per month seat, one unchecked loop costs the revenue of $1,200 / $30 = 40 seats for a month. With the breaker it costs 24% of one seat.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://gateway.palmsouqltd.com/v1",
api_key=os.environ["ANTHROPIC_API_KEY"],
default_headers={
"X-PalmSouq-Tenant": workspace.id,
"X-PalmSouq-Tier": workspace.plan,
"X-PalmSouq-Feature": f"run:{run.id}/agent:{agent.path}",
"X-PalmSouq-User": user.id,
},
)
# On a trip the gateway answers instead of the provider:
# HTTP 429
# X-PalmSouq-Reason: circuit_breaker_triggered
# X-PalmSouq-Breaker: cyclical_tool_thrashingFour headers describe the whole hierarchy.
- X-PalmSouq-Tenant
- The workspace or customer paying for the run.
- X-PalmSouq-Tier
- Picks the policy: thresholds, envelope size, fallbacks.
- X-PalmSouq-Feature
- Run ID and agent path, so envelopes cascade.
- X-PalmSouq-User
- The person who started the run, for per-user limits.
“One-line drop-in, no latency we could measure, and the circuit breaker stopped tool thrashing completely.”
Questions, answered
Will a breaker kill legitimate long-running agents?
Thresholds are per policy and per tier. Long refactors or research runs get higher step limits and larger envelopes; what trips them is a pattern, such as identical tool calls or echoing plans, not length alone. Every trip is logged with the exact trigger so thresholds can be tuned.
What does my agent runner see when a breaker trips?
An HTTP 429 with X-PalmSouq-Reason: circuit_breaker_triggered and a header naming the heuristic. Most runners treat it as a terminal error for that run and surface it to the user.
How do budget envelopes cascade to sub-agents?
Encode the agent path in X-PalmSouq-Feature, for example run:7f3a/agent:orchestrator/researcher. A child spends against its own share and against the parent envelope, so one runaway branch cannot drain the whole run.
Does PALM SOUQ read my agent's prompts to detect loops?
The gateway reads payloads in memory while a request is in flight. Loop checks use derived signals, such as a hash of tool name and arguments, that cannot be turned back into text and are discarded after the detection window. Prompts and completions are never written to disk, logged or used for training.
Put a breaker in front of your next agent run.
Point your agent runner at gateway.palmsouqltd.com, pass a run ID, and every loop heuristic is on from the first request.
14-day free production trial · 100k requests included · no card required