/ src / lib / a2a / agent-card.ts
agent-card.ts
 1  import type { Agent } from '@/types/agent'
 2  import type { AgentCard } from './types'
 3  
 4  const A2A_PROTOCOL_VERSION = '0.3.0'
 5  const SWARMCLAW_VERSION = '1.0.0'
 6  
 7  /**
 8   * Generate an A2A Agent Card from a SwarmClaw agent.
 9   * Ref: https://a2a-protocol.org/v0.3.0/specification/#agent-card
10   */
11  export function generateAgentCard(agent: Agent, baseUrl: string): AgentCard {
12    return {
13      name: agent.name,
14      description: agent.description || `SwarmClaw agent: ${agent.name}`,
15      version: SWARMCLAW_VERSION,
16      protocolVersion: A2A_PROTOCOL_VERSION,
17      apiEndpoint: `${baseUrl}/api/a2a`,
18  
19      capabilities: [
20        {
21          name: 'task_execution',
22          methods: ['executeTask', 'getStatus', 'cancelTask'],
23          description: 'Execute tasks and manage task lifecycle',
24        },
25        {
26          name: 'discovery',
27          methods: ['discoverAgents'],
28          description: 'Discover available A2A agents',
29        },
30        ...(agent.delegationEnabled ? [{
31          name: 'delegation',
32          methods: ['executeTask'],
33          description: 'Delegate work to other agents',
34        }] : []),
35      ],
36  
37      skills: (agent.capabilities ?? []).map(cap => ({
38        name: cap,
39        description: `Agent capability: ${cap}`,
40      })),
41  
42      authMethods: ['api_key'],
43      supportsStreaming: true,
44      supportsAsync: true,
45  
46      rateLimit: {
47        requestsPerMinute: 60,
48        maxConcurrentRequests: 10,
49      },
50  
51      extensions: [{
52        name: 'swarmclaw',
53        version: SWARMCLAW_VERSION,
54      }],
55  
56      tags: [
57        ...(agent.capabilities ?? []),
58        'swarmclaw',
59      ],
60    }
61  }