Sessions
Sessions represent conversations with an agent. They store conversation history, track resources and variables, and enable stateful interactions.
Creating Sessions
Create a session by specifying the agent ID and initial input variables:
Getting Session Messages
To restore a conversation on page load, use getMessages() to retrieve UI-ready messages:
The returned messages can be passed directly to the client SDK's initialMessages option.
UISessionState Interface
Full Session State (Debug)
For debugging or internal use, you can retrieve the complete session state including all variables and internal message format:
Note: Use getMessages() for client-facing code. The get() method returns internal message format that includes hidden content not intended for end users.
Attaching to Sessions
To trigger actions on a session, you need to attach to it first:
Triggering Actions
Once attached, trigger actions on the session:
Session Lifecycle
Restoring Sessions
When a user returns to your app, restore their session:
The messages array contains UIMessage objects with properly structured parts, enabling direct use with the client SDK's initialMessages option.