Package:
@hexos/react-corePrimary 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:
- User sends a message via
sendMessage()— added optimistically to messagesAtom - Transport streams the response —
text-deltaevents accumulate in streamingMessageAtom - Tool calls are tracked locally —
tool-call-start/args/result/errorupdate internal trackers - Frontend tools are detected and executed locally via frontendToolsAtom
- Approval requests create entries in pendingToolCallsAtom
- Agent handoffs update activeAgentAtom and handoffHistoryAtom
- 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): UseAgentReturnParameters