Skip to content

< all problems44 · Level 05, Agents

Remember What Matters

medium · implement · Agents

A conversation ends and whatever the user said is gone unless something wrote it down. Implement two functions.

remember(llm, store, text): ask the model which facts in text are worth keeping across conversations (names, preferences, constraints, decisions, not small talk), as a JSON list of {"key": ..., "value": ...}; an empty list means nothing worth keeping. Append each fact to store["facts"] with a timestamp from store["clock"], which you increment per write. Return how many facts you stored.

recall(store, query): return the value of the newest fact whose key or value contains query (case-insensitive), or None.

Rules:

  1. Newest wins. "I prefer dark mode" and later "light mode" are both kept; recall returns the later one.
  2. An empty reply is a failed call, not an empty list. Try once more before concluding there was nothing.
  3. Drop any fact with an empty key or value.
  4. Never raise on a reply you cannot parse.

Tests assert properties: a stated name is recallable, the newer of two conflicting preferences wins, small talk stores nothing.