Media Understanding(入站)— 2026-01-17

OpenClaw 可以在回复流水线运行之前,先对入站媒体(image/audio/video)做摘要理解。它会在检测到本地工具或 provider keys 可用时自动启用,也可以被禁用或自定义。若 understanding 关闭,models 仍会像平常一样收到原始文件/URLs。

各 vendor 专属的媒体行为由 vendor plugins 注册,而 OpenClaw core 负责统一的 tools.media 配置、fallback 顺序以及与 reply pipeline 的集成。

目标

  • 可选:先将入站媒体预处理为简短文本,以便更快路由并提升命令解析效果。
  • 始终保留原始媒体传递给 model(永远如此)。
  • 支持 provider APIsCLI fallbacks
  • 允许多个 model 按顺序 fallback(基于 error/size/timeout)。

高层行为

  1. 收集入站附件(MediaPathsMediaUrlsMediaTypes)。
  2. 对每个启用的 capability(image/audio/video),按照策略选择附件(默认:first)。
  3. 选择第一个符合条件的 model entry(基于 size + capability + auth)。
  4. 如果某个 model 失败,或媒体过大,则回退到下一个 entry
  5. 成功时:

    • Body 会变成 [Image][Audio][Video] block。
    • Audio 会设置 {{Transcript}};命令解析优先使用 caption text,如无 caption,则使用 transcript。
    • Captions 会以 User text: 的形式保留在 block 中。

如果 understanding 失败或被禁用,reply flow 仍会继续,并使用原始 body + attachments。

配置概览

