Conversation.to_dict()

Serialize the conversation to a plain dictionary.

Usage

Source

Conversation.to_dict()

The output is JSON-serializable and can be persisted or transmitted. Use from_dict() to reconstruct the conversation later.

Returns

dict[str, Any]
Dictionary with keys "conversation_id", "created_at", "metadata", "max_context_length", and "messages".

Examples

from talk_box.conversation import Conversation

convo = Conversation()
convo.add_user_message("Test")
d = convo.to_dict()
list(d.keys())
['conversation_id', 'created_at', 'metadata', 'max_context_length', 'messages']