Skip to main content
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 App instance to attach memory stores to. See Building Applications.

Configure a memory store

Define memory stores at design time and attach them to your application:
Attach the store to your application:

Memory store scopes

Retention policies

Runtime usage in tools

Access memory stores at runtime using RequestContext:

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:
Set 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=True in production to prevent unexpected data. Validate data types explicitly.
  • Scope selection: Use USER_SPECIFIC for personal data. Use APPLICATION_WIDE only for data genuinely shared across all users. Use SESSION_LEVEL for 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.success before accessing result.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.