Skip to content

AGUI Framework

agui-framework

A TypeScript SDK for building AI agent-powered applications. AGUI Framework provides a complete toolkit for creating, orchestrating, and deploying LLM-based agents with multi-provider support, real-time streaming, state management, persistence, and the AG-UI protocol for frontend communication.


Features

  • Agent Runtime -- Central orchestrator for LLM interactions with run/stream/resume execution modes, tool execution, middleware pipeline, and event emission.
  • Multi-LLM Providers -- OpenAI, Anthropic, Ollama, and Fireworks support through a common BaseLLMProvider abstraction.
  • Real-Time Streaming -- AsyncGenerator-based streaming with event callbacks and SSE encoding.
  • Event System -- Publish/subscribe EventBus with history, compaction, and piping.
  • State Management -- Thread-isolated SharedState with versioning, diffing, merging, conflict resolution, and agent-accessible tools.
  • Long-Term Memory -- Optional RDF-based semantic store (Oxigraph) with self-managing remember/recall/forget tools.
  • AG-UI Protocol -- Full SSE-based protocol encoding, validation, and event compaction.
  • MCP Integration -- Connect to any MCP-compatible tool server via stdio or streamable HTTP; tools are auto-discovered and registered.
  • Multi-Agent Patterns -- Delegation, cyclic handoff, capability routing, and directed graph workflows.
  • Middleware Pipeline -- Composable event interception and transformation.
  • Persistence -- Memory, Redis, and Postgres thread stores.
  • HTTP/WebSocket Server -- Express-based AguiServer with REST API, SSE streaming, and WebSocket agent communication.
  • Model Catalog -- 44+ models across 4 providers with pricing, context windows, and capabilities.
  • Cost & Usage Tracking -- Per-run token usage, cost calculation, cumulative thread cost, budget limits.
  • React Hooks -- useStream, useThread, useInterrupts, useCoAgent, useWebSocket, useAgentState, useRunningAgents, useLiveState, useGeneratedUI, and more.
  • :material-wand: Generative User Interfaces -- Agents dynamically generate forms, wizards, and interactive UIs at runtime without custom tool renderers.
  • Type Safety -- Full TypeScript with strict types across all modules.

Quick Start

npm install agui-framework

Requires Node.js 18+.

1. Basic Agent

import { Agent } from "agui-framework";

const agent = new Agent({
  model: "gpt-4o",
  provider: "openai",
  instructions: "You are a helpful assistant.",
});

const response = await agent.run("What is the capital of France?");
console.log(response);

Set OPENAI_API_KEY in your environment.

2. Streaming Response

import { Agent } from "agui-framework";

const agent = new Agent({
  model: "gpt-4o",
  provider: "openai",
  instructions: "Tell a detailed story.",
});

for await (const chunk of agent.stream("Tell me about space exploration")) {
  process.stdout.write(chunk);
}

3. Agent with Tools

import { Agent } from "agui-framework";
import type { ToolConfig } from "agui-framework";

const weatherTool: ToolConfig = {
  name: "get_weather",
  description: "Get current weather for a city",
  parameters: {
    type: "object",
    properties: { city: { type: "string", description: "City name" } },
    required: ["city"],
  },
  handler: async ({ city }) => ({ city, temperature: 22, conditions: "sunny" }),
};

const agent = new Agent({
  model: "gpt-4o",
  provider: "openai",
  instructions: "Use the weather tool when asked about weather.",
  tools: [weatherTool],
});

const response = await agent.run("What is the weather in Paris?");
console.log(response);

Where to Go Next

Section Description
Getting Started Installation, prerequisites, first agent, configuration
Agent Agent class deep dive: config, tools, execution modes
Events EventBus API, event types, subscriptions
State Management SharedState, StateManager, thread isolation
Providers Provider architecture, custom providers
Architecture Module relationships, data flow, extension points
Multi-Agent Patterns Delegation, handoff, graph workflows
Server HTTP/WebSocket server setup and API
Generative UI AI-generated interfaces — forms, wizards, and interactive UIs at runtime
API Reference Complete API reference organized by module