Deno
easy5 mindeno-server.ts
You want to serve an agent from Deno with only network and environment permissions.
What it shows
- Serve the Hono adapter with
Deno.serve - Shut down cleanly on SIGINT
The code
deno-server.ts
import { Agent, Cogitator, tool } from '@cogitator-ai/core';
import { cogitatorApp } from '@cogitator-ai/hono';
import { Hono } from 'hono';
import { z } from 'zod';
const apiKey = Deno.env.get('GOOGLE_API_KEY');
if (!apiKey) throw new Error('Set GOOGLE_API_KEY');
const calculator = tool({
name: 'calculator',
description: 'Add, subtract, multiply or divide two numbers',
parameters: z.object({ a: z.number(), b: z.number(), op: z.enum(['+', '-', '*', '/']) }),
execute: async ({ a, b, op }) => ({
result: op === '+' ? a + b : op === '-' ? a - b : op === '*' ? a * b : a / b,
}),
});
const assistant = new Agent({
name: 'assistant',
model: 'google/gemini-3.5-flash-lite',
instructions: 'You are a helpful assistant. Use the calculator for arithmetic. Be concise.',
tools: [calculator],
temperature: 0.3,
});
const cog = new Cogitator({ llm: { providers: { google: { apiKey } } } });
const app = new Hono();
app.route('/cogitator', cogitatorApp({ cogitator: cog, agents: { assistant } }));
const server = Deno.serve({ port: Number(Deno.env.get('PORT') ?? 3105) }, app.fetch);
Deno.addSignalListener('SIGINT', async () => {
await server.shutdown();
await cog.close();
Deno.exit(0);
});Run it
install · bash
deno add npm:@cogitator-ai/core npm:@cogitator-ai/hono npm:hono npm:zodEnvironment
GOOGLE_API_KEYrun · bash
GOOGLE_API_KEY=your-key deno run --allow-net --allow-env=GOOGLE_API_KEY,PORT deno-server.tsOr run the full example from a clone of the repository (keys in .env):
repository · bash
deno run --allow-net --allow-env=GOOGLE_API_KEY,PORT examples/integrations/09-deno-server.tsTry it
Try it · bash
curl -X POST http://localhost:3105/cogitator/agents/assistant/run \
-H 'Content-Type: application/json' -d '{"input": "What is 123 * 456?"}'