agentle.agents.conversations.callback_conversation_store

Callback-based conversation store for the Agentle framework.

This module provides a CallbackConversationStore that allows users to define custom callback functions for handling conversation persistence operations. This provides maximum flexibility for integrating with any storage system or implementing custom logic without subclassing the abstract base class.

Example

```python import asyncio from agentle.agents.conversations.callback_conversation_store import CallbackConversationStore from agentle.generations.models.messages.user_message import UserMessage from agentle.generations.models.message_parts.text import TextPart

# Custom storage (could be Redis, custom API, etc.) custom_storage = {}

async def get_messages(chat_id: str):

return custom_storage.get(chat_id, [])

async def add_message(chat_id: str, message):
if chat_id not in custom_storage:

custom_storage[chat_id] = []

custom_storage[chat_id].append(message)

async def clear_messages(chat_id: str):

custom_storage.pop(chat_id, None)

# Create the callback store store = CallbackConversationStore(

get_callback=get_messages, add_callback=add_message, clear_callback=clear_messages, message_limit=100, override_old_messages=True

)

# Use it like any other conversation store message = UserMessage(parts=[TextPart(text=”Hello!”)]) await store.add_message_async(“chat-123”, message) history = await store.get_conversation_history_async(“chat-123”) ```

Functions

override(method, /)

Indicate that a method is intended to override a method in a base class.

Classes

AssistantMessage(*[, role])

Represents a message from an assistant in the system.

Awaitable()

Callable()

CallbackConversationStore(get_callback, ...)

A conversation store that uses user-provided callback functions for persistence.

ConversationStore([message_limit, ...])

DeveloperMessage(*[, role])

Represents a message from a developer in the system.

Sequence()

All the operations on a read-only sequence.

UserMessage(*[, role])

Represents a message from a user in the system.