Skip to main content
This cookbook gets you from zero to working memory in 3 minutes. Choose your version and follow along.

Install

pip install lyzr-adk
export LYZR_API_KEY="your-lyzr-api-key"

Step 1: Initialize and Add Memories

from lyzr import Cognis, CognisMessage

cog = Cognis()

# Store a conversation
cog.add(
    messages=[
        CognisMessage(role="user", content="My name is Alice and I love hiking."),
        CognisMessage(role="assistant", content="Nice to meet you, Alice!"),
        CognisMessage(role="user", content="I work at Google as a data scientist."),
        CognisMessage(role="assistant", content="That's a great role!"),
    ],
    owner_id="user_alice",
)
Cognis automatically extracts discrete facts from the conversation and stores them as searchable memory records.

Step 2: Search Memories

results = cog.search(query="What does Alice do for work?", owner_id="user_alice", limit=5)
for r in results:
    print(f"  {r.content}  (score: {r.score})")

# Output:
#   Alice works at Google as a data scientist  (score: 0.89)

Step 3: Retrieve All Memories

memories = cog.get(owner_id="user_alice")
for mem in memories.memories:
    print(f"  [{mem.id[:8]}] {mem.content}")

# Output:
#   [a1b2c3d4] Alice's name is Alice
#   [e5f6g7h8] Alice works at Google as a data scientist
#   [i9j0k1l2] Alice loves hiking

Step 4: Use Context in Your LLM

context = cog.context(
    current_messages=[
        CognisMessage(role="user", content="What should I do this weekend?"),
    ],
    owner_id="user_alice",
)
# Use context in your LLM system prompt
print(context)

What’s Different Between Hosted and Open Source?

AspectHostedOpen Source
Data storageLyzr cloudLocal (~/.cognis/)
Async supportFull (aadd, asearch, etc.)Sync only
SummariesAvailableNot available
Return typesObjects (.content, .score)Dicts (["content"], ["score"])
CleanupOptionalRequired (m.close())
For a full comparison, see Hosted vs Open Source.

Next Steps

CrewAI Integration

Add memory to multi-agent crews

LangGraph Integration

Memory as graph nodes