ag_ui library

AG-UI Dart SDK - Standardizing agent-user interactions

This library provides strongly-typed Dart models for the AG-UI protocol, enabling agent-user interaction through a standardized event-based system.

Features

  • Core Protocol Support: Full implementation of AG-UI event types
  • HTTP Client: Production-ready client with SSE streaming support
  • Event Streaming: Real-time event processing with backpressure handling
  • Tool Interactions: Support for tool calls with generative UI
  • State Management: Handle snapshots and deltas (JSON Patch RFC 6902)
  • Type Safety: Strongly-typed models for all protocol entities

Getting Started

import 'package:ag_ui/ag_ui.dart';

final client = AgUiClient(
  config: AgUiClientConfig(
    baseUrl: 'http://localhost:8000',
  ),
);

final input = SimpleRunAgentInput(
  messages: [
    UserMessage(
      id: 'msg_1',
      content: 'Hello, world!',
    ),
  ],
);

await for (final event in client.runAgent('agent', input)) {
  print('Event: ${event.type}');
}

Classes

ActivityDeltaEvent
Event containing a JSON Patch (RFC 6902) delta for an activity message
ActivityMessage
Activity message embedded in a MESSAGES_SNAPSHOT payload.
ActivitySnapshotEvent
Event containing a snapshot of an activity message.
AgUiClient
Main client for interacting with AG-UI servers.
AgUiClientConfig
Configuration for AgUiClient.
AGUIModel
Base class for all AG-UI models with JSON serialization support.
AssistantMessage
Assistant message with optional content and tool calls.
AudioInputContent
Audio part of a multimodal message.
BackoffStrategy
Abstract interface for backoff strategies.
BaseEvent
Base event for all AG-UI protocol events.
BinaryInputContent
Legacy binary content part.
CancelToken
Cancel token for request cancellation.
ClientToolResult
ToolResult model for submitting tool execution results to the server.
ConstantBackoff
Simple constant backoff strategy that returns the same delay every time.
Context
Additional context for the agent
CustomEvent
Event containing a custom event
DataSource
Inline content source carrying a data payload (e.g. base64-encoded bytes).
Decoder
Decoder extensions for client operations
DeveloperMessage
Developer message with required content.
DocumentInputContent
Document part of a multimodal message.
Encoder
Encoder extensions for client operations
EventDecoder
Decoder for AG-UI events.
EventEncoder
Encoder for AG-UI events.
EventStreamAdapter
Adapter for converting streams of SSE messages to typed AG-UI events.
ExponentialBackoff
Implements exponential backoff with jitter for reconnection attempts.
FunctionCall
Represents a function call within a tool call.
ImageInputContent
Image part of a multimodal message.
InputContent
A single typed part of a multimodal UserMessage.
InputContentSource
The source of a multimodal InputContent part.
JsonDecoder
Utility for tolerant JSON decoding that ignores unknown fields.
LegacyBackoffStrategy
Legacy class for backward compatibility - maintains state internally
Message
Base message class for all message types.
MessagesSnapshotEvent
Event containing a snapshot of messages
MultimodalContent
Multimodal user message content. Serializes to a JSON List.
RawEvent
Event wrapping a raw, uninterpreted upstream event payload.
ReasoningEncryptedValueEvent
Event containing an encrypted value for a message or tool call.
ReasoningEndEvent
Event indicating the end of a reasoning phase.
ReasoningMessage
Reasoning message emitted by models that expose their chain-of-thought.
ReasoningMessageChunkEvent
Event containing a chunk of reasoning message content.
ReasoningMessageContentEvent
Event containing a piece of reasoning message content.
ReasoningMessageEndEvent
Event indicating the end of a reasoning message.
ReasoningMessageStartEvent
Event indicating the start of a reasoning message.
ReasoningStartEvent
Event indicating the start of a reasoning phase.
Run
Represents a run in the AG-UI protocol
RunAgentInput
Input for running an agent.
RunErrorEvent
Event indicating that a run has encountered an error
RunFinishedEvent
Event indicating that a run has finished
RunStartedEvent
Event indicating that a run has started
SimpleRunAgentInput
Simplified input for running an agent via HTTP endpoint
SseClient
A client for Server-Sent Events (SSE) with automatic reconnection.
SseMessage
Represents a Server-Sent Event message.
StateDeltaEvent
Event containing a delta of the state (JSON Patch RFC 6902)
StateSnapshotEvent
Event containing a snapshot of the state
StepFinishedEvent
Event indicating that a step has finished
StepStartedEvent
Event indicating that a step has started
SystemMessage
System message with required content.
TextContent
Plain-text user message content. Serializes to a JSON String.
TextInputContent
Plain text part of a multimodal message.
TextMessageChunkEvent
Event containing a chunk of text message content
TextMessageContentEvent
Event containing text message content
TextMessageEndEvent
Event indicating the end of a text message
TextMessageStartEvent
Event indicating the start of a text message
ThinkingContentEvent
Event containing thinking content.
ThinkingEndEvent
Event indicating the end of a thinking section
ThinkingStartEvent
Event indicating the start of a thinking section
ThinkingTextMessageContentEvent
Event containing thinking text message content.
ThinkingTextMessageEndEvent
Event indicating the end of a thinking text message.
ThinkingTextMessageStartEvent
Event indicating the start of a thinking text message.
Tool
Represents a tool definition.
ToolCall
Represents a tool call made by the assistant.
ToolCallArgsEvent
Event containing tool call arguments
ToolCallChunkEvent
Event containing a chunk of tool call content
ToolCallEndEvent
Event indicating the end of a tool call
ToolCallResultEvent
Event containing the result of a tool call
ToolCallStartEvent
Event indicating the start of a tool call
ToolMessage
Tool message with tool call result.
ToolResult
Represents the result of a tool call
UrlSource
Remote content source referenced by URL.
UserMessage
User message with text or multimodal content.
UserMessageContent
The content union for a UserMessage: plain text or multimodal parts.
Validators
Validation utilities for AG-UI SDK
VideoInputContent
Video part of a multimodal message.

