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