- Home — the user types a task, the app creates a session and sends the task.
- Session — the app polls for messages and lets the user send follow-ups.
src/lib/api.ts.
Setup: SDK Clients
The app uses both SDK versions — v3 for the agent session API and v2 for profiles (which are not on v3 yet).api.ts
Section 1: Home Page — Creating a Session
API layer
Two functions handle session creation:api.ts
keepAlive: truekeeps the session open after the task completes so the user can send follow-ups.createSessioncreates the browser without a task — the session starts idle.sendTaskcallssessions.create()again with the existingsessionIdand ataskto start the agent.
api.ts
Page flow
The home page calls these functions in sequence — create the session, navigate immediately, then fire-and-forget the task:page.tsx
Section 2: Messages Interface — Polling & Follow-ups
API layer
The session page needs three more SDK calls:api.ts
getSessionreturns the session status (created,idle,running,stopped,timed_out,error) and theliveUrl.getMessagesreturns the conversation history — user messages, agent thoughts, and tool calls.stopTaskstops only the current task (not the session) usingstrategy: "task", so the user can send another task.
Polling with React Query
The session context sets up two parallel polls using TanStack Query:session-context.tsx
Sending follow-ups
Follow-up messages reuse the samesendTask function from the home page. The context adds optimistic updates so the user’s message appears instantly:
session-context.tsx
Stopping a task
session-context.tsx
stopTask to a stop button that appears while the agent is running. Since we used strategy: "task", the session stays alive for follow-ups.
Session page
The session page consumes everything through the context provider:session/[id]/page.tsx
Summary
The full SDK surface used by this app:
The complete source is at github.com/browser-use/chat-ui-example.