Enums

EventType
Enumeration of all AG-UI event types
MessageRole
Role types for messages in the AG-UI protocol.
ReasoningEncryptedValueSubtype
Subtype for ReasoningEncryptedValueEvent.
ReasoningMessageRole
Role for reasoning messages (aligned with the AG-UI protocol).
TextMessageRole
Text message roles that can be used in text message events.
ToolCallResultRole
Role for tool-call result messages (aligned with the AG-UI protocol).

Mixins

TypeDiscriminator
Mixin for models with type discriminators.

Constants

aguiMediaType → const String
The AG-UI protobuf media type constant.
agUiVersion → const String
SDK version
kUnsetSentinel → const _CopyWithSentinel
Single shared sentinel instance used across all AG-UI copyWith methods.

Functions

camelToSnake(String camel) String
Converts camelCase to snake_case
initAgUI() → void
Initialize the AG-UI SDK
snakeToCamel(String snake) String
Converts snake_case to camelCase

Exceptions / Errors

AGUIError
Base exception for AG-UI protocol errors.
AgUiError
Base class for runtime / transport / decoding AG-UI errors.
AGUITimeoutError
Error when operation times out.
AGUIValidationError
Represents a validation error during JSON decoding.
CancellationError
Error when operation is cancelled
DecodeError
Error thrown when decoding fails.
DecodingError
Error decoding JSON or event data
EncodeError
Error thrown when encoding fails.
EncoderError
Base error for encoder/decoder operations.
ProtocolViolationError
Error when protocol rules are violated
ServerError
Server-side application error
TransportError
Error during HTTP/SSE transport operations
ValidationError
Error validating input or output data.