11.17 Agent发送

Agent Send 允许你从命令行运行单个代理回合,而无需通过聊天频道进行。

概述

openclaw agent 命令用于在无入站聊天的情况下运行单个代理回合。

  • 默认: 通过Gateway运行
  • --local: 强制使用嵌入式本地运行时

基本用法

# 发送消息到指定电话号码
openclaw agent --to +15555550123 --message "status update"

# 发送消息到指定代理
openclaw agent --agent ops --message "Summarize logs"

# 使用会话ID发送消息
openclaw agent --session-id 1234 --message "Summarize inbox" --thinking medium

参数说明

必需参数

  • --message <text>: 要发送的消息内容

会话选择(三选一)

  • --to: 指定目标联系人
  • --session-id: 使用现有会话ID
  • --agent: 指定代理名称

可选参数

  • --local: 强制使用本地运行时(跳过Gateway)
  • --deliver: 将响应投递到频道
  • --channel: 投递频道(配合--deliver使用)
  • --reply-to: 回复的消息ID
  • --reply-channel: 回复消息所在的频道
  • --reply-account: 回复消息所在的账户
  • --thinking: 思考级别(off/minimal/low/medium/high/xhigh)
  • --verbose: 详细输出
  • --timeout: 超时时间
  • --json: 以JSON格式输出结果

输出格式

默认情况下,命令输出文本响应。使用 --json 参数可以获得结构化的JSON输出:

openclaw agent --agent main --message "Hello" --json

投递响应

使用 --deliver 参数可以将代理响应投递到指定频道:

openclaw agent --agent main --message "Send update" \
  --deliver --channel discord --reply-to 12345

使用场景

  • 自动化脚本: 在CI/CD流程中触发代理任务
  • 定时任务: 通过cron定期执行代理命令
  • 测试调试: 快速测试代理响应而无需完整的聊天流程
  • 批处理: 批量发送消息到不同会话
提示
Agent Send 是一个强大的命令行工具,可以将OpenClaw集成到各种自动化工作流中。