{"record":{"id":"5353004dd2349061","repo":"zed-industries/zed","slug":"the-agent-reached-the-maximum-number-of-allowed-requests","errorCode":null,"errorMessage":"The agent reached the maximum number of allowed requests between user turns. Try prompting again.","messagePattern":"The agent reached the maximum number of allowed requests between user turns\\. Try prompting again\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/agent/src/agent.rs","lineNumber":3537,"sourceCode":"                        thread.update(cx, |thread, cx| thread.cancel(cx)).await;\n                        Err(anyhow!(\n                            \"The agent is nearing the end of its context window and has been \\\n                             stopped. You can prompt the thread again to have the agent wrap up \\\n                             or hand off its work.\"\n                        ))\n                    }\n                }\n            };\n            let discard_partial_output = matches!(\n                &response,\n                Ok(Some(response)) if response.stop_reason == acp::StopReason::Cancelled\n                    || response.stop_reason == acp::StopReason::Refusal\n            );\n            let result = match response {\n                Ok(Some(response)) => match response.stop_reason {\n                    acp::StopReason::Cancelled => Err(anyhow!(\"User canceled\")),\n                    acp::StopReason::MaxTokens => Err(anyhow!(\"The agent reached the maximum number of tokens.\")),\n                    acp::StopReason::MaxTurnRequests => Err(anyhow!(\"The agent reached the maximum number of allowed requests between user turns. Try prompting again.\")),\n                    acp::StopReason::Refusal => Err(anyhow!(\"The agent refused to process that prompt. Try again.\")),\n                    _ => thread.read_with(cx, |thread, _cx| {\n                        thread\n                            .last_message()\n                            .and_then(|message| {\n                                let content = message.as_agent_message()?\n                                    .content\n                                    .iter()\n                                    .filter_map(|content| match content {\n                                        AgentMessageContent::Text(text) => Some(text.as_str()),\n                                        _ => None,\n                                    })\n                                    .join(\"\\n\\n\");\n                                if content.is_empty() {\n                                    None\n                                } else {\n                                    Some(content)\n                                }","sourceCodeStart":3519,"sourceCodeEnd":3555,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/agent/src/agent.rs#L3519-L3555","documentation":"Mapped from ACP StopReason::MaxTurnRequests: the agent exceeded the maximum number of model requests permitted within a single user turn (a turn-request cap that prevents unbounded agentic loops). The run is stopped and this error is returned to the parent thread instead of a final message.","triggerScenarios":"A subagent enters a long chain of tool calls (search, read, edit) requiring more model round-trips than the per-turn limit allows, so the backend ends the turn with stop_reason=MaxTurnRequests.","commonSituations":"Broad, open-ended tasks like 'fix all the tests' or 'refactor this crate' that spiral into dozens of tool invocations; tool failures causing retry loops; agents stuck re-reading the same files.","solutions":["Give the agent a narrower, more specific task so it completes within fewer requests","Re-prompt the thread to continue from where it stopped, as the message suggests","Split the work into multiple sequential turns with intermediate checkpoints","Reduce tool-call churn by providing the needed context/files up front in the prompt"],"exampleFix":"// before: unbounded task\nthread.send(\"Fix every failing test in the workspace\");\n\n// after: bounded task\nthread.send(\"Fix only the failing tests in crates/agent/src/tests/agent_tests.rs\");","handlingStrategy":"retry","validationCode":"// avoid dispatching tasks likely to need many tool calls:\n// keep prompt scope to a single file/module when possible","typeGuard":null,"tryCatchPattern":"match subagent_result {\n    Err(e) if e.to_string().contains(\"maximum number of allowed requests\") => {\n        // re-prompt the thread to continue, or split the task and retry\n    }\n    other => other?,\n}","preventionTips":["Scope each agent turn to a bounded, well-defined task","Provide needed file contents in the prompt to cut down tool-call round trips","Checkpoint progress across turns instead of one giant task","Watch for tool-failure retry loops that burn the request budget"],"tags":["agent","llm","loop-limit"],"backgroundTag":"value-out-of-range","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}