Managing conversations with R2R.

This feature is currently in beta. Functionality may change, and we value your feedback around these features.

Occasionally this SDK documentation falls out of date, cross-check with the automatically generated API Reference documentation for the latest parameters.

Conversation Management

Get Conversations Overview

Retrieve an overview of existing conversations:

1conversation_ids = ['123e4567-e89b-12d3-a456-426614174000', '987f6543-e21b-12d3-a456-426614174000']
2offset = 0
3limit = 10
4overview_response = await client.conversations_overview(conversation_ids, offset, limit)
conversation_ids
list[str]

Optional list of conversation UUIDs to retrieve.

offset
int

The offset to start listing conversations from.

limit
int

The maximum number of conversations to return.

Get Conversation

Fetch a specific conversation by its UUID:

1conversation_id = '123e4567-e89b-12d3-a456-426614174000'
2branch_id = 'optional-branch-id'
3conversation = await client.get_conversation(conversation_id, branch_id)
conversation_id
strRequired

The UUID of the conversation to retrieve.

branch_id
str

Optional ID of a specific branch to retrieve.

Create Conversation

Create a new conversation:

1new_conversation = await client.create_conversation()

Add Message

Add a message to an existing conversation:

1conversation_id = '123e4567-e89b-12d3-a456-426614174000'
2message = Message(text='Hello, world!')
3parent_id = '98765432-e21b-12d3-a456-426614174000'
4metadata = {'key': 'value'}
5
6add_message_response = await client.add_message(conversation_id, message, parent_id, metadata)
conversation_id
strRequired

The UUID of the conversation to add the message to.

message
MessageRequired

The message object to add to the conversation.

parent_id
str

An optional UUID of the parent message.

metadata
dict

An optional metadata dictionary for the message.

Update Message

Update an existing message in a conversation:

1message_id = '98765432-e21b-12d3-a456-426614174000'
2updated_message = Message(text='Updated message content')
3
4update_message_response = await client.update_message(message_id, updated_message)
message_id
strRequired

The UUID of the message to update.

message
MessageRequired

The updated message object.

Get Branches Overview

Retrieve an overview of branches in a conversation:

1conversation_id = '123e4567-e89b-12d3-a456-426614174000'
2branches_overview = await client.branches_overview(conversation_id)
conversation_id
strRequired

The UUID of the conversation to get branches for.

Update Message Metadata

Update the metadata of a message by its ID:

1message_id = '123e4567-e89b-12d3-a456-426614174000'
2metadata = {
3 'key1': 'value1',
4 'key2': 'value2'
5}
6update_response = await client.update_message_metadata(message_id, metadata)
message_id
strRequired

The ID of the message to update.

metadata
dictRequired

The metadata to update.

Delete Conversation

Delete a conversation by its UUID:

1conversation_id = '123e4567-e89b-12d3-a456-426614174000'
2delete_response = await client.delete_conversation(conversation_id)
conversation_id
strRequired

The UUID of the conversation to delete.