A2A Server
medium10 mina2a-server.ts
Other teams’ agents should discover and call your agent through the Agent-to-Agent protocol.
What it shows
- Wrap agents in
A2AServerand mount it on Express witha2aExpress() - Publish the agent card
The code
a2a-server.ts
import { A2AServer } from '@cogitator-ai/a2a';
import { a2aExpress } from '@cogitator-ai/a2a/express';
import { Agent, Cogitator } from '@cogitator-ai/core';
import express from 'express';
const apiKey = process.env.GOOGLE_API_KEY;
if (!apiKey) throw new Error('Set GOOGLE_API_KEY');
const PORT = 3100;
const writingAssistant = new Agent({
name: 'writing-assistant',
description: 'Improves text, suggests edits and answers questions about writing.',
model: 'google/gemini-3.5-flash-lite',
instructions: 'You are a professional writing assistant. Keep responses concise and actionable.',
temperature: 0.5,
maxIterations: 3,
});
const a2a = new A2AServer({
agents: { 'writing-assistant': writingAssistant },
cogitator: new Cogitator({ llm: { providers: { google: { apiKey } } } }),
cardUrl: `http://localhost:${PORT}`,
});
const app = express();
app.use(a2aExpress(a2a));
app.listen(PORT, () => {
console.log(JSON.stringify(a2a.getAgentCard(), null, 2));
console.log(`Agent card: http://localhost:${PORT}/.well-known/agent.json`);
console.log(`RPC endpoint: http://localhost:${PORT}/a2a`);
});Run it
install · bash
pnpm add @cogitator-ai/a2a @cogitator-ai/core expressEnvironment
GOOGLE_API_KEYrun · bash
GOOGLE_API_KEY=your-key npx tsx a2a-server.tsOr run the full example from a clone of the repository (keys in .env):
repository · bash
npx tsx examples/a2a/01-a2a-server.tsTry it
Try it · bash
curl http://localhost:3100/.well-known/agent.json