Skip to main content
Clients

React SDK

Build a chat UI for an agent with React.

Build a chat UI for an agent with @rivetkit/react. The agent logic lives in one hook, and the UI in one component.

Chat.tsxuseAgentChatAgent Actorstateprompt, abortevents
  • useActor connects to the agent by name and key. Once the connection opens, the hook loads the conversation with getMessages.
  • message_update streams the reply as text deltas, and message_end adds each finished message, including your own prompt. See Session Lifecycle for every event.
  • agent_settled marks the agent idle once it has finished, after any retry. Chat switches its button from Send to Stop while the agent works.

Next steps

  • To steer a run in progress, see Session Lifecycle. To handle errors, see Client SDK.
  • To send a login token, add params to useActor.
  • To switch models from the UI, call setModel on the connection with one of the agent’s scopedModels.

See React in the Actors docs for everything @rivetkit/react can do.