Memory Management ExampleΒΆ
This guide provides a professional, step-by-step walkthrough of using the MemoryManager in the agenticaiframework package to efficiently store, retrieve, inspect, and clear different types of memory. It is designed for developers building intelligent agents that require persistent or temporary state management.
7 Memory Managers Available
Part of 400+ modules with 7 specialized memory managers including Redis, PostgreSQL, and vector store backends. See Enterprise Documentation.
Prerequisites & ConfigurationΒΆ
- Installation: Ensure
agenticaiframeworkis installed and accessible in your Python environment. - No additional configuration is required for this example.
- Python Version: Compatible with Python 3.10+.
CodeΒΆ
Step-by-Step ExecutionΒΆ
-
Import the Class Import
MemoryManagerfromagenticaiframework.memory. -
Instantiate the Manager Create an instance of
MemoryManagerto handle all memory operations. -
Store Data Use
store_short_termto save temporary key-value pairs (e.g., user session data). -
Retrieve Data Access stored values using
retrieveby providing the key. -
Inspect Stored Keys Combine keys from
short_term,long_term, andexternalmemory to get a complete view of stored data. -
Clear Memory Use
clear_short_term,clear_long_term, andclear_externalto remove stored data when no longer needed.
Best Practice: Always clear sensitive data from memory after use to prevent leaks in long-running applications.
Expected InputΒΆ
No user input is required; the script uses hardcoded values for demonstration purposes. In production, these values could come from user interactions, API calls, or other runtime events.
Expected OutputΒΆ
How to RunΒΆ
Run the example from the project root:
| Bash | |
|---|---|
If installed as a package, you can also run it from anywhere:
| Bash | |
|---|---|
Tip: Use logging or print statements to verify memory operations during development.