> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentium.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming and replay

> Public streaming and replay signatures and configuration in @agentium/transport 4.0.0.

Import these **11 exports** from `@agentium/transport`. Read the [streaming and replay guide](/transport/ui-stream) for setup and behavior, or return to the [package reference](/api-reference/transport).

A `?` marks an optional field. These are declarations for lookup; run the examples in the linked guide. Follow related-type links for Agentium types and source links for imported dependency types.

## agentUIStream

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/express/ui-stream.ts)

```typescript theme={null}
/**
 * Render an `agent.stream()` source as a Vercel-compatible UI message stream.
 *
 * The returned `ReadableStream<Uint8Array>` can be wrapped in a `Response`
 * (web / edge / fetch) or piped to a Node `ServerResponse`.
 */
export declare function agentUIStream(agent: Agent | AgentLike, input: string, options?: AgentUIStreamOptions): ReadableStream<Uint8Array>;
```

Related: [`Agent`](/api-reference/core/agent#agent), [`AgentUIStreamOptions`](/api-reference/transport/streaming#agentuistreamoptions).

## AgentUIStreamOptions

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/express/ui-stream.ts)

```typescript theme={null}
/**
 * Vercel AI SDK UI Message Stream adapter.
 *
 * Converts the chunks emitted by `agent.stream(...)` into the line-delimited
 * JSON protocol consumed by Vercel's `useChat` / `createAgentUIStreamResponse`.
 *
 * Spec: https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol
 */
export interface AgentUIStreamOptions {
    /** sessionId forwarded to `agent.run` / `agent.stream`. */
    sessionId?: string;
    /** userId forwarded to `agent.run` / `agent.stream`. */
    userId?: string;
    /** Optional per-request API key override. */
    apiKey?: string;
    /** Optional abort signal to cancel the run. */
    signal?: AbortSignal;
}
```

## createAgentUIStreamResponse

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/express/ui-stream.ts)

````typescript theme={null}
/**
 * Create a `Response` whose body streams Vercel UI messages. Use as the return
 * value of a Web / Edge / Next.js Route Handler.
 *
 * @example
 * ```ts
 * import { createAgentUIStreamResponse } from "@agentium/transport";
 *
 * export async function POST(req: Request) {
 *   const { input, sessionId } = await req.json();
 *   return createAgentUIStreamResponse(agent, input, { sessionId });
 * }
 * ```
 */
export declare function createAgentUIStreamResponse(agent: Agent | AgentLike, input: string, options?: AgentUIStreamOptions): Response;
````

Related: [`Agent`](/api-reference/core/agent#agent), [`AgentUIStreamOptions`](/api-reference/transport/streaming#agentuistreamoptions).

## defaultEventLog

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/sse-event-log.ts)

```typescript theme={null}
export declare const defaultEventLog: InMemoryEventLog;
```

Related: [`InMemoryEventLog`](/api-reference/transport/streaming#inmemoryeventlog).

## formatSSEEvent

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/sse-event-log.ts)

```typescript theme={null}
/** Format an `SSEEvent` for the wire. */
export declare function formatSSEEvent(ev: SSEEvent): string;
```

Related: [`SSEEvent`](/api-reference/transport/streaming#sseevent).

## InMemoryEventLog

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/sse-event-log.ts)

```typescript theme={null}
export declare class InMemoryEventLog implements SSEEventLog {
    constructor(config?: InMemoryEventLogConfig);
    record(runId: string, event: Omit<SSEEvent, "id" | "recordedAt">): SSEEvent;
    since(runId: string, afterId: number): SSEEvent[];
    all(runId: string): SSEEvent[];
    finalize(runId: string): void;
    drop(runId: string): void;
}
```

Related: [`InMemoryEventLogConfig`](/api-reference/transport/streaming#inmemoryeventlogconfig), [`SSEEvent`](/api-reference/transport/streaming#sseevent), [`SSEEventLog`](/api-reference/transport/streaming#sseeventlog).

## InMemoryEventLogConfig

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/sse-event-log.ts)

```typescript theme={null}
export interface InMemoryEventLogConfig {
    /** Max events kept per run. Oldest evicted when exceeded. Default: 1024. */
    maxEventsPerRun?: number;
    /** Milliseconds after finalize before a run's buffer is dropped. Default: 300_000 (5min). */
    ttlMs?: number;
}
```

## pipeAgentUIStreamToResponse

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/express/ui-stream.ts)

```typescript theme={null}
/**
 * Pipe a Vercel UI message stream into a Node `ServerResponse` (Express style).
 */
export declare function pipeAgentUIStreamToResponse(agent: Agent | AgentLike, input: string, res: any, options?: AgentUIStreamOptions): Promise<void>;
```

Related: [`Agent`](/api-reference/core/agent#agent), [`AgentUIStreamOptions`](/api-reference/transport/streaming#agentuistreamoptions).

## SSEEvent

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/sse-event-log.ts)

```typescript theme={null}
/**
 * Per-run in-memory ring buffer of SSE events. Each event gets a monotonically
 * increasing numeric `id` so clients can pass `Last-Event-ID` on reconnect and
 * replay missed events.
 *
 * Storage is intentionally in-process; for multi-instance deployments, plug a
 * Redis-backed implementation behind the same interface.
 */
export interface SSEEvent {
    /** Monotonic numeric ID. */
    id: number;
    /** Optional `event:` line value. Default omitted. */
    event?: string;
    /** Payload (will be JSON-stringified into the `data:` field). */
    payload: unknown;
    /** Wall-clock time the event was recorded. */
    recordedAt: number;
}
```

## SSEEventLog

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/sse-event-log.ts)

```typescript theme={null}
export interface SSEEventLog {
    /** Record a new event and return its assigned id. */
    record(runId: string, event: Omit<SSEEvent, "id" | "recordedAt">): SSEEvent;
    /** Return events for a run with id greater than `afterId`. */
    since(runId: string, afterId: number): SSEEvent[];
    /** All events for a run. */
    all(runId: string): SSEEvent[];
    /** Mark a run completed (frees buffers after `ttlMs`). */
    finalize(runId: string): void;
    /** Remove a run's buffer immediately. */
    drop(runId: string): void;
}
```

Related: [`SSEEvent`](/api-reference/transport/streaming#sseevent).

## TextStreamLimits

[Source](https://github.com/agentiumOS/agentium/blob/v4.0.0/packages/transport/src/text-stream.ts)

```typescript theme={null}
export interface TextStreamLimits {
    /** Maximum encoded frame and queued response bytes. Default 256 KiB each. */
    maxFrameBytes?: number;
    maxBufferedBytes?: number;
    /** Maximum wait for a writable drain. Default 10 seconds. */
    writeTimeoutMs?: number;
}
```

## Supporting types

These local shapes appear in public signatures but are not named exports of this entrypoint.

### AgentLike

```typescript theme={null}
interface AgentLike {
    stream(input: string, opts?: {
        sessionId?: string;
        userId?: string;
        apiKey?: string;
        signal?: AbortSignal;
    }): AsyncIterable<AgentLikeChunk>;
}
```

### AgentLikeChunk

```typescript theme={null}
interface AgentLikeChunk {
    type?: string;
    text?: string;
    delta?: string;
    toolCallId?: string;
    toolName?: string;
    arguments?: unknown;
    args?: unknown;
    input?: unknown;
    output?: unknown;
    result?: unknown;
    finishReason?: string;
    usage?: {
        promptTokens?: number;
        completionTokens?: number;
        totalTokens?: number;
    };
    error?: string | {
        message?: string;
    };
    reasoning?: string;
    thinking?: string;
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.