Skip to main content
InMemoryStorage provides a flexible, lightweight storage solution that keeps all session data in memory, with the option to hook it up to any custom persistent storage solution.

Summary

  • No setup or additional dependencies: No installations or database setup required.
  • Custom storage options: Use the built-in dictionary or provide your own for custom persistence.

Use Cases

InMemoryStorage is ideal for:
  • Custom Storage Solutions: When you need to integrate with a persistence layer that doesn’t (yet) have first-party agno support (snowflake, AWS S3, etc).
  • Development and Testing: Quick setup without external dependencies.
  • Temporary Sessions: Short-lived applications where persistence isn’t required.

Important Notes

  • Data Persistence: Session data is not persistent across program restarts unless you provide an external dictionary with your own persistence mechanism.
  • Memory Usage: All session data is stored in RAM. For applications with many long sessions, monitor memory usage.
Remember that data is lost when your application restarts unless you implement your own persistence mechanism using a custom dictionary.

Usage

Basic Agent with In-Memory Storage

Here’s a simple example of using in-memory storage with an agent:
agent.py

Bring Your Own Dictionary (Custom Storage Integration)

The real power of InMemoryStorage comes from providing your own dictionary for custom storage mechanisms:
custom_persistence.py

Developer Resources