Memory Stores
Memory stores provide persistent data storage scoped to a user, session, or application. Use them to maintain state and share data between agents and tools across interactions.Prerequisites
- AgenticAI Core SDK installed and configured.
- An
Appinstance to attach memory stores to. See Building Applications.
Configure a memory store
Define memory stores at design time and attach them to your application:Memory store scopes
| Scope | Description | Use for |
|---|---|---|
USER_SPECIFIC | Data unique to each user. | Preferences, history, personalization. |
APPLICATION_WIDE | Global data shared across all users. | Shared configuration, lookup tables. |
SESSION_LEVEL | Temporary data cleared when the session ends. | Caching, in-progress task state. |
Retention policies
| Period | Example |
|---|---|
| Session (clears on session end) | RetentionPolicy(type=RetentionPeriod.SESSION, value=1) |
| Days | RetentionPolicy(type=RetentionPeriod.DAY, value=7) |
| Weeks | RetentionPolicy(type=RetentionPeriod.WEEK, value=2) |
| Months | RetentionPolicy(type=RetentionPeriod.MONTH, value=6) |
Runtime usage in tools
Access memory stores at runtime usingRequestContext:
Write data
Read data
Use projections to retrieve only the fields you need (1 = include field):
Delete data
Schema definition
Define a JSON Schema to validate data before storage:strict_schema=True in production to enforce schema validation.
Namespaces
Namespaces partition stored data within a store. Use dynamic namespaces for runtime values (user ID, session ID) and static namespaces for fixed values (environment, version).Dynamic namespaces
Static namespaces
Multiple namespaces
Best practices
- Schema design: Define specific schemas with required fields. Use
strict_schema=Truein production to prevent unexpected data. Validate data types explicitly. - Scope selection: Use
USER_SPECIFICfor personal data. UseAPPLICATION_WIDEonly for data genuinely shared across all users. UseSESSION_LEVELfor temporary data. - Retention: Match retention period to actual data needs. Short-lived data (cart state, current step) should use session retention. Consider data privacy requirements.
- Error handling: Always check
result.successbefore accessingresult.data. Provide fallback values for missing fields. Log errors with enough context to diagnose the issue. - Performance: Use projections when reading — fetch only the fields you need. Avoid memory reads in hot paths where possible. Cache frequently accessed data locally.
- Security: Do not store sensitive data (passwords, tokens, PINs) in memory stores. Use appropriate scopes to isolate user data. Set conservative retention policies to limit exposure.