Agent 集成
MessageRouter 与 Agent 的集成包含两种路径:
- Push 模式: 路由规则中配置
agent动作,事件命中后由 MessageRouter 处理。 - Pull 模式: Agent 作为 MCP 客户端连接 MessageRouter 的 MCP 服务器,主动查询事件、创建路由、发送消息或回复事件。
Push: Route Agent Action
Section titled “Push: Route Agent Action”在路由规则中添加 agent 动作:
{ "type": "agent", "config": { "prompt": "为这篇文章生成摘要和标签" }}config.prompt 可选,作为生成摘要和标签时的指令。事件命中该规则后:
- MessageRouter 为事件生成摘要和标签。
- 结果通过 Webhook 订阅推送:
item.summarized(摘要)和item.tagged(标签),订阅方式见 API 文档 的「Webhook 订阅」。 - 执行状态记录在 Dashboard「执行日志」,也可以通过
GET /v1/route-logs查询。
Pull: MCP Tools
Section titled “Pull: MCP Tools”MCP 服务器提供以下主要 tools:
| Tool | 说明 |
|---|---|
query_events |
查询事件列表 |
get_event |
获取事件详情 |
send_message |
通过 ConnectorBind 发送纯文本消息 |
reply_message |
按事件上下文回复入站事件 |
list_routes |
查询路由规则 |
create_route |
创建路由规则 |
list_connectors |
查询可用 Connector 和绑定实例 |
get_route_logs |
查询路由执行日志 |
get_usage |
查询使用量统计 |
send_message 示例:
await mcp.call("send_message", { bind_id: "bind_01JD8", text: "日报已生成"});reply_message 示例:
await mcp.call("reply_message", { event_id: "evt_01JD8", text: "已收到,我会处理。"});MCP 调用支持 API Key 或 OAuth Bearer Token,并按 API Key/OAuth scope 检查 events、messages、routes、connector_binds、audit_logs:r 等权限。发送类工具使用 messages:w scope;get_route_logs 使用 routes:r,get_usage 使用 audit_logs:r;为兼容旧授权,发送类工具也接受 legacy events:w。
收到链接后自动总结
Section titled “收到链接后自动总结”- Connector 接收外部消息并解析为
MessageEvent。 - 事件命中配置了
agent动作的路由规则。 agent动作生成摘要和标签,通过item.summarized、item.taggedWebhook 推送给你的服务。- 同一规则中还可以加一个
notify动作,通过bind_id或webhook_url把这条消息转发到指定渠道。
Agent 主动查询并发送或回复消息
Section titled “Agent 主动查询并发送或回复消息”- Agent 调用
query_events查询今天的链接事件。 - Agent 生成日报。
- Agent 调用
send_message通过指定bind_id发送到目标渠道,或调用reply_message按原事件上下文回复。
- 通过 API Key/OAuth scope 限制 Agent 可访问的资源。
- 对发送类工具使用专用 ConnectorBind,便于审计和限流。