Fastify
easy5 minfastify-server.ts
Same API, but your service runs on Fastify.
What it shows
- Register
cogitatorPluginwith a prefix
The code
fastify-server.ts
import { Agent, Cogitator, calculator } from '@cogitator-ai/core';
import { cogitatorPlugin } from '@cogitator-ai/fastify';
import Fastify from 'fastify';
const apiKey = process.env.GOOGLE_API_KEY;
if (!apiKey) throw new Error('Set GOOGLE_API_KEY');
const cog = new Cogitator({ llm: { providers: { google: { apiKey } } } });
const assistant = new Agent({
name: 'assistant',
description: 'General assistant with a calculator tool',
model: 'google/gemini-3.5-flash-lite',
instructions: 'You are a helpful assistant. Use tools when appropriate. Be concise.',
tools: [calculator],
temperature: 0.3,
});
const fastify = Fastify({ logger: false });
await fastify.register(cogitatorPlugin, {
cogitator: cog,
agents: { assistant },
prefix: '/cogitator',
enableSwagger: false,
});
await fastify.listen({ port: 3101, host: '0.0.0.0' });
console.log('Listening on http://localhost:3101/cogitator');Run it
install · bash
pnpm add @cogitator-ai/core @cogitator-ai/fastify fastifyEnvironment
GOOGLE_API_KEYrun · bash
GOOGLE_API_KEY=your-key npx tsx fastify-server.tsOr run the full example from a clone of the repository (keys in .env):
repository · bash
npx tsx examples/integrations/02-fastify-server.tsTry it
Try it · bash
curl -X POST http://localhost:3101/cogitator/agents/assistant/run \
-H 'Content-Type: application/json' -d '{"input": "What is 123 * 456?"}'