tools.media 支持 共享 models 以及按 capability 的覆盖配置:

  • tools.media.models:共享 model 列表(使用 capabilities 做约束)。
  • tools.media.image / tools.media.audio / tools.media.video

    • 默认值(promptmaxCharsmaxBytestimeoutSecondslanguage
    • provider overrides(baseUrlheadersproviderOptions
    • Deepgram audio 选项通过 tools.media.audio.providerOptions.deepgram
    • audio transcript echo 控制(echoTranscript,默认 falseechoFormat
    • 可选的 按 capability 单独定义的 models 列表(优先于 shared models)
    • attachments 策略(modemaxAttachmentsprefer
    • scope(可选,用于按 channel/chatType/session key 做限制)
  • tools.media.concurrency:最大并发 capability 运行数(默认 2)。
  1. {
  2. tools: {
  3. media: {
  4. models: [
  5. /* shared list */
  6. ],
  7. image: {
  8. /* optional overrides */
  9. },
  10. audio: {
  11. /* optional overrides */
  12. echoTranscript: true,
  13. echoFormat: '📝 "{transcript}"',
  14. },
  15. video: {
  16. /* optional overrides */
  17. },
  18. },
  19. },
  20. }

Model entries

每个 models[] entry 都可以是 providerCLI

  1. {
  2. type: "provider", // default if omitted
  3. provider: "openai",
  4. model: "gpt-5.2",
  5. prompt: "Describe the image in <= 500 chars.",
  6. maxChars: 500,
  7. maxBytes: 10485760,
  8. timeoutSeconds: 60,
  9. capabilities: ["image"], // optional, used for multi-modal entries
  10. profile: "vision-profile",
  11. preferredProfile: "vision-fallback",
  12. }
  1. {
  2. type: "cli",
  3. command: "gemini",
  4. args: [
  5. "-m",
  6. "gemini-3-flash",
  7. "--allowed-tools",
  8. "read_file",
  9. "Read the media at {{MediaPath}} and describe it in <= {{MaxChars}} characters.",
  10. ],
  11. maxChars: 500,
  12. maxBytes: 52428800,
  13. timeoutSeconds: 120,
  14. capabilities: ["video", "image"],
  15. }

CLI templates 还可以使用:

  • {{MediaDir}}(包含该媒体文件的目录)
  • {{OutputDir}}(本次运行创建的 scratch dir)
  • {{OutputBase}}(scratch 文件基础路径,不带扩展名)

默认值与限制

推荐默认值:

  • maxChars:image/video 推荐 500(简短、便于命令处理)
  • maxChars:audio 推荐 不设置(默认输出完整 transcript,除非你手动设置限制)
  • maxBytes

    • image:10MB
    • audio:20MB
    • video:50MB

规则:

  • 如果媒体超过 maxBytes,该 model 会被跳过,并尝试下一个 model
  • 小于 1024 bytes 的 audio 文件会被视为空或损坏,并在 provider/CLI transcription 之前直接跳过。
  • 如果 model 返回内容超过 maxChars,输出会被截断。
  • prompt 默认是简单的 “Describe the {media}.”,并附带 maxChars 指引(仅 image/video)。
  • 如果 <capability>.enabled: true,但没有配置 models,OpenClaw 会尝试使用当前激活的 reply model,前提是它的 provider 支持该 capability。

自动检测 media understanding(默认)

如果 tools.media.<capability>.enabled 未被显式设置为 false,且你也没有配置 models,OpenClaw 会按以下顺序自动检测,并在找到第一个可用方案后停止

  1. 本地 CLI(仅 audio;若已安装)

    • sherpa-onnx-offline(要求设置 SHERPA_ONNX_MODEL_DIR,其中包含 encoder/decoder/joiner/tokens)
    • whisper-cliwhisper-cpp;使用 WHISPER_CPP_MODEL 或内置 tiny model)
    • whisper(Python CLI;会自动下载 models)
  2. Gemini CLIgemini),使用 read_many_files
  3. Provider keys

    • Audio:OpenAI → Groq → Deepgram → Google
    • Image:OpenAI → Anthropic → Google → MiniMax
    • Video:Google

如需关闭自动检测,可设置:

  1. {
  2. tools: {
  3. media: {
  4. audio: {
  5. enabled: false,
  6. },
  7. },
  8. },
  9. }

注意:二进制检测在 macOS/Linux/Windows 上是 best-effort;请确保 CLI 已加入 PATH(我们会展开 ~),或者显式配置一个带完整命令路径的 CLI model。

代理环境支持(provider models)

启用基于 provider 的 audiovideo media understanding 时,OpenClaw 会遵循标准的出站代理环境变量,用于 provider HTTP 调用:

  • HTTPS_PROXY
  • HTTP_PROXY
  • https_proxy
  • http_proxy

如果未设置任何 proxy 环境变量,media understanding 会直接出网。 如果 proxy 值格式错误,OpenClaw 会记录 warning,并回退为 direct fetch。

Capabilities(可选)

如果你设置了 capabilities,该 entry 只会用于这些媒体类型。对于 shared lists,OpenClaw 可以推断默认值:

  • openaianthropicminimaximage
  • moonshotimage + video
  • google(Gemini API):image + audio + video
  • mistralaudio
  • zaiimage
  • groqaudio
  • deepgramaudio

对于 CLI entries,建议显式设置 capabilities,以避免意外匹配。 如果省略 capabilities,该 entry 会默认适用于它所在的列表。

Provider 支持矩阵(OpenClaw integrations)

Capability Provider integration 说明
Image OpenAI、Anthropic、Google、MiniMax、Moonshot、Z.AI Vendor plugins 会把 image support 注册到 core media understanding。
Audio OpenAI、Groq、Deepgram、Google、Mistral provider transcription(Whisper/Deepgram/Gemini/Voxtral)。
Video Google、Moonshot 通过 vendor plugins 提供 provider video understanding。

Model 选择建议

  • 当质量和安全性重要时,优先为每种 media capability 选择当前最强、最新一代的 model。
  • 对于处理不可信输入且启用了 tool 的 agents,避免使用较旧或较弱的 media models。
  • 每种 capability 至少保留一个 fallback,以提高可用性(高质量 model + 更快/更便宜的 model)。
  • CLI fallbacks(whisper-cliwhispergemini)在 provider APIs 不可用时很有帮助。
  • parakeet-mlx 说明:配合 --output-dir 使用时,如果输出格式为 txt(或未指定),OpenClaw 会读取 <output-dir>/<media-basename>.txt;非 txt 格式则回退到 stdout。

附件策略

每个 capability 下的 attachments 用于控制要处理哪些附件:

  • modefirst(默认)或 all
  • maxAttachments:处理数量上限(默认 1
  • preferfirstlastpathurl

mode: "all" 时,输出会标记为 [Image 1/2][Audio 2/2] 等。

配置示例

1)共享 models 列表 + overrides

  1. {
  2. tools: {
  3. media: {
  4. models: [
  5. { provider: "openai", model: "gpt-5.2", capabilities: ["image"] },
  6. {
  7. provider: "google",
  8. model: "gemini-3-flash-preview",
  9. capabilities: ["image", "audio", "video"],
  10. },
  11. {
  12. type: "cli",
  13. command: "gemini",
  14. args: [
  15. "-m",
  16. "gemini-3-flash",
  17. "--allowed-tools",
  18. "read_file",
  19. "Read the media at {{MediaPath}} and describe it in <= {{MaxChars}} characters.",
  20. ],
  21. capabilities: ["image", "video"],
  22. },
  23. ],
  24. audio: {
  25. attachments: { mode: "all", maxAttachments: 2 },
  26. },
  27. video: {
  28. maxChars: 500,
  29. },
  30. },
  31. },
  32. }

2)仅启用 Audio + Video(关闭 image)

  1. {
  2. tools: {
  3. media: {
  4. audio: {
  5. enabled: true,
  6. models: [
  7. { provider: "openai", model: "gpt-4o-mini-transcribe" },
  8. {
  9. type: "cli",
  10. command: "whisper",
  11. args: ["--model", "base", "{{MediaPath}}"],
  12. },
  13. ],
  14. },
  15. video: {
  16. enabled: true,
  17. maxChars: 500,
  18. models: [
  19. { provider: "google", model: "gemini-3-flash-preview" },
  20. {
  21. type: "cli",
  22. command: "gemini",
  23. args: [
  24. "-m",
  25. "gemini-3-flash",
  26. "--allowed-tools",
  27. "read_file",
  28. "Read the media at {{MediaPath}} and describe it in <= {{MaxChars}} characters.",
  29. ],
  30. },
  31. ],
  32. },
  33. },
  34. },
  35. }

3)可选的 image understanding

  1. {
  2. tools: {
  3. media: {
  4. image: {
  5. enabled: true,
  6. maxBytes: 10485760,
  7. maxChars: 500,
  8. models: [
  9. { provider: "openai", model: "gpt-5.2" },
  10. { provider: "anthropic", model: "claude-opus-4-6" },
  11. {
  12. type: "cli",
  13. command: "gemini",
  14. args: [
  15. "-m",
  16. "gemini-3-flash",
  17. "--allowed-tools",
  18. "read_file",
  19. "Read the media at {{MediaPath}} and describe it in <= {{MaxChars}} characters.",
  20. ],
  21. },
  22. ],
  23. },
  24. },
  25. },
  26. }

