Package: @hexos/react-core

Primary hook for agent interaction — manages transport, streaming, and state.

Initializes an SSETransport on mount, subscribes to TransportEvents, and translates them into Jotai atom updates. Handles the complete message lifecycle:

  1. User sends a message via sendMessage() — added optimistically to messagesAtom
  2. Transport streams the response — text-delta events accumulate in streamingMessageAtom
  3. Tool calls are tracked locally — tool-call-start/args/result/error update internal trackers
  4. Frontend tools are detected and executed locally via frontendToolsAtom
  5. Approval requests create entries in pendingToolCallsAtom
  6. Agent handoffs update activeAgentAtom and handoffHistoryAtom
  7. On text-complete, the finalized message with all parts is added to messagesAtom

Also provides stop(), reset(), regenerate(), and editMessage() controls.

Related: AgentConfig configures the connection, AgentProvider provides the Jotai scope, ChatWindow typically consumes this hook’s return value.

function useAgent(config: AgentConfig): UseAgentReturn

Parameters

config