Skip to main content

Conversation

The Conversation class provides access to conversation history, message management, and title operations.

Listing conversations

# All conversations
conversations = await af.Conversation.list()

# Filter by agent
conversations = await af.Conversation.list(agent_id=agent.id, limit=20)

for conv in conversations:
    print(f"{conv.title or 'Untitled'}{conv.message_count} messages")

Retrieving a conversation

conv = await af.Conversation.get("conv_abc123")

# Access messages
for msg in conv.messages:
    print(f"[{msg.role}] {msg.content[:100]}...")

# Access metadata
print(f"Title: {conv.title}")
print(f"Agent: {conv.agent_id}")
print(f"Messages: {conv.message_count}")

Title management

# Auto-generate a title from conversation content
title = await conv.generate_title()

# Set a custom title
await conv.set_title("Q3 Revenue Analysis")

Refreshing data

# Reload conversation from the server
await conv.refresh()

Deleting conversations

# Via class method
await af.Conversation.delete("conv_abc123")

Message dataclass

FieldTypeDescription
idstrMessage ID
rolestr"user", "assistant", or "system"
contentstrMessage text content
created_at`datetimeNone`When the message was created
metadatadictAdditional message metadata