Skip to content

Agent Server

Cognipeer Agent Server ​

REST API infrastructure for AI agents. Register an agent once and get conversations, storage, authentication, streaming, human approvals, files, budgets and interactive API docs, without writing that plumbing yourself.

  • Package @cognipeer/agent-server 0.3.0
  • Storage PostgreSQL · MongoDB · SQLite · memory
  • Frameworks Express · Next.js · Fastify · Node http · custom adapters
  • Node 18 or newer

Register agents built with @cognipeer/agent-sdk directly, serve your own backend as a host-backed agent, bring an agent from any other library through a simple handler, or point the server at an OpenAI-compatible endpoint. Whichever you choose, you get the same REST surface: conversations, messages, files, approvals and streaming, backed by a storage provider that migrates itself.

typescript
import express from 'express';
import {
  createAgentServer,
  createPostgresProvider,
  createExpressMiddleware,
} from '@cognipeer/agent-server';
import { createSmartAgent } from '@cognipeer/agent-sdk';

const storage = createPostgresProvider({
  connectionString: 'postgresql://user:pass@localhost:5432/mydb',
});

const agentServer = createAgentServer({
  basePath: '/api/agents',
  storage,
  allowAnonymousList: true, // a quick start with no sign-in: see "Who may list" in Request Context
  swagger: { enabled: true, path: '/docs', title: 'My Agent API' },
});

const myAgent = createSmartAgent({ name: 'Assistant', model: myLLMModel, tools: [...] });
agentServer.registerSDKAgent('assistant', myAgent, { description: 'A helpful assistant' });

const app = express();
app.use(express.json());
await storage.connect();
app.use(createExpressMiddleware(agentServer));
app.listen(3000);

What's new in 0.3.0 ​

  • Human in the loop. An agent can pause for a tool approval, a question or a tool that runs in the embedding page; the server stores the pause, expires it, checks who may answer, validates edited arguments and records how each request ended. Approvals & Questions
  • Runs that outlive the connection. A turn is independent of the request that started it: closing the tab no longer stops it, POST /conversations/:id/cancel does, one turn runs at a time per conversation across server instances, and an event log plus a reattach stream bring a client back where it was. Runs, Cancel & Reattach
  • Files the agent reads. Documents inline or in pages, images by reference, raw uploads, ownership, per-conversation limits and retention. Files
  • Usage and budgets. Per-turn usage and cost, a spend limit per conversation, and a continue route. Usage & Budgets
  • Host-backed agents. registerHostAgent serves an agent whose work runs in your backend: it streams, pauses and is cancelled like any other. Host-backed agents
  • Chat experience. Regenerate, edit and resend, pin, rename, bulk delete, generated titles, starters, feedback with reasons and export. Chat experience
  • Embeddable. Per-request bearer auth, client tools, rateLimit and audit hooks. Embedding & limits
  • Storage held to one contract. Memory, SQLite, PostgreSQL and MongoDB pass one suite against real databases; GridFS for MongoDB files; a durable event log and leases. Storage Providers
  • Safer defaults. Listing needs a user, JWT signatures are verified, files belong to their uploader and expire. Upgrading to 0.3.0

What it gives you ​

Agent SDK integration

Register agents created with @cognipeer/agent-sdk directly and expose them as REST APIs, with approvals, questions and files.

Your own backend as an agent

A host-backed agent streams, reports tool calls, pauses for approvals and is cancelled through a signal, while the work stays where it is.

Custom handler support

Integrate agents from any library with a simple handler interface, or point the server at a Chat Completions or Responses endpoint.

Durable runs

Turns outlive the connection, are stored when they finish, can be cancelled, and are recovered if the server dies.

Multiple storage backends

PostgreSQL, MongoDB, SQLite and in-memory providers with automatic schema upgrades, tested against one contract.

Authentication and identity

Token and JWT providers, or your own identity per request; conversations belong to their user.

SSE streaming

Real-time responses with Server-Sent Events, and a cursor to resume from.

Swagger UI

OpenAPI documentation of every route, with interactive Swagger UI.

Files

Upload, download, ownership and retention built in; the agent reads what people attach.

Budgets

Prices in, a cost per turn and a spend limit per conversation out.

Chat experience

Everything a chat product needs around a conversation, for every agent kind.

Framework agnostic

Express, Next.js, Fastify and plain Node, or your own adapter.

The REST surface ​

MethodEndpointDescription
GET/agents, /agents/:agentIdList agents; get an agent with its capabilities
GET / POST/conversationsList / create conversations
GET / PATCH / DELETE/conversations/:idGet (a page of messages, runtime, pending actions), rename / pin / set the budget, delete
POST/conversations/bulk-deleteDelete several conversations
GET / POST/conversations/:id/messagesList or send messages (JSON or SSE)
POST/conversations/:id/messages/:messageId/{regenerate,edit,feedback}Run the newest answer again, edit and resend, rate an answer
POST/conversations/:id/actions/:actionIdAnswer a pending approval, question or client tool
POST/conversations/:id/{cancel,continue}Stop the running turn; carry on a turn the budget stopped
GET/conversations/:id/events, .../events/streamThe event log, replayed and followed
GET/conversations/:id/exportDownload as Markdown, JSON, HTML or PDF
GET / DELETE/conversations/:id/remembered-tools[/:tool]List and forget tools the person chose not to be asked about again
POST / GET/files, /conversations/:id/filesUpload a file; list a conversation's files
GET / DELETE/files/:fileId, /files/:fileId/contentFile metadata, download, delete
POST / GET/tasks, /tasks/:taskId[/status|/result|/cancel|/comments]Background tasks

See REST Endpoints for the complete reference with request and response examples.

Where to go next ​

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub