AI SDK

Enterprise-grade AI SDK for Go

The AI SDK is a standalone Go library for building production AI applications. It provides type-safe text generation, structured output via generics, agent orchestration, multi-tier memory, RAG pipelines, workflow engines, and native safety guardrails -- all built for Go's concurrency model with zero external dependencies for core features.

Installation

go get github.com/xraph/ai-sdk

Key Features

  • Type-safe generics -- structured output with compile-time type checking
  • Multiple LLM providers -- OpenAI, Anthropic, Ollama, Azure, HuggingFace, LM Studio
  • Agent patterns -- ReAct (Reasoning + Acting) and Plan-Execute agents
  • Multi-tier memory -- working, short-term, long-term, and episodic memory with automatic consolidation
  • RAG pipeline -- document chunking, embedding, semantic search, and reranking
  • Workflow engine -- DAG-based orchestration with parallel execution
  • Tool system -- auto-discovery from Go functions with JSON schema validation
  • Native guardrails -- zero-cost PII detection, toxicity filtering, and prompt injection prevention
  • Cost management -- budget tracking, usage analytics, and optimization recommendations
  • Resilience -- circuit breakers, retries with exponential backoff, and rate limiting
  • Streaming -- real-time token streaming with thinking/reasoning extraction
  • MCP support -- Model Context Protocol client and server
  • 17+ integrations -- pgvector, Qdrant, Pinecone, Redis, PostgreSQL, and more

Documentation

Quick Start

Install the SDK, configure a provider, and run your first generation in minutes.

Text Generation

Fluent builder API for text generation with prompt templates and callbacks.

Structured Output

Generate typed Go structs from LLM responses with automatic JSON schema validation.

Streaming

Real-time token streaming with reasoning extraction and UI component generation.

Providers

LLM provider interface, built-in providers, and manager configuration.

Agents

Stateful agents with tool integration, state persistence, and multi-agent orchestration.

ReAct Agent

Reasoning and Acting agent pattern with reflection and confidence tracking.

Plan-Execute Agent

Plan-then-execute agent with verification and replanning.

Tools

Tool registry with auto-discovery from Go functions and JSON schema validation.

Memory

Multi-tier memory system with automatic consolidation and semantic recall.

RAG

Retrieval-Augmented Generation with chunking, embeddings, and reranking.

Workflows

DAG-based workflow engine with parallel execution and conditional branching.

Guardrails

Native PII detection, toxicity filtering, and prompt injection prevention.

Cost Management

Usage tracking, budget enforcement, and optimization recommendations.

Resilience

Circuit breakers, retry policies, and rate limiting.

Observability

Distributed tracing, structured logging, and metrics collection.

Integrations

Vector stores, state stores, caches, and embedding providers.

MCP

Model Context Protocol client and server for external data and tools.

Forge Integration

Using the AI SDK inside a Forge application via the AI extension.

How is this guide?

On this page