Messages

Messages represent the conversation history. The Client SDK tracks messages automatically and provides structured access to their content through typed parts.

Message Structure

typescript

Message Parts

Messages contain ordered parts that preserve content ordering:

typescript

Sending Messages

tsx

The send function:

  1. Adds the user message to the UI immediately (if userMessage is provided)
  2. Triggers the agent with the specified trigger name and input
  3. Streams the assistant's response back

Rendering Messages

Basic Rendering

tsx

Rendering Parts

tsx

Named Threads

Content from named threads (like "summary") is identified by the thread property. Use the isOtherThread helper:

tsx

Session Restore

When restoring a session, fetch messages from your backend and pass them to the hook:

tsx

On your backend, use agentSessions.getMessages() to fetch UI-ready messages:

typescript

Callbacks

tsx