Messages
Messages represent the conversation history. The Client SDK tracks messages automatically and provides structured access to their content through typed parts.
Message Structure
Message Parts
Messages contain ordered parts that preserve content ordering:
Sending Messages
The send function:
- Adds the user message to the UI immediately (if
userMessageis provided) - Triggers the agent with the specified trigger name and input
- Streams the assistant's response back
Message Content Types
The content field in userMessage accepts both strings and objects:
When passing an object as content:
- The SDK creates a
UIObjectPartinstead of aUITextPart - The object's
typefield is used as thetypeName(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:
See File Uploads for complete upload flow.
Attributing the Sender (Multi-User Chats)
In conversations shared by several people, pass sender so the optimistic bubble shows who sent the message immediately:
This sender is for instant local display only. For attribution that persists and is visible to other participants, set the authoritative sender server-side on the trigger (see Server SDK Sessions). The persisted value comes back on message.sender from getMessages(), so render from message.sender and treat the value you passed to send() as the optimistic placeholder.
Rendering Messages
Basic Rendering
Rendering Parts
Named Threads
Content from named threads (like "summary") is identified by the thread property. Use the isOtherThread helper:
Session Restore
When restoring a session, fetch messages from your backend and pass them to the hook:
On your backend, use agentSessions.getMessages() to fetch UI-ready messages: