👁️ OpenClaw Agent多模态处理

世界上有一种能力叫多模态,它让Agent不再只是"读"文字,而是能"看"图片、"听"声音、"理解"视频...

"帮我看看这张图是什么问题",用户发来一张报错截图。传统Agent傻了,它只能读文字。多模态Agent扫了一眼:"这是内存溢出,建议检查递归调用..."——这就是多模态的魔法。

📋 功能介绍

🎯 支持的模态

模态 支持格式 典型应用
图像 PNG, JPG, GIF, WebP, BMP 图像理解、OCR、图表分析
音频 MP3, WAV, M4A, FLAC 语音转录、音频分析
视频 MP4, MOV, AVI, WebM 视频理解、关键帧提取
文档 PDF, DOCX, XLSX, PPT 文档解析、表格提取

💡 多模态Agent能做什么?

🚀 使用方法

1. 图像处理配置

# 图像理解Agent
agents:
  image-analyzer:
    name: 图像分析师
    
    # 支持图像输入
    multimodal:
      image:
        enabled: true
        max_size: 20MB  # 最大图片大小
        formats: [png, jpg, gif, webp]
        
    # 使用支持视觉的模型
    model: claude-sonnet-4  # 或 gpt-4.5-turbo
    
    prompt: |
      你是一个图像分析专家。
      
      对于用户发送的图片,你可以:
      1. 描述图片内容
      2. 识别文字(OCR)
      3. 分析图表数据
      4. 检测问题(如报错截图)
      
      请根据图片类型提供专业分析。

2. 音频处理配置

# 音频处理Agent
agents:
  audio-processor:
    name: 音频助手
    
    multimodal:
      audio:
        enabled: true
        max_duration: 600s  # 最长10分钟
        
        # 自动转录配置
        transcription:
          enabled: true
          language: zh-CN
          speaker_diarization: true  # 说话人分离
          
    tools:
      - whisper_transcribe
      - audio_analyze
      
    prompt: |
      你可以处理音频文件:
      - 自动转录为文字
      - 分析音频内容
      - 提取关键信息

3. 视频处理配置

# 视频分析Agent
agents:
  video-analyzer:
    name: 视频分析师
    
    multimodal:
      video:
        enabled: true
        max_duration: 300s
        
        # 处理策略
        strategy:
          - keyframe_extraction  # 关键帧提取
          - frame_sampling: 1fps  # 每秒1帧
          - audio_extraction      # 音频分离
          
    tools:
      - extract_frames
      - analyze_frame
      - generate_subtitles

4. 文档处理配置

# 文档解析Agent
agents:
  doc-parser:
    name: 文档解析助手
    
    multimodal:
      document:
        enabled: true
        formats: [pdf, docx, xlsx, pptx]
        
        # PDF处理选项
        pdf:
          extract_images: true  # 提取PDF中的图片
          ocr_enabled: true     # OCR扫描件
          
        # 表格识别
        table_extraction:
          enabled: true
          format: markdown  # 输出格式

✨ 最佳实践

💡 模型选择建议
⚠️ 注意事项
📝 实战案例:报错截图诊断
# 用户发送报错截图
用户: "帮我看看这个错误" [发送图片]

Agent: 
我看到这是一个 Node.js 错误:
```
TypeError: Cannot read property 'id' of undefined
    at UserController.update (controllers/user.js:45)
```

问题分析:
1. 在 user.js 第45行,试图访问 undefined 对象的 id 属性
2. 可能是 req.user 为 undefined,即用户未登录

解决方案:
```javascript
// 添加空值检查
if (!req.user || !req.user.id) {
  return res.status(401).json({ error: '请先登录' });
}
const userId = req.user.id;
```

需要我提供更详细的修复建议吗?

💻 代码示例

图像理解

from openclaw import Agent
from openclaw.multimodal import Image

# 创建多模态Agent
agent = Agent(
    name="image-analyzer",
    model="claude-sonnet-4",
    multimodal=["image"]
)

# 方式1:传入图片路径
result = agent.run(
    "分析这张图表",
    image="./data/sales-chart.png"
)

# 方式2:传入图片URL
result = agent.run(
    "描述这张图片",
    image="https://example.com/photo.jpg"
)

# 方式3:传入base64
import base64
with open("screenshot.png", "rb") as f:
    image_data = base64.b64encode(f.read()).decode()

result = agent.run(
    "这个错误怎么解决?",
    image=f"data:image/png;base64,{image_data}"
)

print(result.content)

音频转录

from openclaw import Agent
from openclaw.multimodal import Audio

agent = Agent(
    name="transcriber",
    multimodal=["audio"]
)

# 转录音频
result = agent.run(
    "转录这段会议录音",
    audio="./meetings/standup.mp3"
)

print(result.transcript)

# 带说话人分离
result = agent.run(
    "转录并区分说话人",
    audio="./meetings/meeting.wav",
    options={"speaker_diarization": True}
)

# 输出格式:
# [00:01:23] 说话人A: 我们来看一下项目进度...
# [00:01:45] 说话人B: 好的,目前...

视频分析

from openclaw import Agent
from openclaw.multimodal import Video

agent = Agent(
    name="video-analyzer",
    multimodal=["video"]
)

# 分析视频
result = agent.run(
    "总结这个视频的主要内容",
    video="./videos/tutorial.mp4",
    
    # 可选:指定处理策略
    options={
        "extract_frames": True,
        "frame_rate": 1,  # 每秒提取1帧
        "transcribe_audio": True
    }
)

print(result.summary)
print(result.keyframes)  # 关键帧列表
print(result.transcript)  # 音频转录

PDF解析

from openclaw import Agent

agent = Agent(
    name="pdf-parser",
    multimodal=["document"]
)

# 解析PDF
result = agent.run(
    "提取这个PDF的表格数据",
    document="./reports/financial.pdf"
)

# 获取提取的表格
tables = result.tables
for table in tables:
    print(table.to_markdown())

# OCR扫描件
result = agent.run(
    "识别这份扫描文档的文字",
    document="./scanned/invoice.pdf",
    options={"ocr": True}
)

混合模态处理

# 同时处理多种模态
agent = Agent(
    name="multimodal-agent",
    multimodal=["image", "audio", "document", "video"]
)

# 综合分析
result = agent.run(
    """请帮我分析这些材料:
    1. 产品截图(图片)
    2. 用户反馈录音(音频)
    3. 产品说明书(PDF)
    """,
    image="./product-screenshot.png",
    audio="./user-feedback.mp3",
    document="./product-manual.pdf"
)

# 综合报告
print(result.report)

🔗 相关链接

📊 多模态模型对比

模型 图像 音频 视频 文档 成本
Claude Sonnet 4 ⭐⭐⭐⭐⭐ - - ⭐⭐⭐⭐ $$
GPT-4.5 Vision ⭐⭐⭐⭐ ⭐⭐⭐ - ⭐⭐⭐⭐ $$$
Gemini Pro ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ $
Whisper - ⭐⭐⭐⭐⭐ - - $