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:
- 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:
tsx
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:
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