Skip to content
Back to skills

Ag Ui

ASecurity

React hook that connects an [AG-UI](https://docs.ag-ui.com) protocol agent endpoint to reachat. Returns the props needed by `<Chat>` plus session helpers, and streams responses via SSE (`text/event-stream`).

  • 4 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 27, 2026
data-aireactapi

Works with

  • api

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add reaviz/skills --skill ag-ui --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ag Ui?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ag Ui
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/reaviz-ag-ui/badge)](https://www.skillsdirectory.com/skills/reaviz-ag-ui)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# useAgUi

React hook that connects an [AG-UI](https://docs.ag-ui.com) protocol agent endpoint to reachat. Returns the props needed by `<Chat>` plus session helpers, and streams responses via SSE (`text/event-stream`).

## Imports

```tsx
import { useAgUi } from 'reachat';
import type {
  AgUiEvent,
  AgUiEventType,
  AgUiMessage,
  AgUiTool,
  AgUiContext,
  AgUiToolCallInfo,
  AgUiRunAgentInput,
  UseAgUiOptions,
  UseAgUiReturn
} from 'reachat';
```

The AG-UI protocol types are bundled with reachat — no separate `@ag-ui/core` install is needed.

## Options

```ts
interface UseAgUiOptions {
  agent: string;                              // Endpoint URL (POST + SSE response)
  initialSessions?: Session[];
  initialActiveSessionId?: string;
  tools?: AgUiTool[];                         // Tools to expose to the agent
  context?: AgUiContext[];                    // Extra context per run
  forwardedProps?: Record<string, unknown>;   // Passthrough props to the agent
  headers?: Record<string, string>;           // Custom request headers
  onToolCall?: (toolCall: AgUiToolCallInfo) => Promise<void> | void;
  onError?: (error: Error) => void;
  onEvent?: (event: AgUiEvent) => void;       // Fires for every parsed event
}
```

## Return value

```ts
interface UseAgUiReturn {
  sessions: Session[];
  activeSessionId: string | undefined;
  isLoading: boolean;
  selectSession: (sessionId: string) => void;
  deleteSession: (sessionId: string) => void;
  createSession: () => void;
  sendMessage: (message: string) => void;
  stopMessage: () => void;
}
```

The shape mirrors the props `<Chat>` expects — pass them through directly.

## Basic usage

```tsx
import { Chat, SessionMessagePanel, SessionMessages, ChatInput, useAgUi } from 'reachat';

function App() {
  const agui = useAgUi({
    agent: 'https://my-agent.example.com/run',
    headers: { Authorization: `Bearer ${token}` },
    onError: err => console.error(err)
  });

  return (
    <Chat
      sessions={agui.sessions}
      activeSessionId={agui.activeSessionId}
      isLoading={agui.isLoading}
      onSelectSession={agui.selectSession}
      onDeleteSession={agui.deleteSession}
      onNewSession={agui.createSession}
      onSendMessage={agui.sendMessage}
      onStopMessage={agui.stopMessage}
    >
      <SessionMessagePanel>
        <SessionMessages />
        <ChatInput />
      </SessionMessagePanel>
    </Chat>
  );
}
```

## Tools and tool calls

Expose tools to the agent and respond when it invokes one:

```tsx
const agui = useAgUi({
  agent: '/api/agent',
  tools: [
    {
      name: 'searchDocs',
      description: 'Search the knowledge base',
      parameters: { query: { type: 'string' } }
    }
  ],
  onToolCall: async toolCall => {
    if (toolCall.toolCallName === 'searchDocs') {
      const args = JSON.parse(toolCall.args);
      const results = await searchKb(args.query);
      // Tool result handling — push back to your agent as needed
      console.log('searchDocs result', results);
    }
  }
});
```

## Streaming behavior

The hook calls `fetch(agent, { method: 'POST', body: JSON.stringify(input) })` and parses the SSE response, dispatching `AgUiEvent`s. It updates the active conversation in-place when `TEXT_MESSAGE_CONTENT` / `TEXT_MESSAGE_CHUNK` deltas arrive, and accumulates `TOOL_CALL_*` events into `AgUiToolCallInfo` before firing `onToolCall` on `TOOL_CALL_END`.

Supported event types include lifecycle (`RUN_STARTED`, `RUN_FINISHED`, `RUN_ERROR`, `STEP_*`), text (`TEXT_MESSAGE_*`), tool calls (`TOOL_CALL_*`), state (`STATE_SNAPSHOT`, `STATE_DELTA`, `MESSAGES_SNAPSHOT`), plus `RAW` and `CUSTOM`.

## Cancellation

`stopMessage()` aborts the in-flight `fetch` via `AbortController`. The hook also auto-aborts on unmount.

## Helpers

These utilities are exported alongside the hook for advanced integrations:

- `addConversationToSession(sessions, sessionId, conversation)` — immutably append
- `updateConversationInSession(sessions, sessionId, conversationId, response)` — patch a conversation's response
- `sessionsToAgUiMessages(session)` — convert reachat history into `AgUiMessage[]`
- `parseSSE(response, signal)` — async generator over `AgUiEvent | Error`
- `parseSSELine(line)` — single-line SSE parser

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.