Skip to main content
@fishaudio/agent-react wraps the Web SDK in idiomatic React: a useConversation hook for session control, an optional provider that shares one session across your component tree, and a ready-made audio visualizer. The SDK handles microphone capture, audio playback, and transport internally — you write UI.

Web SDK reference

Every event, method, and error code.

Authentication

Create session tokens on your backend.

Public agents

Connect with just an agent id, no backend.

Install

Quick start

A minimal call UI: start a call, show what the agent is doing, mute, hang up. This example connects to a public agent by id.
App.tsx
status, mode, and isSpeaking are React state — your component re-renders as the conversation progresses. When the component unmounts, the session ends automatically.
Call startSession from a user gesture (such as a click handler) so the browser allows microphone capture and audio playback.

Connect to a private agent

For agents that are not public, your backend creates the session with your API key (POST /v1/agent/sessions) and returns the response to the browser. Pass it to startSession unchanged.
See Authentication for the backend side. startSession accepts the same options as AgentSession.start in the Web SDK, including clientTools. Session settings such as overrides and dynamicVariables apply when you connect with an agentId; with a sessionToken, your backend sets them in its session-creation request instead.

What useConversation returns

sendUserMessage(text) injects a typed turn; the agent’s reply streams back as transcript and audio. Pass { audio: false } to get a text-only reply for that turn — useful for a do-not-disturb typing mode.
For transcripts, tool-call events, and error handling, subscribe to events on session — see the Web SDK event reference.

Share one session across components

Wrap your tree in AgentSessionProvider when several components need the same conversation — call controls in the header, a transcript panel elsewhere.
App.tsx
The provider hosts the conversation, so components inside it read the shared state with useAgentSessionContext() instead of calling useConversation themselves — it returns the same fields, so the quick-start CallButton only needs its hook call swapped.

Audio visualizer

<AgentAudioVisualizer> renders animated canvas bars driven by the agent’s output audio — a drop-in “the agent is talking” indicator. Inside an AgentSessionProvider it picks up the active session automatically; elsewhere, pass a session prop. Optional bars, width, height, and className props control the rendering, and the bars follow the element’s CSS color.
For a custom visualization, build on useAudioLevels or the session’s frequency-data methods from the Web SDK.

Going further

Web SDK

Full event and method reference behind these hooks.

Client tools

Let the agent call functions in your app.

Authentication

Create session tokens server-side for private agents.

Dynamic variables

Personalize each session at start time.