Skip to main content

Client Effects

info

Learn how to define tools that let the agent trigger client-side effects.

Client effects push model-generated โ€œside-effect eventsโ€ to the frontend for execution without interrupting model reasoning, and they return a server-configured default value to the model. Use them for UI updates, focus, highlighting, animations, and state syncโ€”situations that only affect the frontend and do not depend on a returned value.

Client effect middleware
Client effect middleware

Core capabilitiesโ€‹

  • No interruption: does not wait for the frontend to respond
  • One-way notification: model โ†’ frontend UI
  • Automatic return value: uses the middleware-configured Result
  • Strong UI control: the model can โ€œdrive UI changesโ€

Workflowโ€‹

  1. Configure the Client Effect middleware on the server
  • Define Tool Name / Description / Arguments Schema
  • Configure a fixed Result
  1. Model triggers the effect
  • The LLM calls the effect tool (for example, show_station)
  1. Frontend receives and executes
  • ChatKit sends the event via onEffect
  • The frontend performs the UI side effect (state update, focus, etc.)
  1. Model continues reasoning
  • It does not wait for frontend completion

Server configuration essentialsโ€‹

Tool Name

show_station

Arguments Schema (example)

The schema must follow the JSON Schema spec:

{
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Station name"
}
}
}

Result

It has already been shown to users

Frontend (React) integrationโ€‹

Register onEffect in useChatKit:

const handleClientEffect = useCallback(
({ name, data }) => {
if (name === 'update_mindmap' && data?.mindmap) {
setMindmap(convertMindmapFromSnake(data.mindmap));
}

if (name === 'focus_node' && data?.nodeId) {
focusNode(data.nodeId);
}
},
[]
);
useChatKit({
...
onEffect: handleClientEffect,
});

Client Tool vs. Client Effectโ€‹

ItemClient ToolClient Effect
Interrupts reasoningโœ… YesโŒ No
Waits for frontend resultโœ… YesโŒ No
Dynamic resultโœ… YesโŒ No (fixed Result)
Best forState reads / user confirmationUI updates / display / focus

Best practicesโ€‹

  • Effects handle UI side effects only; keep business decisions elsewhere
  • name must exactly match the server tool name
  • data should include only the minimal fields needed by the frontend
  • Avoid long-running or blocking tasks inside effects

Client effects let the model declaratively drive UI behavior, which is key for building visual, highly interactive agent experiences.