help wanted
Description
背景
执行调研/分析任务时,Agent 将完整报告通过 write_file 工具一次性写入文件。报告内容较长,LLM 需要在单次流式响应中生成整个 content 参数。
现象
写入文件时报错,两种错误交替出现:
错误 1(在config.yaml中配置 stream_chunk_timeout 前)
File "/app/backend/.venv/lib/python3.12/site-packages/langchain_openai/chat_models/base.py", line 3361, in _astream
async for chunk in super()._astream(*args, **kwargs):
File "/app/backend/.venv/lib/python3.12/site-packages/langchain_openai/chat_models/base.py", line 1838, in _astream
async for chunk in _astream_with_chunk_timeout(
File "/app/backend/.venv/lib/python3.12/site-packages/langchain_openai/chat_models/_client_utils.py", line 665, in _astream_with_chunk_timeout
raise StreamChunkTimeoutError(
langchain_openai.chat_models._client_utils.StreamChunkTimeoutError: No streaming chunk received for 120.0s (model=mimo-v2.5, chunks_received=58). The connection may be alive at the TCP layer but is not producing content. Tune or disable via the `stream_chunk_timeout` constructor kwarg (set to None or 0 to disable) or the `LANGCHAIN_OPENAI_STREAM_CHUNK_TIMEOUT_S` env var. See also `http_socket_options` for the kernel-level TCP timeout that catches dead TCP peers.
错误 2(配置 stream_chunk_timeout: 300 后)
2026-05-24 02:45:11 - deerflow.agents.middlewares.llm_error_handling_middleware - WARNING - Transient LLM error on attempt 1/3; retrying in 1000ms: peer closed connection without sending complete message body (incomplete chunked read)
复现条件
- 场景:Agent 执行
write_file(content="完整报告"),单次工具调用 content 参数很大时 - 正常场景:同样内容让 LLM 直接输出到页面(对话式输出),正常完成
- 多环境验证:本地电脑(家庭宽带)和公司服务器(数据中心)均出现过
- 多模型验证:不同 LLM 提供方均出现过
已尝试的修复
- 配置
stream_chunk_timeout: 300:无效,只是把报错从"客户端超时"变成"服务器断连" - 重启家庭路由器:暂时有效,但公司服务器环境同样出现
求助问题
- 是否有更好的方式处理长报告写入?是否考虑在工具层面支持自动分块?
- 是否可以在 Skill 提示词中引导 LLM 分章节追加写入(
append=True),避免单次生成超长 content,但有些情况下调研任务并没有通过Skill执行,所以系统提示词层面引导? create_chat_model中是否需要设置默认的stream_chunk_timeout和 httpxtimeout值?- 社区是否有类似经验,长流式响应的最佳实践是什么?