Overview
Threads are conversations between the user and the AI. Each thread maintains:- Message history - All user and assistant messages
- Component state - Rendered components and their current props/state
- Metadata - Thread name, creation time, last updated
- Run state - Current streaming status and run IDs
userKey or userToken.
Thread Lifecycle
1. Creating Threads
Threads are created automatically when you send the first message:2. Accessing Thread Data
Get the current thread withuseTambo():
3. Switching Threads
Switch between existing threads:4. Listing Threads
Get all threads for the current user:Thread Structure
A thread contains:Messages
Each message in a thread has:Content Parts
Messages contain an array of content parts:Thread Naming
Threads can be named automatically or manually.Auto-Generated Names
By default, Tambo generates names after a threshold of messages:Manual Naming
Set thread names programmatically:Thread Metadata
Store custom data with threads:Thread Status
Monitor thread state:"idle"- No active run"streaming"- AI is generating a response"error"- Last run encountered an error
Cancelling Runs
Cancel an in-progress AI response:User Scoping
Threads are scoped to users viauserKey or userToken:
Initial Messages
Seed new threads with initial messages:- Display immediately in new threads
- Are sent to the API when the first user message is sent
- Only appear in new threads, not when switching to existing threads
Thread Hooks Reference
useTambo()
Access current thread data:useTamboThreadList()
List all user threads:useTamboThread(threadId)
Fetch a specific thread:Best Practices
Thread List UI
Show threads with names and timestamps:Loading States
Handle thread loading:Error Handling
Handle thread errors:Next Steps
- Learn about Streaming to handle real-time updates
- Explore Authentication for user scoping
- See Components for rendering in threads
- Check Tools for executing actions