Repository navigation
Add support bot memory decisions example #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
theprodsde
merged 3 commits into
theprodsde:main
from
Dhanalakshmi17601:feat/support-bot-memory-example
Sep 30, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """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 = [ | ||
| # 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?", | ||
| ] | ||
|
|
||
| for query in queries: | ||
| print(f"\nUser: {query}") | ||
| print(f"Bot: {support_bot(memory, query)}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.