媒体理解(入站)— 2026-01-17
OpenClaw 可以在回复流程运行前自动总结入站媒体(图片/音频/视频)。它会自动检测本地工具或 Provider 密钥是否可用,你也可以禁用或自定义这个功能。如果关闭理解功能,模型仍会像往常一样接收原始文件或 URL。
目标
- 可选:将入站媒体预先转换成简短文本,加快路由速度,提升命令解析效果。
- 始终保留原始媒体传递给模型。
- 支持 Provider API 和 CLI 备用方案。
- 允许配置多个模型,按顺序进行故障转移(处理错误/大小/超时)。
工作流程
- 收集入站附件(
MediaPaths、MediaUrls、MediaTypes)。 - 对每个启用的能力(图片/音频/视频),按策略选择附件(默认:第一个)。
- 选择第一个符合条件的模型条目(大小 + 能力 + 认证)。
- 如果模型失败或媒体太大,回退到下一个条目。
- 成功时:
Body变成[Image]、[Audio]或[Video]块。- 音频会设置
{{Transcript}};命令解析会优先使用标题文本, 如果没有标题则使用转录文本。 - 标题会保留为块内的
User text:。
如果理解失败或被禁用,回复流程会继续,使用原始正文和附件。
配置概览
tools.media 支持共享模型列表以及按能力覆盖:
tools.media.models:共享模型列表(使用capabilities来限制)。tools.media.image/tools.media.audio/tools.media.video:- 默认值(
prompt、maxChars、maxBytes、timeoutSeconds、language) - Provider 覆盖(
baseUrl、headers、providerOptions) - Deepgram 音频选项通过
tools.media.audio.providerOptions.deepgram配置 - 可选的按能力
models列表(优先于共享模型) attachments策略(mode、maxAttachments、prefer)scope(可选,按 channel/chatType/session key 限制)
- 默认值(
tools.media.concurrency:最大并发能力运行数(默认 2)。
{
tools: {
media: {
models: [
/* 共享列表 */
],
image: {
/* 可选覆盖 */
},
audio: {
/* 可选覆盖 */
},
video: {
/* 可选覆盖 */
},
},
},
}
模型条目
每个 models[] 条目可以是 provider 或 CLI:
{
type: "provider", // 省略时默认
provider: "openai",
model: "gpt-5.2",
prompt: "Describe the image in <= 500 chars.",
maxChars: 500,
maxBytes: 10485760,
timeoutSeconds: 60,
capabilities: ["image"], // 可选,用于多模态条目
profile: "vision-profile",
preferredProfile: "vision-fallback",
}
{
type: "cli",
command: "gemini",
args: [
"-m",
"gemini-3-flash",
"--allowed-tools",
"read_file",
"Read the media at {{MediaPath}} and describe it in <= {{MaxChars}} characters.",
],
maxChars: 500,
maxBytes: 52428800,
timeoutSeconds: 120,
capabilities: ["video", "image"],
}
CLI 模板还可以使用:
{{MediaDir}}(包含媒体文件的目录){{OutputDir}}(为本次运行创建的临时目录){{OutputBase}}(临时文件基础路径,不含扩展名)
默认值和限制
推荐的默认值:
maxChars:图片/视频用 500(简短,便于命令解析)maxChars:音频不设置(完整转录,除非你设置限制)maxBytes:- 图片:10MB
- 音频:20MB
- 视频:50MB
规则:
- 如果媒体超过
maxBytes,该模型会被跳过,尝试下一个模型。 - 如果模型返回超过
maxChars的内容,输出会被截断。 prompt默认为简单的 “Describe the {media}.” 加上maxChars指导(仅图片/视频)。- 如果
<capability>.enabled: true但没有配置模型,OpenClaw 会在 Provider 支持该能力时 尝试使用当前活动的回复模型。
自动检测媒体理解(默认)
如果 tools.media.<capability>.enabled 没有设置为 false 且你没有配置模型,
OpenClaw 会按以下顺序自动检测,在第一个可用选项处停止:
- 本地 CLI(仅音频;如果已安装)
sherpa-onnx-offline(需要SHERPA_ONNX_MODEL_DIR包含 encoder/decoder/joiner/tokens)whisper-cli(whisper-cpp;使用WHISPER_CPP_MODEL或内置的 tiny 模型)whisper(Python CLI;自动下载模型)
- Gemini CLI(
gemini)使用read_many_files - Provider 密钥
- 音频:OpenAI → Groq → Deepgram → Google
- 图片:OpenAI → Anthropic → Google → MiniMax
- 视频:Google
要禁用自动检测,设置:
{
tools: {
media: {
audio: {
enabled: false,
},
},
},
}
注意:二进制检测在 macOS/Linux/Windows 上是尽力而为的;确保 CLI 在 PATH 中(我们会展开 ~),或者设置一个带完整命令路径的显式 CLI 模型。
Capabilities(可选)
如果你设置了 capabilities,该条目只会为这些媒体类型运行。对于共享列表,
OpenClaw 可以推断默认值:
openai、anthropic、minimax:imagegoogle(Gemini API):image + audio + videogroq:audiodeepgram:audio
对于 CLI 条目,显式设置 capabilities 以避免意外匹配。
如果省略 capabilities,该条目对它所在的列表都有效。
Provider 支持矩阵(OpenClaw 集成)
| 能力 | Provider 集成 | 说明 |
|---|---|---|
| Image | OpenAI / Anthropic / Google / 其他通过 pi-ai | 注册表中任何支持图片的模型都可用。 |
| Audio | OpenAI、Groq、Deepgram、Google | Provider 转录(Whisper/Deepgram/Gemini)。 |
| Video | Google(Gemini API) | Provider 视频理解。 |
推荐的 Provider
图片
- 如果你的活动模型支持图片,优先使用它。
- 好的默认选择:
openai/gpt-5.2、anthropic/claude-opus-4-5、google/gemini-3-pro-preview。
音频
openai/gpt-4o-mini-transcribe、groq/whisper-large-v3-turbo或deepgram/nova-3。- CLI 备用:
whisper-cli(whisper-cpp)或whisper。 - Deepgram 设置:Deepgram(音频转录)。
视频
google/gemini-3-flash-preview(快速)、google/gemini-3-pro-preview(更丰富)。- CLI 备用:
geminiCLI(支持视频/音频的read_file)。
附件策略
按能力的 attachments 控制处理哪些附件:
mode:first(默认)或allmaxAttachments:限制处理数量(默认 1)prefer:first、last、path、url
当 mode: "all" 时,输出会标记为 [Image 1/2]、[Audio 2/2] 等。
配置示例
1) 共享模型列表 + 覆盖
{
tools: {
media: {
models: [
{ provider: "openai", model: "gpt-5.2", capabilities: ["image"] },
{
provider: "google",
model: "gemini-3-flash-preview",
capabilities: ["image", "audio", "video"],
},
{
type: "cli",
command: "gemini",
args: [
"-m",
"gemini-3-flash",
"--allowed-tools",
"read_file",
"Read the media at {{MediaPath}} and describe it in <= {{MaxChars}} characters.",
],
capabilities: ["image", "video"],
},
],
audio: {
attachments: { mode: "all", maxAttachments: 2 },
},
video: {
maxChars: 500,
},
},
},
}
2) 仅音频 + 视频(关闭图片)
{
tools: {
media: {
audio: {
enabled: true,
models: [
{ provider: "openai", model: "gpt-4o-mini-transcribe" },
{
type: "cli",
command: "whisper",
args: ["--model", "base", "{{MediaPath}}"],
},
],
},
video: {
enabled: true,
maxChars: 500,
models: [
{ provider: "google", model: "gemini-3-flash-preview" },
{
type: "cli",
command: "gemini",
args: [
"-m",
"gemini-3-flash",
"--allowed-tools",
"read_file",
"Read the media at {{MediaPath}} and describe it in <= {{MaxChars}} characters.",
],
},
],
},
},
},
}
3) 可选的图片理解
{
tools: {
media: {
image: {
enabled: true,
maxBytes: 10485760,
maxChars: 500,
models: [
{ provider: "openai", model: "gpt-5.2" },
{ provider: "anthropic", model: "claude-opus-4-5" },
{
type: "cli",
command: "gemini",
args: [
"-m",
"gemini-3-flash",
"--allowed-tools",
"read_file",
"Read the media at {{MediaPath}} and describe it in <= {{MaxChars}} characters.",
],
},
],
},
},
},
}
4) 多模态单条目(显式 capabilities)
{
tools: {
media: {
image: {
models: [
{
provider: "google",
model: "gemini-3-pro-preview",
capabilities: ["image", "video", "audio"],
},
],
},
audio: {
models: [
{
provider: "google",
model: "gemini-3-pro-preview",
capabilities: ["image", "video", "audio"],
},
],
},
video: {
models: [
{
provider: "google",
model: "gemini-3-pro-preview",
capabilities: ["image", "video", "audio"],
},
],
},
},
},
}
状态输出
当媒体理解运行时,/status 会包含一行简短摘要:
📎 Media: image ok (openai/gpt-5.2) · audio skipped (maxBytes)
这会显示每个能力的结果以及选择的 provider/model(如果适用)。
注意事项
- 理解是尽力而为的。错误不会阻止回复。
- 即使禁用理解,附件仍会传递给模型。
- 使用
scope限制理解运行的位置(例如仅 DM)。