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

Message Content Types

The content field in userMessage accepts both strings and objects:

tsx

When passing an object as content:

  • The SDK creates a UIObjectPart instead of a UITextPart
  • The object's type field is used as the typeName (defaults to 'object' if not present)
  • This is useful for rich UI interactions like product selections, quick replies, etc.

Sending with Files

Include file attachments with messages:

tsx

See File Uploads for complete upload flow.

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