4)多模态单一 entry(显式 capabilities)

  1. {
  2. tools: {
  3. media: {
  4. image: {
  5. models: [
  6. {
  7. provider: "google",
  8. model: "gemini-3.1-pro-preview",
  9. capabilities: ["image", "video", "audio"],
  10. },
  11. ],
  12. },
  13. audio: {
  14. models: [
  15. {
  16. provider: "google",
  17. model: "gemini-3.1-pro-preview",
  18. capabilities: ["image", "video", "audio"],
  19. },
  20. ],
  21. },
  22. video: {
  23. models: [
  24. {
  25. provider: "google",
  26. model: "gemini-3.1-pro-preview",
  27. capabilities: ["image", "video", "audio"],
  28. },
  29. ],
  30. },
  31. },
  32. },
  33. }

状态输出

当 media understanding 运行时,/status 会包含一行简要摘要:

  1. 📎 Media: image ok (openai/gpt-5.2) · audio skipped (maxBytes)

这会显示各 capability 的结果,以及实际选用的 provider/model(如适用)。

说明

  • Understanding 是 best-effort 的。即使出错,也不会阻塞 replies。
  • 即使 understanding 被禁用,attachments 仍然会传递给 models。
  • 可以使用 scope 来限制 understanding 的运行范围(例如只在 DMs 中启用)。