androidengineers.Book a session

Context and memory architecture

Lab: build a scoped memory store

exerciseSelf-paced

Assignment

Create two users, three temporary facts, two explicit preferences, and one later correction. Use synthetic values only.

Build sequence

  1. Define working and persistent record schemas with provenance and expiry.
  2. Implement scope-filtered lookup, correction, and deletion.
  3. Summarize a conversation containing a qualified statement and inspect whether uncertainty survives.
  4. Test context reconstruction after a user switch.

Acceptance checks

  • No user can retrieve another user’s records.
  • Expired and deleted facts are absent from future context.
  • The summary retains material uncertainty and links to its source.

Evidence to keep

Submit the working artifact or decision document described above, the inputs used, and the observed results for every acceptance check. Include one failed attempt and the change you made after investigating it. Label fixture-based outcomes separately from live-system measurements. These artifacts become part of your final portfolio review.

Guided workshop: retrieve only current, permitted memories

Working context is temporary task state. Long-term memory persists across tasks and needs ownership, provenance, expiry, correction, and deletion. A model-inferred preference should not silently become a permanent fact about a person.

# academy-check
memories = [
    {"id": "m1", "user": "alice", "tenant": "a", "text": "Use concise replies", "expires": 100, "deleted": False},
    {"id": "m2", "user": "bob", "tenant": "a", "text": "Private preference", "expires": 100, "deleted": False},
]

def recall(principal, now):
    return [m for m in memories if m["tenant"] == principal["tenant"]
            and m["user"] == principal["user"] and not m["deleted"] and m["expires"] > now]

alice = {"tenant": "a", "user": "alice"}
assert [m["id"] for m in recall(alice, 10)] == ["m1"]
assert recall(alice, 100) == []
memories[0]["deleted"] = True
assert recall(alice, 10) == []

The numeric clock is injected so expiry tests are deterministic. Use an explicit time convention in persistent storage. Scope filtering must happen before semantic ranking; otherwise an unauthorized record may enter a prompt or leak through an intermediate trace.

Build steps: add source event ID, creation time, memory kind, and correction version. Separate user-confirmed preferences from episodic records of a task and semantic facts derived from documents. Provide a way to list and delete memories. Test that cached summaries stop using deleted or corrected material.

Worked context budget: reserve space for trusted instructions and the current request, then select a small amount of relevant memory and evidence. Summarizing an old conversation can discard qualifiers such as “only for this project.” Keep provenance and avoid converting a temporary instruction into a global preference.

Challenge: two memories disagree about a user's preferred notification channel. Return the conflict for clarification or follow an explicitly documented precedence policy. Do not resolve it merely by whichever text gets a higher similarity score.

Assessment: demonstrate another user, another tenant, expired records, deletion, correction, and a poisoned memory containing an instruction to call an unauthorized tool. Memory can influence a draft, but it cannot change runtime permissions. Save a context assembly trace with memory IDs and reasons for inclusion while keeping private content out of general logs.

YOUR LEARNING JOURNEY

0 of 121 available lessons completed

Progress saved in this browser. No account needed.
Lab: build a scoped memory store | Agentic AI | Android Engineers