Overview
TheSession class represents a conversation session. It provides methods for adding messages, retrieving context, and processing sessions to update user memories.
Properties
Unique identifier for the session.
ID of the user this session belongs to.
Current session status:
PENDING, PROCESSING, PROCESSED, or FAILEDSession metadata as a dictionary.
UTC timestamp when the session was created. Can be customized using
custom_created_at_utc during session creation for benchmarking or importing historical data.UTC timestamp when the session was processed, or None if not yet processed.
Seconds of inactivity before auto-processing, or None if disabled.
Session Management Methods
update()
Update the session metadata.New metadata to replace the existing metadata. Completely replaces the old metadata.
UserNotFoundError, SessionNotFoundError
refresh()
Refresh the session instance with the latest data from the server.UserNotFoundError, SessionNotFoundError
Message Methods
add_message()
Add a message to the session.Message role:
MessageRole.USER or MessageRole.ASSISTANTThe message content text.
MessageRole.USER: Messages from the user/human
MessageRole.ASSISTANT: Messages from the AI assistant
MessageRole.ASSISTANT: Messages from the AI assistant
UserNotFoundError, SessionNotFoundError, InvalidSessionStateError
get_messages()
Retrieve messages from the session with pagination.Number of messages to skip. Default:
0Maximum number of messages to return. Default:
50MessageList object with:
messages: List of message objects withrole,content, andtimestampfieldstotal: Total number of messages in the sessionhas_more: Boolean indicating if more messages are available
UserNotFoundError, SessionNotFoundError
Context Retrieval
get_context()
Retrieve contextual information for the session based on user memories and conversation history.Strategy for memory retrieval:
LOW_LATENCY: Fast retrieval with basic relevanceBALANCED: Good balance of speed and quality (default)AGENTIC: Agentic exploration for complex queries
Minimum number of memories to return. Range: 5-50. Default:
15Maximum number of memories to return. Range: 10-100. Default:
50Similarity threshold for memories. Range: 0.2-0.8. Default:
0.6Similarity threshold for summaries. Range: 0.2-0.8. Default:
0.5Number of last messages to include in context. Range: 1-100. Optional.
Number of last summaries to include in context. Range: 1-20. Optional.
Timezone for formatting timestamps in the context (e.g., “America/New_York”, “Europe/London”, “Asia/Tokyo”). All timestamps in the retrieved memories and summaries will be formatted according to this timezone. Defaults to UTC.
Whether to include the default RecallrAI system prompt. Default:
TrueTimestamps in the context are formatted using the specified
timezone parameter (defaults to UTC). This ensures temporal information like “Last updated on Monday, January 6th at 3:45 PM EST” is presented in a user-friendly, localized format.context field containing the formatted context string
Raises: UserNotFoundError, SessionNotFoundError
Processing
process()
Process the session to update user memories.Processing extracts memories from the conversation and updates the user’s memory store. This is an asynchronous operation - the session status will change to
PROCESSING and then PROCESSED when complete.UserNotFoundError, SessionNotFoundError, InvalidSessionStateError
Usage Example with LLM
Here’s how to use sessions with an LLM like OpenAI:Async Session
For async applications, useAsyncSession: