Skip to content

Memory ​

Without memory:, each call is a new request. The model only sees what you put in that call. memory: keeps a working set of messages, stores the conversation so a later process can load the same session, and can bring back older text that no longer fits in the window.

Memory sits beside the model, the same way guardrails do. Do not put memory on the model block.

The runtime behaviour is documented in Memory. This page is the YAML for that runtime.


Installation ​

Native sliding and summarizing need only the base install. Shaping steps need the chat-history extra. Turn recall and facts need the memory extra.

bash
pip install --upgrade --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-yaml[elsai-chat-history]==0.4.3"
pip install --upgrade --extra-index-url https://elsai-agents.elsai.ai/root/ "elsai-yaml[elsai-memory]==0.4.3"

Session identity ​

run_id is required. The stored session is {run_id}:{role}. role defaults to default. The key is fixed when the agent is built.

One file can serve many users. Pass memory_run_id at build time, and keep a placeholder in the file.

python
from elsai.config import yaml_to_agent

alice = yaml_to_agent("agent.yaml", entry="chat", memory_run_id="user-alice")
bob = yaml_to_agent("agent.yaml", entry="chat", memory_run_id="user-bob")

memory_run_id requires a memory: field.


Persistence ​

persistence picks the session backend. It is not a file extension.

BackendStepsExtra
elsai_fileElsaiSlidingStep, ElsaiSummarizingStepBase elsai-agents
elsai_jsonTrim, LRU, TTL, ElsAI summarization, similarity, semantic factselsai-chat-history, or elsai-memory for recall and facts

file_store_dir sets the folder for elsai_file. elsai_store_dir sets it for elsai_json.

One pipeline, one store

Native steps and ElsAI shaping steps cannot share a pipeline list. A native step with elsai_json, or a shaping step with elsai_file, is rejected. At most one shaping step is allowed.

A bare window_size on the memory map is rejected. The window belongs on the step. metadata_filter and multiagent_mode on the memory map are rejected. metadata_filter is accepted under similarity:.

StepWhat it keepsFields
ElsaiSlidingStepThe last N messageswindow_size, should_truncate_results
ElsaiSummarizingStepA summary of older turns, plus the newest messages. Uses the agent modelpreserve_recent_messages, summary_ratio
ElsaiTrimmingStepMessages under a count and an optional token ceilingmax_messages, max_tokens, preserve_system, preserve_recent
ElsaiSummarizationStepA summary written by summarizer_llm, which must be settrigger_count, preserve_system
ElsaiLRUStepRecently used messages. Drops the least recently usedmax_messages, preserve_system, preserve_recent
ElsaiTTLStepMessages younger than ttl_secondsttl_seconds, preserve_system, preserve_recent, use_last_accessed

ElsaiSummarizingStep and ElsaiSummarizationStep are different. The native step uses the agent model and elsai_file. The ElsAI step needs summarizer_llm, elsai_json, and the chat-history extra. Missing summarizer_llm fails at build time.

preserve_system keeps the system message after a trim. preserve_recent locks the last N messages so a trim, LRU eviction, or TTL expiry does not drop the current exchange.


Sliding window ​

Keeps the most recent messages. No memory extra.

yaml
openai:
  type: OpenAIModel
  model_id: gpt-4o-mini

session_memory:
  type: MemoryConfig
  run_id: "{{$MEMORY_RUN_ID:user-alice}}"
  persistence: elsai_file
  pipeline:
    - type: ElsaiSlidingStep
      window_size: 20
      should_truncate_results: true

chat:
  type: Agent
  name: Chat
  system_prompt: You are a helpful assistant.
  model: ${openai}
  tools: []
  memory: ${session_memory}
python
agent = yaml_to_agent("agent.yaml", entry="chat", memory_run_id="user-alice")
agent("Remember that my favourite colour is blue.")
print(agent("What is my favourite colour?"))

The same map can be written inline under memory: without a named leaf. type: MemoryConfig is required on a named leaf and optional when the map is inline.

ElsaiSummarizingStep is the other native step. It folds older turns into a summary with the agent model and stays on elsai_file. It is not ElsaiSummarizationStep, which needs a separate summarizer_llm, elsai_json, and the chat-history extra.


Turn recall ​

The live window stays small. similarity: embeds each saved message and injects the closest earlier messages on the next turn. Put the embedding and the vector store on similarity:, next to one shaping step. Do not add ElsaiSimilarityStep beside that step.

Use a different vector collection from document RAG. See RAG.

yaml
openai:
  type: OpenAIModel
  model_id: gpt-4o-mini

titan_embed:
  type: EmbeddingBackend
  provider: bedrock
  aws_region: us-east-1
  model_name: amazon.titan-embed-text-v1

