agent-ops-patterns / gallery / DeerFlow map / how it decides
How DeerFlow decides
In DeerFlow, a lead AI model does the work through tool calls and, when sub-agents are switched on (the web app does this only in its Ultra mode), can hand tasks to them; a run normally ends when that model replies without asking for a tool, and plain code can also remove tool calls to bring it to a close. When a thread has an active /goal, a separate model call can judge whether the conversation shows the goal was met, though some conditions stand the goal down without that call.
How it decides it is done
-
Do the receipt ids a sub-agent cites in its report point to real, successful tool calls?
Decided by plain code When a task sub-agent completes and receipts were harvested, code checks its report's citations against them. Any verdict shown to the lead does not change the task status.
receipt_verification.py:79· decision G7 in the full map -
Did the run actually hand over the output files it produced?
Decided by plain code On normal completion, worker code uses available before and after snapshots to detect changed output files. If some are detected and none is covered by a recorded present_files path, the delivery check returns an error.
worker.py:402· decision G5 in the full map
Limits and memory
-
How many graph steps may one run take before it is stopped?
Decided by plain code The Gateway takes the request's recursion_limit if it is a positive integer, otherwise the configured default, and caps it at max_recursion_limit.
services.py:1319· decision F1 in the full map -
Is the agent stuck repeating the same tool calls, and should it be warned or stopped?
Decided by plain code After a model response with tool calls, code counts repeated call sets per run. With defaults, a repeated set can trigger a warning at 3 and a stop at 5; a separate window counting tool names has thresholds of 30 and 50. A stop removes that response's calls and adds a stop message.
loop_detection_middleware.py:634· decision F5 in the full map -
How many turns may a sub-agent take?
Decided by plain code Code turns the sub-agent's max_turns (general-purpose 150, bash 60, config default 50) into a recursion limit.
turn_budget.py:128· decision F10 in the full map -
Is there a free slot to run this sub-agent now, or must it queue or be refused?
Decided by plain code A process-wide admission controller (default 3 running) admits the execution, queues it up to max_queued with a timeout, or rejects it at once under the reject policy.
capacity.py:68· decision H4 in the full map
Other judgments
-
Did the provider stop because the output budget ran out, and if so must the possibly truncated tool calls be suppressed and the person told?
Decided by plain code Four detectors recognise the provider's output cap. On a hit all tool calls are removed, and a notice is added when tool calls were removed or no visible text remains.
model_length_finish_reason_middleware.py:121· decision C5 in the full map -
How should the user's rough draft be rewritten before it is sent?
Decided by an AI model On request, a one-shot model call rewrites the draft into a clearer instruction; the user decides whether to send it.
input_polish.py:88· decision A11 in the full map -
Is an inbound IM text a channel command or a chat turn?
Decided by plain code Code checks whether the first whitespace-delimited token is a known slash command, case-insensitively.
commands.py:87-91· decision A9 in the full map
Three problems in the code
-
1. web_fetch cuts page content at 4,096 characters, with no notice of the cut
Each web_fetch tool the map cites keeps at most the first 4,096 characters of the content it selects and adds no notice of that cut, so a long page can reach the model incomplete with nothing from the tool saying so. The example config uses the Jina tool, which does this. An open pull request proposes making the limit a setting.
Reported; a fix is proposed, not merged (#1071), checked 2026-11-15.
Where:
tools.py:70-71,tools.py:130. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-08, in five rounds; each sentence it questioned was narrowed, removed or kept with the reason recorded. -
2. One matching presented file is enough to pass the delivery check
On a normal completion, when changed output files are detected, the delivery check compares them with the paths recorded as presented. One presented path that covers a detected change satisfies the check, even if the run's other changed output files were not presented. The check is written to catch runs that present none of them.
No tracker issue found, checked 2026-11-08.
Where:
worker.py:401-403,worker.py:418-422. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-08, in five rounds; each sentence it questioned was narrowed, removed or kept with the reason recorded. -
3. Fifty proposed calls to one tool can force a stop, even when each call differs
Besides counting repeated sets of tool calls, the loop check counts calls by tool name in a sliding window. At the default threshold, reaching 50 proposed calls to one tool in that window triggers a stop whatever their arguments: all calls in that response are removed and a stop message is added. A setting can raise the limit per tool. An open issue reports this limit interrupting batch scientific work, and a contributor there points to that setting.
Already tracked upstream (#2510), checked 2026-11-15.
Where:
loop_detection_middleware.py:699-718,loop_detection_middleware.py:846-855,loop_detection_config.py:58-70. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-08, in five rounds; each sentence it questioned was narrowed, removed or kept with the reason recorded.