From ea04c0cf30bbf03ec32498e43dd11d9dea867a4f Mon Sep 17 00:00:00 2001 From: Dhanalakshmi M Date: Tue, 29 Sep 2026 00:23:40 +0530 Subject: [PATCH 1/2] Add support bot memory decisions example --- docs/examples.md | 13 ++++++++ examples/support_bot.py | 72 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 examples/support_bot.py diff --git a/docs/examples.md b/docs/examples.md index ecbca9e..2cd5709 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -1,3 +1,16 @@ # Examples See `examples/basic_usage.py` and evaluation datasets in `benchmarks/datasets/`. + +## Support Bot with Memory Decisions + +See `examples/support_bot.py` for a support-bot example that uses memory decisions to determine how to answer a user query. + +The example handles four possible decisions: + +- **Replay** — returns the stored response directly. +- **Restore** — restores relevant context before generating a response. +- **Verify** — uses a verification tool before generating a response. +- **None** — makes a fresh LLM call when no useful memory is available. + +The LLM and verification tool are stubbed in the example so the focus is on how the memory decisions are handled. diff --git a/examples/support_bot.py b/examples/support_bot.py new file mode 100644 index 0000000..6249787 --- /dev/null +++ b/examples/support_bot.py @@ -0,0 +1,72 @@ +"""Support bot example using memory decisions.""" + +from agent_memory import Memory, MemoryAction, MemoryType + + +def call_llm(prompt: str) -> str: + """Stub for an LLM call.""" + return f"LLM response: {prompt}" + + +def verify_with_tool(context: str) -> str: + """Stub for an external verification tool.""" + return f"Verified information: {context}" + + +def support_bot(memory: Memory, query: str) -> str: + decision = memory.resolve(query) + + if decision.action == MemoryAction.REPLAY: + return decision.response + + if decision.action == MemoryAction.RESTORE: + context = memory.format_restore_context(decision) + return call_llm( + f"Use the following restored context to answer the user:\n" + f"{context}\n\nUser: {query}" + ) + + if decision.action == MemoryAction.VERIFY: + context = memory.format_verify_context(decision) + verified = verify_with_tool(context) + return call_llm( + f"Use this verified information to answer the user:\n" + f"{verified}\n\nUser: {query}" + ) + + return call_llm(query) + + +def main() -> None: + memory = Memory(persist_dir=".support_bot_demo") + + memory.remember( + query="How do I reset my password?", + response="Go to Settings → Security → Reset Password and follow the email link.", + type=MemoryType.CONVERSATION, + tags=["auth", "faq"], + ) + + memory.remember( + query="Current API rate limit", + response="1000 requests/minute per API key.", + type=MemoryType.FACT, + requires_verification=True, + ) + + queries = [ + "How do I reset my password?", + "Give me a one-sentence explanation of password reset", + "What is the API rate limit?", + "What's the weather today?", + ] + + for query in queries: + print(f"\nUser: {query}") + print(f"Bot: {support_bot(memory, query)}") + + +if __name__ == "__main__": + main() + + From 6571cf91cbf08271be6336a199bfabbb7e447532 Mon Sep 17 00:00:00 2001 From: Dhanalakshmi M Date: Thu, 1 Oct 2026 00:00:40 +0530 Subject: [PATCH 2/2] Clarify expected support bot responses --- examples/support_bot.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/support_bot.py b/examples/support_bot.py index 6249787..23867ba 100644 --- a/examples/support_bot.py +++ b/examples/support_bot.py @@ -55,9 +55,16 @@ def main() -> None: ) queries = [ + # Expected action: REPLAY — return the stored response directly. "How do I reset my password?", + + # Expected action: RESTORE — restore relevant context, then call the LLM. "Give me a one-sentence explanation of password reset", + + # Expected action: VERIFY — verify the stored information, then call the LLM. "What is the API rate limit?", + + # Expected action: NONE — no useful memory, so call the LLM directly. "What's the weather today?", ]