chroma_store:
  type: VectorBackend
  provider: chroma
  collection_name: agent_history
  persist_directory: ./chroma_db

session_memory:
  type: MemoryConfig
  run_id: "{{$MEMORY_RUN_ID:session_user_123}}"
  persistence: elsai_json
  elsai_store_dir: ./json_sessions
  pipeline:
    - type: ElsaiTrimmingStep
      max_messages: 15
      preserve_recent: 3
  similarity:
    embedding: ${titan_embed}
    vector: ${chroma_store}
    top_k: 3
    injection_mode: system_append

recall_chat:
  type: Agent
  name: Recall chat
  system_prompt: Use the recalled earlier messages when they are relevant.
  model: ${openai}
  tools: []
  memory: ${session_memory}
python
from elsai.config import yaml_to_agent

agent = yaml_to_agent("agent.yaml", entry="recall_chat")
agent("My project is called Falcon and it ships in March.")
for i in range(10):
    agent(f"Unrelated question {i}: what is {i} + {i}?")
print(agent("When does my project ship?"))

The Falcon message has been trimmed from the window by then, but the similarity search brings it back.

similarity keyWhat it does
embedding${block} of an EmbeddingBackend: bedrock or azure
vector${block} of a VectorBackend: chroma, pinecone, or weaviate
top_kHow many earlier messages to bring back
injection_modesystem_append adds them to the system prompt. user_preamble puts them before the user message
metadata_filterOnly recall messages whose metadata matches

The provider keys are the same as for RAG, including the optional credential fields on those leaves. See Embedding providers and Vector databases. A string that is not a ${block} reference is rejected on embedding and vector.


Facts across sessions ​

semantic: pulls short facts about a user out of the conversation, such as "prefers email" or "lives in Berlin", and stores them under that user's id. Later sessions for the same user get those facts injected. It sits on the same memory map as the pipeline.

semantic: does not reuse the clients from similarity:. Point semantic_strategy at its own embedding, vector collection, and model.

yaml
openai:
  type: OpenAIModel
  model_id: gpt-4o-mini

azure_embed:
  type: EmbeddingBackend
  provider: azure
  model: text-embedding-ada-002

chroma_history:
  type: VectorBackend
  provider: chroma
  collection_name: semantic_history
  persist_directory: ./chroma

chroma_facts:
  type: VectorBackend
  provider: chroma
  collection_name: semantic_facts
  persist_directory: ./chroma

facts_chat:
  type: Agent
  name: Semantic memory
  system_prompt: Use known user facts when they are injected.
  model: ${openai}
  tools: []
  memory:
    run_id: "{{$MEMORY_RUN_ID:facts-demo}}"
    persistence: elsai_json
    elsai_store_dir: ./json_sessions
    pipeline:
      - type: ElsaiTrimmingStep
        max_messages: 20
        preserve_recent: 3
    similarity:
      embedding: ${azure_embed}
      vector: ${chroma_history}
      top_k: 3
      injection_mode: system_append
    semantic:
      user_id_key: user_id
      injection_mode: system_append
      query_from_last_user_message: true
    semantic_strategy:
      llm: ${openai}
      embedding: ${azure_embed}
      vector: ${chroma_facts}
      trigger_count: 2
      collection_name: semantic_facts
python
from elsai.config import yaml_to_agent

monday = yaml_to_agent("agent.yaml", entry="facts_chat", memory_run_id="mon-session")
monday.state.set("user_id", "alice")
monday("I'm vegetarian and I live in Berlin.")
monday("Thanks, that's all for today.")

friday = yaml_to_agent("agent.yaml", entry="facts_chat", memory_run_id="fri-session")
friday.state.set("user_id", "alice")
print(friday("Suggest a restaurant for tonight."))

Facts are skipped when the user id is not in agent.state.

KeyWhat it does
semantic.user_id_keyThe agent.state key that holds the user id
semantic.injection_modesystem_append or user_preamble
semantic.query_from_last_user_messageSearch facts with the latest user message
semantic_strategy.llmModel that extracts facts. semantic_llm: on the memory map is the fallback
semantic_strategy.embedding, .vectorWhere facts are stored. Use a collection of their own
semantic_strategy.trigger_countExtract facts every N messages. Defaults to 7
semantic_strategy.top_k, .similarity_thresholdHow many facts come back (default 5), and how close they must be (default 0.8)
semantic_strategy.collection_name, .namespaceName of the facts collection. namespace is required for Pinecone, or set PINECONE_NAMESPACE

ElsaiSimilarityStep alone, with no shaping step, indexes messages and does not trim the window. Its settings still live on the sibling similarity: map.


Copyright © 2026 elsai foundry.