Skip to content

file_extract 默认关闭导致文件内容丢失,LLM 只看到 [File] 占位符 #8997

Description

@sunlonglong-creator

问题

通过 QQ 发送文件给机器人时,LLM 看不到文件内容,只收到 [File] 占位符或 <attachment>,文件 URL 完全丢掉了。

复现

  1. 在 QQ 中向机器人发送一个文件(不附带文字,或附带文字如"帮我看下")
  2. LLM 回复中完全不知道文件内容,或一问三不知
  3. 检查日志可以看到请求中 prompt 为空或仅有文字,文件 URL 未出现在上下文里

链路分析

QQ文件事件 → aiocqhttp_adapter
  → message_str = ""(File 不贡献文本)
  → File(url=..., name=...) 存入消息链 ✓

internal.py (InternalAgentSubStage.process):
  → has_media_content = True ✓(不会跳过请求)
  → file_extract_enabled = False(默认关闭)
  → _apply_file_extract 被跳过!

astr_main_agent.py (build_main_agent):
  → req.prompt 为空(如果无附带文字)
  → 无 image_urls、无 audio_urls
  → has_reply = False → return None  ← 整个请求被丢弃

如果带了文字一起发送,req.prompt 有内容不会 return None,但文件的 URL/路径仍然没有传给 LLM —— 它只知道有文件但不知道是什么、怎么读。

根因

core/utils/file_extract.py 的 Moonshot AI 文件提取功能默认 enable: False。关闭之后,AstrBot 没有任何备用机制将文件 URL 或本地路径透传给 LLM 或上下文。文件消息的 URL 被闷在 File 组件里,从未进入 ProviderRequest.contextsreq.prompt

建议修复方向

  1. 最低成本方案:不依赖 Moonshot AI,直接把文件 URL/名称追加到 req.promptreq.contexts 中,类似 "[用户上传了文件: xxx.pdf,URL: https://...]",让 LLM 知道有文件并可以调 astrbot_file_read_tool 来读。
  2. 完整方案:对常见纯文本格式(.txt, .md, .py, .log 等)做本地读取后直接注入上下文,不经过 Moonshot API。
  3. 配置层面file_extract.enable 默认值改为 true 或增加一个 fallback 开关。

环境

  • AstrBot: v4.25.6(uv tool 安装)
  • 平台: aiocqhttp (QQ / Napcat)
  • 模型: deepseek-v4-flash (Sensenova API)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendarea:platformThe bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions