Skip to content

Environment Variable Memory Module (VariableMemoryModule)

The Environment Variable Memory Module stores key-value pairs that can be used to personalize your AI assistant's responses based on user preferences, context, or application state.

Purpose

Store environment variables (key-value pairs) that can be used to personalize responses and maintain application-specific context across conversations.

Parameters

  • variables: A dictionary of key-value pairs representing environment variables.
  • max_context: Max total character count for retrieved env variables. Must be a positive integer.

Example

Environment variables are typically included in agent prompts to provide context and personalization. For example:

# To customize VariableMemoryModule, define memory_config and include it in the memory_modules. 
# Otherwise, omit this block to use defaults.
memory_config:
  memory_modules:
    - memory_name: env_variable            # Required. Unique identifier for this memory module.
      memory_class: VariableMemoryModule   # Required. Memory module class.
      config:                              # Optional. Specified per-module configuration.
        max_context: 5000                  # Optional. Max total character count for retrieved env variables. Must be a positive integer. Defaults to 10,000.
        variables:                         # Optional. Dictionary of environment variables
          event_title: "FIFA World Cup"    # Optional. Key-value pairs.
          event_year: "2022"
          supporting_team: "Brazil"

These variables can then be retrieved and included in your agent's prompt to provide personalized context.

Adding or Overriding Variables at Runtime

You can dynamically add or update environment variables during runtime using the add_memory() method.