Skip to content
广告 · 本站推荐广告

输入状态指示

Typing Indicators(输入状态指示)在 Agent 处理消息时向用户显示"正在输入..."提示,改善等待体验。

基本机制

当 Agent 收到消息并开始处理时,OpenClaw 会向对应渠道发送 Typing Indicator(输入状态指示)信号:

用户发送消息


  Agent 开始处理

      ├── 发送 "正在输入..." 信号


  LLM 调用 + 工具执行

      ├── 持续维持输入状态


  回复生成完成

      └── 停止输入状态,发送回复

用户体验

Typing Indicator 让用户知道 Agent 正在处理消息,避免用户以为消息发送失败或 Agent 无响应。

渠道支持

不同渠道对 Typing Indicator 的支持情况:

渠道支持实现方式
WhatsAppsendPresenceUpdate('composing')
TelegramsendChatAction('typing')
Discordchannel.sendTyping()
iMessage原生 Typing Bubble
Web UI自定义动画
Slacktyping WebSocket 事件

配置

yaml
typingIndicator:
  enabled: true              # 启用输入状态指示
  refreshInterval: 5000      # 刷新间隔(毫秒)
  showOnToolExecution: true  # 工具执行时也显示

refreshInterval

某些平台的 Typing Indicator 会在一段时间后自动消失。refreshInterval 配置定期重新发送信号:

yaml
# Telegram 的 typing 状态持续约 5 秒
# 设置 4 秒刷新确保连续显示
typingIndicator:
  refreshInterval: 4000

showOnToolExecution

控制是否在工具执行期间维持输入状态:

yaml
# 工具可能执行较长时间,持续显示 typing 提示用户等待
typingIndicator:
  showOnToolExecution: true

长时间工具调用

当工具执行时间超过 30 秒时,建议在 Web UI 上显示更具体的状态信息(如"正在搜索..."),而非仅显示"正在输入..."。

自定义指示器

Web UI 自定义

Web UI 支持自定义 Typing Indicator 的外观和行为:

yaml
typingIndicator:
  webUI:
    animation: dots          # dots | pulse | spinner
    text: "AI 正在思考..."   # 自定义提示文字
    showToolName: true       # 显示正在执行的工具名称

显示效果示例:

🤔 AI 正在思考...
⚙️ 正在执行: web_search
📝 正在生成回复...

渠道自定义

不同渠道可配置不同的行为:

yaml
overrides:
  telegram:
    typingIndicator:
      refreshInterval: 4000
  whatsapp:
    typingIndicator:
      refreshInterval: 3000
  discord:
    typingIndicator:
      refreshInterval: 8000  # Discord typing 持续 10 秒

状态流转

┌──────────┐     消息到达     ┌──────────────┐
│  Idle    │───────────────▶│   Typing     │
│  空闲    │                 │   正在输入    │
└──────────┘                 └──────┬───────┘
      ▲                            │
      │         回复发送完成        │
      └────────────────────────────┘

在 Agent Loop 的不同阶段,Typing Indicator 的状态:

阶段输入状态说明
消息排队中❌ 不显示尚未开始处理
准备阶段✅ 显示Agent 正在准备上下文
LLM 调用中✅ 显示模型正在生成回复
工具执行中✅/❌ 可配置取决于 showOnToolExecution
流式输出中❌ 不显示用户已看到实时输出
回复发送后❌ 不显示处理完成

性能考虑

API 速率限制

频繁发送 Typing Indicator 可能触发平台 API 的速率限制。refreshInterval 不应设置过低:

  • Telegram: 最低 3000ms
  • Discord: 最低 5000ms
  • WhatsApp: 最低 2000ms

禁用输入状态

某些场景下可能需要禁用 Typing Indicator:

yaml
# 全局禁用
typingIndicator:
  enabled: false

# 仅特定渠道禁用
overrides:
  whatsapp:
    typingIndicator:
      enabled: false

下一步

基于MIT协议开源 | 内容翻译自 官方文档,同步更新