Skip to main content

Overview

The Thread class represents a conversation containing multiple messages. It provides rich functionality for managing conversation state, tracking metrics, and organizing messages by turns.

Creating a Thread

Key properties

string
default:"auto-generated UUID"
Unique identifier for the thread
string
default:"Untitled Thread"
Human-readable title for the thread
List[Message]
default:"[]"
List of messages in the thread
datetime
default:"now"
Timestamp when the thread was created (UTC)
datetime
default:"now"
Timestamp when the thread was last updated (UTC)
Dict
default:"{}"
Custom metadata for the thread
Dict[str, Dict[str, str]]
default:"{}"
References to where this thread exists on external platforms (e.g., Slack, Discord)

Adding Messages

Single message

Batch messages

Accessing Messages

Thread Analytics

Token usage

Message statistics

Thread Management

Reactions

Threads support emoji reactions on messages:

Serialization

Turn Management

Messages are organized into turns, representing conversation rounds:

Example: Building a Conversation