Skip to main content

Overview

The Session class represents a conversation session. It provides methods for adding messages, retrieving context, and processing sessions to update user memories.

Properties

string
Unique identifier for the session.
string
ID of the user this session belongs to.
SessionStatus
Current session status: PENDING, PROCESSING, PROCESSED, or FAILED
dict
Session metadata as a dictionary.
datetime
UTC timestamp when the session was created. Can be customized using custom_created_at_utc during session creation for benchmarking or importing historical data.
datetime | None
UTC timestamp when the session was processed, or None if not yet processed.
integer | None
Seconds of inactivity before auto-processing, or None if disabled.

Session Management Methods

update()

Update the session metadata.
dict
required
New metadata to replace the existing metadata. Completely replaces the old metadata.
Returns: None (mutates the instance in place) Raises: UserNotFoundError, SessionNotFoundError

refresh()

Refresh the session instance with the latest data from the server.
Returns: None (updates the instance in place) Raises: UserNotFoundError, SessionNotFoundError

delete()

Delete this session and all associated data permanently.
This action is irreversible. Deleting a session permanently removes its messages, memories, memory connections, memory categories, and merge conflicts that were created from it.
Returns: None Raises: UserNotFoundError, SessionNotFoundError

Message Methods

add_message()

Add a message to the session.
MessageRole
required
Message role: MessageRole.USER or MessageRole.ASSISTANT
string
required
The message content text.
MessageRole.USER: Messages from the user/human
MessageRole.ASSISTANT: Messages from the AI assistant
Returns: None Raises: UserNotFoundError, SessionNotFoundError, InvalidSessionStateError
You cannot add messages to a session that has already been processed.

get_messages()

Retrieve messages from the session with pagination.
integer
Number of messages to skip. Default: 0
integer
Maximum number of messages to return. Default: 50
Returns: MessageList object with:
  • messages: List of message objects with role, content, and timestamp fields
  • total: Total number of messages in the session
  • has_more: Boolean indicating if more messages are available
Raises: UserNotFoundError, SessionNotFoundError

Context Retrieval

get_context()

Retrieve contextual information for the session based on user memories and conversation history.

Trusted IDs Fast Path

If your system already trusts the IDs, you can skip SDK pre-validation calls and go directly to context retrieval:
This skips SDK lookup requests only. It removes extra latency from get_user() and get_session() when IDs are already validated in your own system.
Use this only with trusted IDs. The context endpoint still performs server-side validation and can still return UserNotFoundError or SessionNotFoundError.

get_context_stream()

Stream context events with status updates and structured metadata.
RecallStrategy
Strategy for memory retrieval: LOW_LATENCY, BALANCED, AGENTIC, or AUTO.
string
Timezone for formatting timestamps (e.g., America/New_York).
boolean
default:"False"
Whether to include context metadata (IDs, queries, filters, and agent reasoning in status events) in the response.
Yields: ContextResponse objects with the following fields:
RecallStrategy
Strategy for memory retrieval:
  • LOW_LATENCY: Fast retrieval with basic relevance
  • BALANCED: Good balance of speed and quality (default)
  • AGENTIC: Agentic exploration for complex queries
integer
Minimum number of memories to return. Range: 5-50. Default: 15
integer
Maximum number of memories to return. Range: 10-100. Default: 50
float
Similarity threshold for memories. Range: 0.2-0.8. Default: 0.6
float
Similarity threshold for summaries. Range: 0.2-0.8. Default: 0.5
integer
Number of last messages to include in context. Range: 1-100. Optional.
integer
Number of last summaries to include in context. Range: 1-20. Optional.
string
default:"UTC"
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.
Use the user’s local timezone for better temporal context. For example, showing “Today at 2:30 PM” is more meaningful than a UTC timestamp.
boolean
Whether to include the default RecallrAI system prompt. Default: True
boolean
default:"False"
Whether to include context metadata. When True, the response includes a metadata field with IDs, queries, filters, and agent reasoning when available.
Enable this to track which specific memories and sessions were used to generate the context, useful for debugging, auditing, or building UI features that show sources.
Timestamps 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.
Returns: ContextResponse object with the following fields:
boolean
Always True for non-streaming responses.
string
The formatted context string containing relevant memories and conversation history.
ContextMetadata
Only present when include_metadata_ids=True. Contains:
  • memory_ids: List of memory IDs that contributed to the context
  • session_ids: List of session IDs that contributed to the context
  • agent_reasoning: (Optional) Agent’s reasoning process, only populated when using agentic recall strategy
  • vector_search_queries: (Optional) Vector search queries generated for recall
  • keywords: (Optional) Keywords extracted for recall
  • session_summaries_search_queries: (Optional) Queries used to search session summaries
  • date_range_filters: (Optional) Date range filters extracted from the query (balanced recall only)
When using the agentic recall strategy, the agent_reasoning field will contain a step-by-step summary of the agent’s exploration through your knowledge graph, showing how it arrived at the final context.
Raises: UserNotFoundError, SessionNotFoundError
Use the context string as part of your system prompt when calling your LLM. This provides the AI with relevant memories and conversation history.

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.
Returns: None Raises: UserNotFoundError, SessionNotFoundError, InvalidSessionStateError
You can only process a session once. After processing, you cannot add more messages to the session.

Usage Example with LLM

Here’s how to use sessions with an LLM like OpenAI:

Async Session

For async applications, use AsyncSession: