---
title: "AG-UI agents"
description: "Render the text an AG-UI agent streams (LangGraph, CrewAI, Mastra and others) as GistUI."
---

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

# AG-UI agents

[AG-UI](https://docs.ag-ui.com) is an event protocol between agents and frontends. An agent's text arrives as `TEXT_MESSAGE_CONTENT` events. GistUI reads them like any other stream: the program is the text of the message.

## On your server

Give the agent GistUI's system prompt (how depends on the agent framework), then turn its event stream into text:

```ts
import { textDeltas, toReadable } from "@gistui/server";

const res = await fetch(AGENT_URL, { method: "POST", headers, body: JSON.stringify(runInput) });
return new Response(toReadable(textDeltas(res, "agui")));
```

## In a chat

`@gistui/chat` has an adapter that speaks to an AG-UI endpoint directly and keeps the thread id:

```ts
import { agui, createChat } from "@gistui/chat";

const store = createChat({ adapter: agui({ url: "/api/agent" }) });
```

## What goes back to the agent

A button press or form submit in the UI becomes the next user message, marked as coming from the UI. In `@gistui/chat` this is automatic. If you hold the conversation yourself, send `action.message` as the next user turn. See [Actions and forms](/docs/guides/actions-and-forms/).

How GistUI Format maps onto AG-UI events in general is in the [Bindings](/docs/protocol/bindings/) page of the protocol section.

Source: https://gistui.com/docs/models/ag-ui/index.mdx
