Skip to main content

useAgentSession

The useAgentSession hook is the entrypoint for frontend AI runtime access in @wacht/react-router. It exchanges an optional one-time session ticket, then reads the live session state from GET /ai/session. Current return shape:
  • hasSession
  • sessionLoading
  • sessionError
  • sessionId
  • actor
  • agents
  • ticketExchanged
  • ticketLoading
  • refetch()
Important current contract changes:
  • the hook no longer uses /agent/session
  • the session contains a single actor, not an actors[] list
  • there is no contextGroup return field
  • the hook does not expose setActiveAgent; agent selection is handled by the runtime consumer layer
import { useAgentSession } from "@wacht/react-router";

export function AgentBootstrap({ ticket }: { ticket?: string }) {
  const { hasSession, sessionLoading, sessionError, actor, agents } = useAgentSession(ticket);

  if (sessionLoading) return <div>Loading AI session…</div>;
  if (sessionError) return <div>Failed: {sessionError.message}</div>;
  if (!hasSession) return <div>No active AI session.</div>;

  return (
    <div>
      <div>Actor: {actor?.display_name ?? actor?.external_key}</div>
      <div>Agents: {agents.map((agent) => agent.name).join(", ")}</div>
    </div>
  );
}
  • useAgentThreadConversation for live thread messaging and execution state
  • useActorProjects and useProjectThreadFeed for runtime resource browsing
  • useActorMcpServers for actor MCP connection flows