Skip to main content
Your server keeps the API key, creates a Session per conversation, and relays its events to the browser. When the agent calls a tool your app owns, the turn pauses until your server sends back the result.

Create the Agent

Give the Agent a custom tool that your server will run:

The server

tools.ts
server.mts
This local demo listens on loopback. For an application, authorize each session read, message, and confirmation against the signed-in user. Install the SDK and the Effect version it pins so the stream callback uses the SDK’s Effect types. Start the server with CHECKFU_BASE_URL and CHECKFU_API_KEY exported.
Then drive it from a second terminal:
You should see the tool call, the requires_action pause, your server’s tool result, and the agent’s final reply stream past.

Stream events to the browser

The relay writes each event’s seq as the SSE id so EventSource resumes from that cursor after reconnecting. If the upstream opens with 204 for an archived Session with no events left at that cursor, the relay returns 204 too. A browser that receives the archive event closes its stream immediately.

Handle tool calls

A pause arrives as session.status_idle with stop reason requires_action. Answer every ID in stop_reason.event_ids; the turn resumes once the last answer arrives.
  • Answer agent.custom_tool_use with user.custom_tool_result.
  • Answer agent.mcp_tool_use that has evaluated_permission: "ask" with user.tool_confirmation (result: "allow" or "deny").
Tool result text can contain up to 16,384 UTF-16 code units after JSON serialization, including escape characters. Have tools return a bounded summary when their output can be large. If a serialized result exceeds the limit, the processor saves a short is_error result and submits it with the same stable ID on each retry. If the API rejects a tool processor request as invalid or too large, the processor logs the request ID and stops so you can investigate. The server owns one tool processor per Session, even with zero browsers connected. Browser streams only observe events. The processor checks that a replayed pause is still current and saves each result and its stable event ID before submitting it. The result key hashes the SDK’s normalized deployment URL, Session ID, and tool call ID. A retry in the same deployment reuses the saved result. After a restart, supply the active Session IDs from your application and reuse the same private results directory. This example uses one server and a read-only lookup. For several servers, claim each call in a shared durable store. For a side-effecting tool, use the same call key with a downstream idempotency check or commit the application effect and result together. Reusing a Checkfu event ID only deduplicates the submitted answer. While paused, the Session waits without making any model requests. See Tools and Resume a stream.