Sessions & Conversations
Sessions enable multi-turn conversations with context persistence.
Multi-Turn Conversation
typescript
// Start a conversation
const { executionId, sessionId } = await client.agents.execute('agent-uuid', {
task: 'What are the key metrics for Q4?',
});
const result = await client.agents.getExecution(executionId);
// Continue the conversation
const followUp = await client.sessions.sendMessageSync(sessionId, {
message: 'Now compare those with Q3',
});
// And again...
const summary = await client.sessions.sendMessageSync(sessionId, {
message: 'Summarize the key differences in a table',
});Resume in Chat UI
tsx
const savedSession = localStorage.getItem('chatSession');
<AgentChat
agentId="agent-uuid"
sessionId={savedSession || undefined}
onSessionCreated={(id) => localStorage.setItem('chatSession', id)}
/>Session History
typescript
const history = await client.sessions.getHistory(sessionId);
history.messages.forEach(msg => {
console.log(`[${msg.role}] ${msg.content}`);
});List Sessions
typescript
const { sessions, total, hasMore } = await client.sessions.list({
limit: 20, offset: 0,
});
sessions.forEach(s => {
console.log(`${s.id}: "${s.lastUserMessage}" (${s.messageCount} msgs)`);
});