AgentHarness breaks with DeepSeek-family thinking models: reasoning_content not passed back on multi-turn tool calls (400), stream parser drops final answer, reasoning burns output budget
Summary
The scheduled extraction agents (kg_extraction / source_extraction / kg_extraction_backfill) and memory_compaction break when the default LLM is a DeepSeek-family thinking model (e.g. deepseek-v4-flash-free). The AgentHarness does not handle reasoning_content (streamed by these models), which produces four distinct failure modes. Switching the default to a non-thinking model fixes all of them immediately.
Context
- Default LLM:
deepseek-v4-flash-freethrough an OpenAI-compatible relay (/v1/chat/completions). - Observed over 8/1–8/5 (v0.10.49/0.10.50): kg_extraction ~100% failure on the worst day (72/72), kg_extraction_backfill never reached success (98/98 partial), source_extraction ~40% failure.
Failure modes observed
1. Multi-turn tool-call flow returns 400 — reasoning_content not passed back
The agent harness makes tool calls (e.g. read source → extract). On the follow-up turn, the reconstructed assistant message does not carry back the model's reasoning_content, which the DeepSeek API requires:
CompletionError: ProviderError: Invalid status code 400 Bad Request with message:
{"error":{"type":"invalid_request_error",
"message":"Error from provider (Console Go): Upstream request failed:
[invalid_request_error] The `reasoning_content` in the thinking mode must be passed back to the API."}}
2. Streamed responses fail to decode
CompletionError: ProviderError: Http client error: error decoding response body
Thinking models stream reasoning_content deltas; the response-body parser chokes on them.
3. memory_compaction — reasoning burns the whole output budget, final answer lost
scheduler task finished task_type=memory_compaction status=failed
error_message="the model produced reasoning but no final answer within the 16384-token output budget"
This is the same "responses stream parser drops final text" family as nowledge-co/community#869.
4. Timeouts on tool-call flows
Evening kg_extraction on 8/5: 33/39 failures were scheduler LLM attempt timed out. Reproduced directly: a tool-call conversation with deepseek-v4-flash-free hangs (>40s, no response), while the identical flow on a non-thinking model returns in ~5s.
Direct reproduction (curl, deepseek-v4-flash-free)
- Single-turn streaming: emits
reasoning_contentdeltas first, then content. - Multi-turn with a
tool_callsassistant turn +toolresult: hangs (>40s). - Non-streaming single response includes
reasoning_contentin the message; a second plain-text turn that omits it is tolerated, but tool-call round-trips are not.
Requested fix (any of)
- Parse
reasoning_contenton streamed responses and pass it back when reconstructing assistant turns (required by DeepSeek API in thinking mode), or - Add a per-provider "disable thinking mode" toggle so a thinking model can be forced to plain output, or
- At minimum, detect thinking-mode models and surface a clear config error instead of silent 400/timeout floods.
Workaround (confirmed working)
Switch purposes.default to a non-thinking model on the same relay — laguna-s-2.1-free or gpt-5.6-luna. Both stream plain content only (no reasoning_content), multi-turn tool-call flows complete in ~5s, and scheduled extraction succeeds.
Related
- nowledge-co/community#869 (Responses SSE stream parser fails to extract final text)
- nowledge-co/community#876 (reindex: transient relay failure aborts whole batch / fake success)
我把这里拆成两个层级处理了。
第一层是后台 direct LLM lane 里的 “reasoning 被丢掉 / 空 final text / output budget 被耗尽” 问题。这个已经在 nowledge-co/mem#852 里修:
- OpenAI-compatible response 里的
message.reasoning会作为reasoning_contentalias 读取,OpenRouter/Nous 这类网关不会再把 hidden reasoning 丢掉。 - 对“没有 final text,但 usage 里
output_tokens >= output_budget”的完成结果,scheduler 会按 output budget exhausted 走已有的单次封顶恢复和 cooldown/dead-letter 路径,而不是落到error_kind=other。
这应该覆盖 kg_extraction / daily_briefing / thread_synced / memory_created 里最典型的空文本预算撞墙问题。
第二层,也就是这个 issue 里提到的 streaming parser、tool-call 多轮 reasoning pass-back、thinking model hang,这个还不能说已经完全解决。那需要 AgentHarness 把 reasoning/finish_reason 做成更完整的 typed roundtrip,而不是只在 direct completion recovery 里补信号。当前 workaround 仍然是:后台任务先用非-thinking 模型;thinking 模型支持我们继续按这条 issue 跟。
Update: the first layer described above has now been verified and merged for the next patch build.
This covers the direct background-generation path:
- OpenRouter/Nous-style
message.reasoningis preserved as structured hidden reasoning. - Empty final-text responses that hit the provider-reported output budget now trigger the bounded output-budget recovery path.
- The failure no longer falls through as a generic empty response /
error_kind=other.
The broader AgentHarness multi-turn tool-call issue for thinking models remains a separate follow-up, because replaying tool turns has stricter at-most-once constraints. I am keeping this issue open for that larger part until it is handled and verified separately.
补充证据:同一问题在 OpenAI Responses API 格式(ollama.com/v1)下同样复现,请确认 mem#852 的修复覆盖 Responses 格式的 reasoning 事件。
环境:nmem 0.10.73,provider = ollama.com/v1(api_format=responses),模型 deepseek-v4-flash:0731(thinking 模型,max output 128k)。
现象(与 nowledge-co/community#887 的 failure mode 2/3 一致):
wants_json=true任务(kg_extraction_backfill / memory_created_backlog_review)在output_budget=3072下:流以response.incomplete(incomplete_details.reason=max_output_tokens)结束,无最终 output_text,input/output tokens 均为 0- nmem 日志:
OpenAI response stream was incomplete: max_output_tokens→model used the output budget for reasoning without a final answer(重试扩到 12288/16384 仍失败) - 连续失败触发熔断:
skipping structured background lane: selected model/config repeatedly failed to return final structured output,retry_at 24h 后
curl 复现(responses 格式,stream=true):
POST /v1/responses
{"model":"deepseek-v4-flash:0731","input":"输出JSON","instructions":"只输出JSON","max_output_tokens":50,"stream":true}
→ 事件序列:response.reasoning_summary_text.delta ×N → response.reasoning_summary_text.done → response.incomplete
→ incomplete_details: {"reason":"max_output_tokens"},output 仅含 reasoning(summary_text),无 message
(无 instructions 时同预算可正常 completed——preamble_transport=instructions 会触发深度 reasoning。)
已验证缓解:
"reasoning":{"effort":"none"}→ 同预算下response.completed✓- 换非 thinking 模型(gemma4:31b)→ 稳定 ok=true
建议:①确认 mem#852 修复对 Responses 格式的 response.reasoning_summary_text 事件同样生效;②output_budget 对 thinking 模型应预留 reasoning 消耗或按模型能力自适应(当前 3072 对 128k 输出模型过于保守);③supports_reasoning=false 时透传 reasoning:{effort:"none"}。
Additional reproduction on v0.10.82 (macOS, MiniMax-M3 through an OpenAI-compatible loopback relay).
This appears to be the same reasoning/output-budget family, but it also reproduces in small direct scheduler lanes:
1) memory_created
- purpose:
background wants_json=true- scheduler
output_budget=900 - provider result:
ok=true,input_tokens=6313,output_tokens=900 - task result:
status=partial,error_kind=invalid_review_response,invalid_json_object - relay audit: request allowed, 267 reasoning chunks observed/suppressed, no protocol retries
2) label_consolidation
- purpose:
background wants_json=false- scheduler
output_budget=1024 - provider result:
ok=true,input_tokens=1538,output_tokens=1024 - task result:
status=failed,error_kind=label_consolidation_judgment_failed - relay audit: request allowed, 60 reasoning chunks observed/suppressed, no protocol retries
The configured provider limit is 8192 tokens, so the 900/1024 limits are scheduler task budgets, not the model/account limit. Both failed calls exactly consumed the task budget. The relay does not lower max_tokens; it only removes hidden reasoning deltas from the returned stream after the upstream response.
Suggested improvements:
- reserve final-answer/JSON headroom separately from reasoning;
- detect
output_tokens == output_budget/ length exhaustion and retry with a larger bounded budget; - or allow a per-purpose low/no-thinking mode for structured background lanes.
No data loss was observed: completed work was retained and downstream KG/working-memory tasks succeeded.
Follow-up from the same reporter, now on v0.10.91 (macOS, local mode). This looks like the same reasoning/output-budget family, now seen in the wm_refresh scheduler lane, and the visible effect is that Working Memory stops updating.
Evidence (from ~/Library/Application Support/NowledgeGraph/Logs/app.log*, 2026-09-24 → 2026-10-02; no memory content included):
task_type=wm_refresh,purpose=background,wants_json=true,output_budget=1200- 129 completed runs in 9 days:
- 76 ×
status=partial,error_message="the model exhausted its 1200-token output budget before returning a valid structured response"(output_tokens=1200,reasoning_only=false,input_tokens≈ 1.7K–2.1K) - 53 ×
status=success,events=0(no update written) - 0 runs with
events>0— nothing was written in this whole window
- 76 ×
- A manual
daily_briefingrun with a different provider returnedDaily Briefing completed: no briefing needed, so the "nothing written" result is not specific to one provider/relay. (The log does not record which provider eachwm_refreshrun used.)
User-visible symptom: ~/ai-now/memory.md / nmem wm still shows the content from 2026-08-28 (file mtime Aug 28), while nmem wm history labels today's date as current. The previous archive entry is 2026-08-27.
Settings checked: maxTokensPerTask/Hour/Day = 0, provider max_tokens = 8192, so the 1200 limit does not come from user configuration (it looks like the built-in scheduler budget).
Questions:
- Does the bounded output-budget recovery from nowledge-co/mem#852 apply to
wm_refresh? On 0.10.91 it still ends aspartialwith the message above. - Should
wm_refreshreserve final-answer headroom or retry with a larger budget, or is a non-thinking mode planned per purpose? - Is
successwithevents=0for roughly 40% of runs expected, given that many new memories were created during the window?
Happy to provide more sanitized log excerpts if useful.
A harness-side variant still shows up on 0.10.124 (Linux, self-hosted), with the built-in DeepSeek provider (deepseek-flash, official API https://api.deepseek.com/v1, Chat Completions) as the background model.
Between 2026-11-26 14:55 and 2026-11-27 09:30 UTC, 133 kg_extraction tasks succeeded, 8 failed with kg_extraction_all_failed, and 3 were skipped. Most failures look like this:
2026-11-26T17:06:48Z WARN nmem_harness::harness: AgentHarness provider stream error session_id=sched-kg_extraction error=PromptError: CompletionError: ResponseError: the model produced no answer and stopped with finish_reason=Length; the turn ran out of output budget before producing one [...]
2026-11-26T17:06:48Z WARN nmem_server::scheduler_service::lanes::knowledge_graph: agentic KG extraction failed; recorded per-memory retry state error=the model exhausted its max_output_tokens output budget without a final answer failure_count=1
There was also one malformed tool call: "tool call knowledge_graph_write arrived with malformed JSON input: key must be a string at line 1 column 758".
Three things we could not settle from the log:
- Is thinking off in harness calls? The direct scheduler lane reports
reasoning_control=Disabledfor DeepSeek. The harness logs neither the budget nor the reasoning control, so we cannot tell whether thinking was on. Could you confirm what the AgentHarness sends to DeepSeek? - Which
max_tokensthe error means. It tells the user to raisemax_tokens, but the provider'smax_tokenswas already 384,000 when these failures happened. - Logging. Recording the budget and the reasoning control for agent-harness calls, as the scheduler already does for its own calls, would make this diagnosable.
Thanks @E-Mezzogori for the 0.10.124 update and data! We've passed the AgentHarness sched-kg_extraction max_output_tokens failures and the logging gap around the effective budget and reasoning_control along to the team, and we'll update this issue once a release with the fix is out.