Skip to main content

@ag-kit/server

Lightweight HTTP/Express adapters for serving AG‑Kit agents. This package exposes a small, typed surface:
  • create and run an Express server with agent routes
  • mount routes on an existing Express app
  • expose a single agent handler as a Fetch-compatible function
All responses stream over Server‑Sent Events (SSE).

Installation

npm install @ag-kit/server

What you get

  • Express helpers: run, createExpressServer, createExpressRoutes
  • HTTP adapter: agui.sendMessage.createServerAdapter
  • Health endpoint: agui.healthz.serverAdapter

Quick start

import { run } from '@ag-kit/server';

run({ agent: () => ({ agent: myAgent }) });

Endpoints

When using Express helpers:
  • POST /send-message — accepts a JSON SendMessageInput and streams events as SSE
  • GET /healthz — returns OK

Request and events

Request body schema (validated via Zod):
type SendMessageInput = {
  conversationId: string;
  messages?: Array<
    | { role: 'system'; content: string }
    | { role: 'user'; content: string }
    | { role: 'tool'; content: string; toolCallId: string }
    | {
        role: 'assistant';
        content?: string;
        toolCalls?: Array<{
          id: string;
          type: 'function';
          function: { name: string; arguments: string };
        }>;
      }
  >;
  resume?: { interruptId: string; payload: unknown };
  tools?: Array<{ name: string; description: string; parameters: any }>;
};
SSE event payloads:
type SendMessageEvent =
  | { type: 'text'; content: string }
  | { type: 'tool-call-start'; toolCallId: string; toolCallName: string }
  | { type: 'tool-call-args'; toolCallId: string; delta: string }
  | { type: 'tool-call-end'; toolCallId: string }
  | { type: 'tool-result'; toolCallId: string; result: string }
  | { type: 'interrupt'; id: string; reason: string; payload: unknown };
See the detailed API and Events pages for full reference.

Next steps