> ## 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

> Build a Go SSE server and connect it to a CopilotKit UI via AG-UI events

Full-stack reference: Go agent server exposes `POST /agui` as SSE with AG-UI JSON events; Next.js + CopilotKit consumes the stream.

Source: [`examples/agent_with_agui/`](https://github.com/agenticenv/agent-sdk-go/tree/main/examples/agent_with_agui)

## What it demonstrates

* Forwarding `ev.ToJSON()` over SSE
* CopilotKit bridge in Next.js (`runtimeUrl="/api/copilotkit"` — the Go URL is set in the Next API route, not directly in React)
* AG-UI event sequence for a real frontend

## Additional requirements

Node.js (LTS) is required for the Next.js UI in terminal 2. The Go server has no extra dependencies.

## Run

From `examples/`:

```bash theme={null}
# Terminal 1 — Go agent server (:8787)
go run ./agent_with_agui/server

# Terminal 2 — Next.js UI
cd agent_with_agui/ui && npm install && npm run dev
```

Open **[http://localhost:3000](http://localhost:3000)**. Health: `GET http://localhost:8787/health`.

Override Go listen port with `PORT=`. Point the UI at another host:

```bash theme={null}
AGENT_URL=http://127.0.0.1:8787/agui npm run dev
```

## Try without the UI

```bash theme={null}
curl -N -X POST http://localhost:8787/agui \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{"prompt":"What is 2+2?"}'
```

You should see `data: {...}` lines (AG-UI-style JSON from `event.ToJSON()`).

Request body accepts `{"prompt":"..."}` or `{"messages":[{"role":"user","content":"..."}]}`.

For a production-shaped split API/worker app with persisted chat history, see [Agent Chat](/reference-apps/agent-chat).

## Learn more

<CardGroup cols={2}>
  <Card title="AG-UI Protocol" icon="diagram-project" href="/features/ag-ui-protocol">
    Event format and integration
  </Card>

  <Card title="Stream" icon="wave-pulse" href="/examples/stream">
    CLI streaming without UI
  </Card>

  <Card title="Agent Chat" icon="comments" href="/reference-apps/agent-chat">
    Full chat app reference
  </Card>
</CardGroup>
