SuperAPI AI 工具集

agent-send

智能体与模型

查看项目

更新于 10-16 04:38

技能介绍

用途

agent-send 是一个技能(Skill),用于向在通信渠道(Discord、Telegram、Slack)中运行的 AI 智能体直接发送消息,从而实现对话式任务委派和多智能体协作。

适用与不适用场景

适用场景:

  • 将任务委派给基于渠道的智能体
  • 多智能体对话
  • 智能体之间的通信
  • 协作工作流

不适用场景:

  • 直接 API 调用(应使用 http-request)
  • 进程内函数调用(应使用 delegate-task)
  • 广播消息(应使用 notify 类技能)

支持的平台

平台 格式 回复支持
Discord 私信或频道提及 支持
Telegram 私信或群组 支持
Slack 私信或频道 支持
Email SMTP 中继 支持

使用方式

Discord

const { sendToAgent } = require('/job/.pi/skills/agent-send/sender.js');

// 发送给指定智能体
const result = await sendToAgent('discord', {
  agentId: 'research-bot',
  message: 'Research the latest developments in LLMs',
  channelId: '123456789',
  threadId: null, // 可选
  mentionAgent: true
});

console.log(result.messageId);
console.log(result.agentResponse); // 若启用等待

Telegram

await sendToAgent('telegram', {
  agentId: 'assistant',
  message: 'Summarize this article: https://...',
  chatId: '-100123456789',
  parseMode: 'Markdown'
});

Slack

await sendToAgent('slack', {
  agentId: 'coding-assistant',
  message: 'Review this PR: #123',
  channelId: 'C123ABC',
  threadTs: '1234567.89' // 可选
});

使用会话线程

// 开始会话
const conversation = await sendToAgent('discord', {
  agentId: 'helper',
  message: 'Help me debug this issue',
  startThread: true
});

// 在线程中继续
await sendToAgent('discord', {
  agentId: 'helper',
  message: 'Here is the error log...',
  threadId: conversation.threadId
});

带附件

await sendToAgent('discord', {
  agentId: 'analyst',
  message: 'Analyze this data',
  channelId: '123456789',
  attachments: [
    { 
      name: 'data.csv', 
      data: Buffer.from('col1,col2\na,b'),
      contentType: 'text/csv'
    }
  ]
});

等待回复

const { sendToAgentAndWait } = require('/job/.pi/skills/agent-send/sender.js');

const response = await sendToAgentAndWait('telegram', {
  agentId: 'assistant',
  message: 'What is 2 + 2?',
  chatId: '-100123456789',
  timeoutMs: 60000
});

console.log(response.agentMessage);
console.log(response.timestamp);

API

sendToAgent(platform, options)

选项:

  • platform - discord|telegram|slack|email
  • agentId - 目标智能体标识
  • message - 消息内容(必填)
  • channelId / chatId - 目标频道
  • threadId / threadTs - 线程标识
  • mentionAgent - @提及该智能体
  • attachments - 文件附件数组
  • parseMode - html|markdown(Telegram)
  • timeoutMs - 等待回复的超时时间
  • waitForResponse - 启用等待回复

返回值:

{
  success: true,
  platform: 'discord',
  messageId: '123456789',
  channelId: 'ch_abc',
  threadId: 'th_xyz',
  agentResponse: 'I found 5 relevant papers...',
  responseTime: 3420
}

消息格式化

Discord

// Markdown
await sendToAgent('discord', {
  agentId: 'bot',
  message: '```python\nprint("Hello")```'
});

// Embed(富文本格式)
await sendToAgent('discord', {
  agentId: 'bot',
  message: 'Task request',
  embed: {
    title: 'Research Task',
    description: 'Investigate X...',
    color: 0x00AAFF,
    fields: [
      { name: 'Priority', value: 'High' },
      { name: 'Deadline', value: 'EOD' }
    ]
  }
});

Telegram

// HTML
await sendToAgent('telegram', {
  agentId: 'bot',
  message: '<b>Important</b> task',
  parseMode: 'HTML'
});

// Markdown
await sendToAgent('telegram', {
  agentId: 'bot',
  message: '*Bold* and _italic_',
  parseMode: 'Markdown'
});

Slack

// Blocks
await sendToAgent('slack', {
  agentId: 'bot',
  message: 'Task request',
  blocks: [
    {
      type: 'section',
      text: { type: 'mrkdwn', text: '*Research Task*\nInvestigate X...' }
    },
    {
      type: 'divider'
    },
    {
      type: 'context',
      elements: [{ type: 'mrkdwn', text: 'Priority: High' }]
    }
  ]
});

智能体发现

const { listAgents } = require('/job/.pi/skills/agent-send/sender.js');

const agents = await listAgents('discord');
console.log(agents);
// [
//   { id: 'research-bot', name: 'Research Bot', capabilities: ['search', 'summarize'] },
//   { id: 'coding-assistant', name: 'Code Helper', capabilities: ['code', 'review'] }
// ]

多智能体工作流

async function collaborativeTask(task) {
  // 1. 研究
  const research = await sendToAgentAndWait('discord', {
    agentId: 'research-bot',
    message: `Research: ${task}`,
    timeoutMs: 120000
  });

  // 2. 代码审查
  const codeReview = await sendToAgentAndWait('discord', {
    agentId: 'coding-assistant',
    message: `Review code based on: ${research.agentResponse}`,
    timeoutMs: 60000
  });

  // 3. 总结
  const summary = await sendToAgentAndWait('discord', {
    agentId: 'summarizer',
    message: `Summarize findings:\n${codeReview.agentResponse}`,
    timeoutMs: 30000
  });

  return summary.agentResponse;
}

错误处理

try {
  await sendToAgent('discord', {
    agentId: 'unknown-bot',
    message: 'Hello'
  });
} catch (error) {
  if (error.code === 'AGENT_NOT_FOUND') {
    console.log('Agent not available');
  } else if (error.code === 'TIMEOUT') {
    console.log('Agent response timeout');
  } else if (error.code === 'PERMISSION_DENIED') {
    console.log('Bot lacks permissions in channel');
  }
}

Bash CLI

# 发送消息
node /job/.pi/skills/agent-send/sender.js \
  --platform discord \
  --agent research-bot \
  --channel 123456789 \
  --message "Research topic X"

# 带附件
node /job/.pi/skills/agent-send/sender.js \
  --platform telegram \
  --agent assistant \
  --chat-id -100123456789 \
  --message "Analyze this" \
  --attachment data.csv

限制

资料中未提供关于收费、价格、平台限制、性能指标或具体使用步骤的更多信息。