How to Integrate Memory Into Agents¶
Use this guide when you want to add memory to generated agent code without mixing it up with the top-level CLI memory backend.
Generate the Scaffold¶
The supported generator entrypoint is amplihack new, not the older goal-agent generate commands.
This gives you a standalone package with:
main.pymemory_config.yamlmemory/amplihack-memory-libinrequirements.txt- helper functions injected into
main.py
Install the Package Dependencies¶
Use the Generated Memory Helpers¶
The generated package exposes helper functions such as:
store_success(context, outcome, confidence=...)store_failure(context, outcome, confidence=...)store_pattern(context, outcome, confidence=...)store_insight(context, outcome, confidence=...)recall_relevant(query, limit=...)cleanup_memory()
A minimal integration pattern is to recall relevant experience before the run and store the result afterward.
recent = recall_relevant(initial_prompt, limit=3)
for item in recent:
print("Previous experience: {} -> {}".format(item.context, item.outcome))
exit_code = auto_mode.run()
if exit_code == 0:
store_success(
context="Goal execution completed",
outcome=initial_prompt,
confidence=0.95,
)
else:
store_failure(
context="Goal execution failed",
outcome="Exit code {}".format(exit_code),
confidence=0.95,
)
Keep the Two Memory Surfaces Straight¶
The generated package and the top-level CLI graph are different systems.
| Surface | Entry Point | Storage |
|---|---|---|
| generated agent scaffold | amplihack new --enable-memory | local ./memory/ directory |
| top-level CLI graph | amplihack memory tree | SQLite MemoryDatabase at ~/.amplihack/memory.db |
| agent-local transfer | amplihack memory export / amplihack memory import | hierarchical Kuzu store for the named agent |
If you want to inspect the top-level CLI graph, use:
If you want to move an agent-local hierarchical memory store between environments, use:
amplihack memory export --agent incident-memory-agent --output ./incident-memory.json
amplihack memory import --agent incident-memory-agent --input ./incident-memory.json --merge
Do not expect those commands to be a direct live view into a generated agent's local ./memory/ directory.
Configure Kuzu-backed Graph Paths¶
For lower-level Kuzu graph integrations and agent-local hierarchical stores, the preferred environment variable is:
AMPLIHACK_KUZU_DB_PATH still exists as a deprecated alias.
The top-level amplihack memory tree command does not read this setting; it opens the SQLite MemoryDatabase unless you change code.