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

# AG-UI

> Enable AG-UI event streaming for CopilotKit and other AG-UI-compatible web frontends

The [AG-UI protocol](https://docs.ag-ui.com) is an open standard for streaming agent events to frontend clients. It defines a structured event sequence — run lifecycle, text deltas, tool calls, reasoning content — so any AG-UI-compatible frontend can consume agent output without custom integration code.

This SDK emits every `Stream` call as a properly sequenced AG-UI event stream. Events like `RUN_STARTED`, `TEXT_MESSAGE_CONTENT`, `TOOL_CALL_START`, and `REASONING_MESSAGE_CONTENT` are produced in the correct order during every [`Stream`](/getting-started/streaming) call. Any frontend built on the AG-UI client SDK — including [CopilotKit](https://copilotkit.ai) and custom React clients — works out of the box.

Serialize any event with `event.ToJSON()` and forward it over **SSE, WebSocket, or Redis** to your frontend. The receiving client handles rendering, tool display, and state — your Go server just forwards bytes.

## Basic integration

When using conversation, pass the session ID in `AgentStreamOptions` — the AG-UI client uses it to thread messages correctly across turns:

```go theme={null}
opts := &agent.AgentStreamOptions{
    ConversationOptions: &agent.ConversationOptions{ID: sessionID},
}
agentStream, err := a.Stream(ctx, prompt, opts)
if err != nil {
    return err
}
runID := agentStream.ID()
_ = runID // the RUN_STARTED event also carries runID via its RunID field
eventCh, err := agentStream.Events(ctx)
```

Enable streaming, then forward serialized events to your frontend over SSE, WebSocket, or Redis:

```go theme={null}
a, err := agent.NewAgent(
    agent.WithLLMClient(llmClient),
)

agentStream, err := a.Stream(ctx, prompt, nil)
if err != nil {
    return err
}
runID := agentStream.ID()
_ = runID
eventCh, err := agentStream.Events(ctx)
if err != nil {
    return err
}

for ev := range eventCh {
    if ev == nil {
        continue
    }
    jsonBytes, err := ev.ToJSON()
    if err != nil {
        continue
    }
    // Forward jsonBytes to SSE/WebSocket client
    _ = jsonBytes
}
```

Call `event.ToJSON()` on any [`AgentEvent`](https://pkg.go.dev/github.com/agenticenv/agent-sdk-go/pkg/agent#AgentEvent) to get AG-UI-compatible JSON.

## Reference app

[Agent Chat](/reference-apps/agent-chat) — production-shaped split API/worker app with Postgres, SSE streaming, and CopilotKit UI.

## Example

<CardGroup cols={2}>
  <Card title="AG-UI" icon="play" href="/examples/agui" horizontal>
    Go SSE server + CopilotKit UI
  </Card>
</CardGroup>

## Related

<CardGroup cols={2}>
  <Card title="Streaming" icon="wave-pulse" href="/getting-started/streaming" horizontal>
    Stream API and event types
  </Card>

  <Card title="Approvals" icon="shield-check" href="/features/approvals" horizontal>
    CUSTOM events and AgentStream.Approve
  </Card>
</CardGroup>


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