Scenario
Five identical calls and a run that ended itself
RolesAgent Systems EngineeringAI Evaluation and Reliability
- Engine
- docker-agent v1.149.0 and sbx v0.47.0
- Model
- ai/qwen3:4b through the local model runner, at temperature 0
- Hardware
- one Mac, no GPU
Situation
A coordinator agent runs in a nightly job with --exec, and nobody watches a terminal. Its agent file gives it one sub-agent, a writer, and the background_agents toolset, so that it can start the writer in the background, wait, and repeat the writer's sentence. The job has worked for weeks when the coordinator used transfer_task. A teammate changed the user message to ask for a background agent, and the next run stopped with exit 1 and the line Agent terminated: detected 5 consecutive identical calls to run_background_agent.
The teammate reads the line as a runtime bug: the model was working, and the runtime killed it. The proposed fix is to raise the limit on repeated calls and to swap the model. You review the run before either change ships.
Questions
- Before you open the event stream, list what the model could have received after its first call, and what a well-behaved agent does with each answer.
- The runtime asked for a confirmation six times, and nobody answered. Why did the asks happen, and what turned each ask into a rejection?
- Compare the arguments of the six calls. What changed after the first round, and what does that tell you about how the model read the answer?
- Name the gate that ended the run, its default, and why the same agent file worked one run earlier.
- Write the change to the agent file or the command that lets a headless coordinator start a background agent, and say what you would leave as it is.
Commit to a cause after each listing. Write it down before you read the next one.
Evidence
the coordinator agent of the team file
The root agent has an iteration limit, one sub-agent, one handoff target and the background_agents toolset.
agents:
root:
model: local
description: Coordinates a writer and a reviewer.
instruction: |
You coordinate two colleagues and never write text yourself.
For every request: first call transfer_task to ask the writer for
the text, then call handoff to pass the conversation to the reviewer.
max_iterations: 6
sub_agents: [writer]
handoffs: [reviewer]
toolsets:
- type: background_agentsSource: manuals/docker-sandboxes-101/capture/fixtures/agents/team.yaml, lines 3-15
the same coordinator one run earlier, with transfer_task
The transfer_task call ran under --exec with no confirmation.
user: Ask the writer for one sentence about microVMs.
root -> tool_call transfer_task {"agent": "writer", "task": "Generate one sentence about microVMs", "expected_output": "A single sentence describing microVMs"}Source: manuals/docker-sandboxes-101/capture/out/19-transcript.txt, lines 1-2
the user message, the first background-agent call, and what came back
The call raised a confirmation, and the tool response says the user rejected it.
user: Run the writer as a background agent on the topic microVMs, wait for it, and repeat its sentence.
tool_call_confirmation: {"agent_name": "root", "tool_call": {"id": "<call-id>", "type": "function", "function": {"name": "run_background_agent", "arguments": "{\"agent\": \"writer\", \"task\": \"Write one sentence on the topic microVMs\", \"expected_output\": \"A single sentence about microVMs\"}"}}, "metadata": {"safety_label": "unknown"}}
root <- tool_call_response Run Background Agent: The user rejected the tool call.Source: manuals/docker-sandboxes-101/capture/out/19-background.txt, lines 1-3
the next five calls and their five answers
Compare the arguments of each call with the one before it.
tool_call_confirmation: {"agent_name": "root", "tool_call": {"id": "<call-id>", "type": "function", "function": {"name": "run_background_agent", "arguments": "{\"agent\": \"writer\", \"task\": \"Write one sentence on the topic microVMs\"}"}}, "metadata": {"safety_label": "unknown"}}
root <- tool_call_response Run Background Agent: The user rejected the tool call.
tool_call_confirmation: {"agent_name": "root", "tool_call": {"id": "<call-id>", "type": "function", "function": {"name": "run_background_agent", "arguments": "{\"agent\": \"writer\", \"task\": \"Write one sentence on the topic microVMs\"}"}}, "metadata": {"safety_label": "unknown"}}
root <- tool_call_response Run Background Agent: The user rejected the tool call.
tool_call_confirmation: {"agent_name": "root", "tool_call": {"id": "<call-id>", "type": "function", "function": {"name": "run_background_agent", "arguments": "{\"agent\": \"writer\", \"task\": \"Write one sentence on the topic microVMs\"}"}}, "metadata": {"safety_label": "unknown"}}
root <- tool_call_response Run Background Agent: The user rejected the tool call.
tool_call_confirmation: {"agent_name": "root", "tool_call": {"id": "<call-id>", "type": "function", "function": {"name": "run_background_agent", "arguments": "{\"agent\": \"writer\", \"task\": \"Write one sentence on the topic microVMs\"}"}}, "metadata": {"safety_label": "unknown"}}
root <- tool_call_response Run Background Agent: The user rejected the tool call.
tool_call_confirmation: {"agent_name": "root", "tool_call": {"id": "<call-id>", "type": "function", "function": {"name": "run_background_agent", "arguments": "{\"agent\": \"writer\", \"task\": \"Write one sentence on the topic microVMs\"}"}}, "metadata": {"safety_label": "unknown"}}
root <- tool_call_response Run Background Agent: The user rejected the tool call.Source: manuals/docker-sandboxes-101/capture/out/19-background.txt, lines 4-13
one round in the event stream, from the tool call to the next message
Read safety_label in the metadata, the two hook events, and isError in the result.
{"agent_name": "root", "metadata": {"safety_label": "unknown"}, "timestamp": "<ts>", "tool_call": {"function": {"arguments": "{\"agent\": \"writer\", \"task\": \"Write one sentence on the topic microVMs\", \"expected_output\": \"A single sentence about microVMs\"}", "name": "run_background_agent"}, "id": "<call-id>", "type": "function"}, "tool_definition": {"annotations": {"idempotentHint": false, "readOnlyHint": false, "title": "Run Background Agent"}, "category": "transfer", "description": "Start a sub-agent task in the background and return immediately with a task ID.\nUse this to dispatch work to multiple sub-agents concurrently. Native sub-agents inherit the current\nsession's safety policy and permissions; calls requiring confirmation are denied because background\ntasks are non-interactive. External harnesses enforce their own permission model. Check progress with\nview_background_agent, or join tasks and collect results with wait_background_agents instead of polling.", "name": "run_background_agent", "outputSchema": null, "parameters": {"additionalProperties": false, "properties": {"agent": {"description": "The name of the sub-agent to run in the background.", "type": "string"}, "expected_output": {"description": "The expected output from the agent (optional).", "type": "string"}, "task": {"description": "A clear and concise description of the task the agent should achieve.", "type": "string"}}, "required": ["agent", "task"], "type": "object"}}, "type": "tool_call_confirmation"}
{"agent_name": "root", "hook_event": "tool_input_transform", "session_id": "<uuid>", "timestamp": "<ts>", "type": "hook_started"}
{"agent_name": "root", "hook_event": "tool_response_transform", "session_id": "<uuid>", "timestamp": "<ts>", "type": "hook_started"}
{"agent_name": "root", "allowed": true, "duration_ms": "<n>", "hook_event": "tool_input_transform", "session_id": "<uuid>", "timestamp": "<ts>", "type": "hook_finished"}
{"agent_name": "root", "allowed": true, "duration_ms": "<n>", "hook_event": "tool_response_transform", "session_id": "<uuid>", "timestamp": "<ts>", "type": "hook_finished"}
{"agent_name": "root", "response": "The user rejected the tool call.", "result": {"isError": true, "output": "The user rejected the tool call."}, "timestamp": "<ts>", "tool_call_id": "<call-id>", "tool_definition": {"annotations": {"idempotentHint": false, "readOnlyHint": false, "title": "Run Background Agent"}, "category": "transfer", "description": "Start a sub-agent task in the background and return immediately with a task ID.\nUse this to dispatch work to multiple sub-agents concurrently. Native sub-agents inherit the current\nsession's safety policy and permissions; calls requiring confirmation are denied because background\ntasks are non-interactive. External harnesses enforce their own permission model. Check progress with\nview_background_agent, or join tasks and collect results with wait_background_agents instead of polling.", "name": "run_background_agent", "outputSchema": null, "parameters": {"additionalProperties": false, "properties": {"agent": {"description": "The name of the sub-agent to run in the background.", "type": "string"}, "expected_output": {"description": "The expected output from the agent (optional).", "type": "string"}, "task": {"description": "A clear and concise description of the task the agent should achieve.", "type": "string"}}, "required": ["agent", "task"], "type": "object"}}, "type": "tool_call_response"}
{"agent_name": "root", "session_id": "<uuid>", "timestamp": "<ts>", "type": "message_added"}Source: manuals/docker-sandboxes-101/capture/out/19-background.ndjson, lines 13-19
the last line of the run
The runtime ended the run, not the model.
stderr: Error: Agent terminated: detected 5 consecutive identical calls to run_background_agent. This indicates a degenerate loop where the model is not making progress.Source: manuals/docker-sandboxes-101/capture/out/19-background.txt, lines 14-14
what each safety mode does with a call that no pattern matched
Find the row for a run that chose no mode, then read the note below the table in the manual.
**Safety mode:** what the runtime does with a call that no pattern matched. It reads the call's label, `safe`, `destructive`, or `unknown`, and the mode decides {{docs-agent Permissions}}:
| Mode | `safe` | `destructive` | `unknown` |
|---|---|---|---|
| `strict` | ask | ask | ask |
| `balanced` | allow | ask | ask |
| `restricted` | allow | deny | deny |
| `autonomous` | allow | allow | allow |Source: manuals/docker-sandboxes-101/sections/5-5-permissions-safety-and-hooks.md, lines 59-66
The answer
Show the walkthrough
- Read the agent file. The root agent has
max_iterations: 6,sub_agents: [writer],handoffs: [reviewer], and one toolset of typebackground_agents. The file has nopermissionsblock, and the command chose no safety mode. So any call that is not approved by default has to ask someone. - Read the first round. The runtime raised
tool_call_confirmationforrun_background_agent, withsafety_labelunknownin the metadata. Under--execthere is no terminal to answer, so the runtime turned the question into a refusal. The tool response went back to the model as plain text:The user rejected the tool call. - Read the five rounds after it. The model sent the same call again, five times, with the same agent and the same task. It dropped
expected_outputafter the first round and changed nothing else. A rejection is a final answer about that call. The model treated it as a transient error and retried. - Read one round in the event stream. The tool call carries
safety_label: unknown. The two hook events aretool_input_transformandtool_response_transform, the built-in transforms, and both reportallowed: true. Nopre_tool_usehook and no allow pattern decided anything. The result hasisError: true, thenmessage_added, and the next model turn starts from the same state. - Read the last line. The runtime stopped the run after five identical calls in a row. The manual names the limit,
max_consecutive_tool_calls, and a value of 0 means the default of 5. The runtime caught a loop that the model did not. One run earlier the same coordinator calledtransfer_task, which is the one tool that is always approved without a prompt, so that run raised no confirmation. - Read the safety-mode table. A run that chose no mode keeps the old default: read-only tools run, and every other tool asks. The background-agent tool is not read-only and its label is
unknown. Underrestrictedan unknown label is denied, and understrictorbalancedit asks again. Only anallowpattern orautonomouslets the call through. The manual adds that inside a running task, a call that would ask is denied automatically, so a headless coordinator needs an allow rule forrun_background_agentand for the tools its sub-agents call.
Show the resolution
The cause is a headless run with a tool whose label is unknown and no allow pattern. Every call asked, every ask became a rejection, and the model repeated the call. The repeat limit worked as designed: it turned an endless loop into one exit code.
The fix is a permission, not a higher limit. Add an allow pattern for run_background_agent to the agent file, and allow patterns for the tools the writer will call, then rerun with --exec. The manual did not run the repaired configuration, so the check is yours: the first run_background_agent call must return a task id in the stream instead of a rejection, and the run must end with the writer's sentence and exit 0. Keep the limit at its default. Keep the safety mode out of autonomous.
The proof that the permission was the cause is already in the stream: every round shows a confirmation with no one to answer it, a result with isError: true, and no rule or hook in the decision. The run with transfer_task on the same file shows the other side: a tool that needs no approval ran once and returned.
Show the wrong turns
“Raise the limit on consecutive calls so the run can finish.”
Every call hit the same rejection. More rounds give more rejections, and the limit is the only thing that ended the run.
“Run the job with
--yolo.”That is
--safety autonomous: every tool is allowed, including every tool of the sub-agents. One allow pattern for one tool is the smaller change.“The model is at fault, swap it.”
The model received an error string and nothing else. Another model can retry the same way, and the runtime holds the gate for that reason. Check the permission before the model.
“Add a
pre_tool_usehook that answers allow.”From a preempting hook, an allow verdict is advice. The hook can deny or ask, and it cannot grant.
Show the general rule
A tool result that returns to the model as text is an input the model may ignore. When a run has nobody to answer a question, give the agent explicit allow patterns for the tools it must call and nothing more, and keep the runtime limits that stop a repeated step. Read a termination line as a gate that worked, then find the reason the model needed it.
Taught in
The sub-agents section records this run, the permissions section gives the decision order, and the failure modes lesson names a repeated step as a failure to gate.