Logo IconGuided Mind
v2.4Sign In
Python SDK

Short Memory

Session-scoped conversation history with automatic expiration.

Short Memory stores conversation records keyed by a session_id. Records are returned in chronological order and expire after a configurable TTL (default 24 hours). It's designed for maintaining turn-by-turn context within a single chat session.

Access it via client.memory.short.

Adding Records

from guidedmind import Client
 
client = Client()
 
# Add a user message
client.memory.short.add_record(
    session_id="session-abc123",
    role="user",
    content="What pricing plans do you offer?",
)
 
# Add the assistant's response
client.memory.short.add_record(
    session_id="session-abc123",
    role="assistant",
    content="We offer Free, Pro, and Enterprise plans.",
)

Retrieving Records

records = client.memory.short.get_records(session_id="session-abc123")
 
print(f"Total records: {records.total}")
for record in records.records:
    print(f"  [{record.role}] {record.content}")

Building a Chat History for an LLM

A common pattern is fetching short memory to pass as context to your LLM call:

def get_chat_history(session_id: str) -> list[dict]:
    """Return messages in OpenAI-compatible format."""
    records = client.memory.short.get_records(session_id=session_id)
    return [
        {"role": record.role, "content": record.content}
        for record in records.records
    ]
 
# Usage
history = get_chat_history("session-abc123")
# Pass `history` as the `messages` array to your LLM API

Methods

MethodReturnsDescription
add_record(session_id, role, content)MemoryRecordAppend a message to the session
get_records(session_id)RecordListFetch all records ordered by time
aadd_record(...)Awaitable[MemoryRecord]Async version of add_record
aget_records(...)Awaitable[RecordList]Async version of get_records

Parameters

ParameterTypeDefaultDescription
session_idrequiredstrUnique identifier for the conversation session.
rolerequiredstrSender role. Either "user" or "assistant".
contentrequiredstrMessage text.

Async Usage

import asyncio
from guidedmind import Client
 
async def save_turn(session_id: str, user_msg: str, assistant_msg: str):
    async with Client() as client:
        await client.memory.short.aadd_record(
            session_id=session_id,
            role="user",
            content=user_msg,
        )
        await client.memory.short.aadd_record(
            session_id=session_id,
            role="assistant",
            content=assistant_msg,
        )

Short Memory records expire automatically. For durable, cross-session storage use Long Memory instead.