v2 phase 4+5: Discord via Chat SDK, expanded MCP tools, message seq IDs
- Chat SDK bridge + Discord adapter (gateway listener, message routing) - MCP tools refactored into modular structure: core (send_message, send_file, edit_message, add_reaction), scheduling (schedule/list/cancel/pause/resume tasks), interactive (ask_user_question, send_card), agents (send_to_agent) - Message seq IDs: shared integer sequence across messages_in/out so agents see small numeric IDs instead of platform snowflakes - busy_timeout=5000 for session DB (poll loop + MCP server concurrent access) - Always copy agent-runner source to fix stale cache when non-index files change - Seed script for Discord testing, e2e test script Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
58
container/agent-runner/src/mcp-tools/agents.ts
Normal file
58
container/agent-runner/src/mcp-tools/agents.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Agent-to-agent MCP tools: send_to_agent.
|
||||
*/
|
||||
import { writeMessageOut } from '../db/messages-out.js';
|
||||
import type { McpToolDefinition } from './types.js';
|
||||
|
||||
function log(msg: string): void {
|
||||
console.error(`[mcp-tools] ${msg}`);
|
||||
}
|
||||
|
||||
function generateId(): string {
|
||||
return `msg-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
|
||||
function ok(text: string) {
|
||||
return { content: [{ type: 'text' as const, text }] };
|
||||
}
|
||||
|
||||
function err(text: string) {
|
||||
return { content: [{ type: 'text' as const, text: `Error: ${text}` }], isError: true };
|
||||
}
|
||||
|
||||
export const sendToAgent: McpToolDefinition = {
|
||||
tool: {
|
||||
name: 'send_to_agent',
|
||||
description: 'Send a message to another agent group.',
|
||||
inputSchema: {
|
||||
type: 'object' as const,
|
||||
properties: {
|
||||
agentGroupId: { type: 'string', description: 'Target agent group ID' },
|
||||
text: { type: 'string', description: 'Message content' },
|
||||
sessionId: { type: 'string', description: 'Target specific session (optional)' },
|
||||
},
|
||||
required: ['agentGroupId', 'text'],
|
||||
},
|
||||
},
|
||||
async handler(args) {
|
||||
const agentGroupId = args.agentGroupId as string;
|
||||
const text = args.text as string;
|
||||
if (!agentGroupId || !text) return err('agentGroupId and text are required');
|
||||
|
||||
const id = generateId();
|
||||
|
||||
writeMessageOut({
|
||||
id,
|
||||
kind: 'chat',
|
||||
channel_type: 'agent',
|
||||
platform_id: agentGroupId,
|
||||
thread_id: (args.sessionId as string) || null,
|
||||
content: JSON.stringify({ text }),
|
||||
});
|
||||
|
||||
log(`send_to_agent: ${id} → ${agentGroupId}`);
|
||||
return ok(`Message sent to agent ${agentGroupId} (id: ${id})`);
|
||||
},
|
||||
};
|
||||
|
||||
export const agentTools: McpToolDefinition[] = [sendToAgent];
|
||||
Reference in New Issue
Block a user