GitHub
Examples

Short-term Memory

Manage ephemeral, session-scoped context with automatic expiration.

Storage Module
Scenario: Tracking current conversation state

When to Use

Use short-term memory as a "scratchpad" or RAM for the current session. Data here is temporary and meant to expire. Perfect for:

  • Current conversation topic
  • User's immediate mood or sentiment
  • Drafting responses or holding intermediate reasoning steps

Key Operations

add()

Add key-value to buffer with TTL

get()

Retrieve value by key

Code Example

Here we buffer the user's current mood and topic. Note the ttl_seconds - this data will auto-delete after 1 hour.

# 1. Add to Short-term Buffer
session_id = "session_week1_day4"
# Store current context with 1 hour TTL
client.memory.short_term.add(
session_id=session_id,
key="current_topic",
value={"topic": "running", "subtopic": "knee_pain"},
ttl_seconds=3600
)
client.memory.short_term.add(
session_id=session_id,
key="user_mood",
value="anxious",
ttl_seconds=3600
)
# 2. Retrieve Context during conversation
topic = client.memory.short_term.get(session_id=session_id, key="current_topic")
print(f"Agent should focus on: {topic}")

Key Takeaways

  • Short-term memory is key-value based, making it fast and direct.
  • TTL (Time To Live) ensures you don't clutter storage with stale context like "user is typing...".
  • It complements Semantic/Episodic memory by handling "right now" vs "forever".