Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/examples.md
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.
79 changes: 79 additions & 0 deletions examples/support_bot.py
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 = [
Comment thread
theprodsde marked this conversation as resolved.
# 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()


Loading