How can I add persistent user memory to an AI agent deployed in Microsoft Foundry?

Mohamed, Rihan 60 Reputation points
2026-08-13T16:28:48.9266667+00:00

I have developed an AI agent using Python in Visual Studio Code and deployed it to Microsoft Foundry. I am using Azure DevOps for the project and Azure Bot Service to integrate the agent with Microsoft Teams.

I am investigating whether I can add a memory capability so the agent can remember user preferences across conversations.

For example:

  • Remember a user's preferred option across conversations.
  • Keep instructions such as “use this source only for this conversation” as session-only.
  • Allow a new user instruction to override a previously remembered preference.
  • Store memory separately for each user.
  • Allow the backend to update or delete stored memory.

Could someone clarify:

  1. What is the Microsoft-recommended way to implement persistent user memory for a Foundry agent?
  2. Is there a built-in memory capability, or should memory be implemented using an external data store?
  3. How can user identity from Teams/Bot Service be mapped to stored memory?
  4. How should persistent memory and session-only context be handled separately?
  5. Can memory be managed or deleted through the backend?
  6. Are there any Microsoft reference architectures or samples for this scenario?

The agent is deployed to Microsoft Foundry and integrated with Teams through Azure Bot Service, with the development and deployment managed through Azure DevOps.I have developed an AI agent using Python in Visual Studio Code and deployed it to Microsoft Foundry. I am using Azure DevOps for the project and Azure Bot Service to integrate the agent with Microsoft Teams.

I am investigating whether I can add a memory capability so the agent can remember user preferences across conversations.

For example:

  • Remember a user's preferred option across conversations.
  • Keep instructions such as “use this source only for this conversation” as session-only.
  • Allow a new user instruction to override a previously remembered preference.
  • Store memory separately for each user.
  • Allow the backend to update or delete stored memory.

Could someone clarify:

  1. What is the Microsoft-recommended way to implement persistent user memory for a Foundry agent?
  2. Is there a built-in memory capability, or should memory be implemented using an external data store?
  3. How can user identity from Teams/Bot Service be mapped to stored memory?
  4. How should persistent memory and session-only context be handled separately?
  5. Can memory be managed or deleted through the backend?
  6. Are there any Microsoft reference architectures or samples for this scenario?

The agent is deployed to Microsoft Foundry and integrated with Teams through Azure Bot Service, with the development and deployment managed through Azure DevOps.

Foundry Agent Service
Foundry Agent Service

A fully managed platform in Microsoft Foundry for hosting, scaling, and securing AI agents built with any supported framework or model

0 comments No comments

2 answers

Sort by: Newest
  1. Thanmayi Godithi 11,825 Reputation points Microsoft External Staff Moderator
    2026-09-02T14:34:02.6166667+00:00

    Hi @Mohamed Rihan,

    Thank you for the detailed explanation of your architecture and requirements.

    For Microsoft Foundry Agent Service, the recommended approach is to use the built-in memory capability (preview) when your goal is to retain user-specific information such as preferences across conversations. The service provides managed memory stores that can be associated with agents and used to persist information beyond a single chat session.

    Regarding your specific questions:

    1. Persistent user memory can be implemented using Foundry Agent Service memory stores rather than building a custom memory layer from scratch.
    2. Session-only context should remain in the current conversation/thread and should not be written to long-term memory unless you explicitly want it persisted.
    3. Per-user isolation is supported by scoping memory to a user identifier. For Teams integrations, a common pattern is to use the Teams/Bot user identity as the key for memory retrieval and storage.
    4. If a user updates a preference, the application or agent logic can update the stored memory, so the latest preference supersedes the previous value.
    5. Memory items can be managed programmatically, allowing backend processes to read, update, and remove stored memory as needed.
    6. Microsoft has published memory concepts, how-to guidance, and quickstart samples for Foundry Agent Service memory, which cover creating memory stores, attaching memory to agents, and implementing persistent memory scenarios.

    From the requirements you've described (persistent preferences, per-user storage, session-only instructions, and backend management), the built-in Foundry memory capability appears to align well with your use case without requiring a separate custom database for memory management.

    I recommend reviewing the Foundry Agent Service memory documentation and quickstart samples to determine whether the preview functionality meets your production requirements before implementing a custom solution.

    Hope this helps clarify the supported approach.

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-08-13T16:29:20.8266667+00:00

    Yes. Foundry Agent Service has a built-in managed memory capability: a memory store. This is the Microsoft-aligned way to add persistent user memory for a Foundry agent when the goal is to retain preferences and continuity across sessions.

    Key points for the scenario described:

    1. Built-in persistent memory
      • Foundry memory is a managed long-term memory solution.
      • It supports persistent storage through memory stores.
      • Memory types include:
        • User profile memory for durable preferences and personal context.
        • Chat summary memory for prior conversation continuity.
        • Procedural memory for reusable how-to routines.
    2. Per-user isolation
      • Memory is segmented with the scope parameter.
      • To scope memory to an individual end user, set scope to "{{$userId}}" in the memory tool definition and pass x-memory-user-id: <user-id> on each response call.
      • If that header is not passed, scope falls back to the caller’s Microsoft Entra identity.
      • For a Teams/Bot Service integration, the practical pattern is to map the Teams/Bot user identity to the value sent in x-memory-user-id, so each user gets a separate memory partition.
    3. Persistent memory vs session-only context
      • Persistent memory should be stored in the memory store.
      • Session-only instructions such as “use this source only for this conversation” should remain in the current conversation context and not be written as long-term memory.
      • Foundry distinguishes between:
        • Static memories injected at the start of a conversation for persistent user context.
        • Contextual memories retrieved per turn based on recent messages.
      • If direct API control is needed, static memories can be retrieved by calling search_memories with scope only, while contextual memories are retrieved by calling search_memories with items set to the latest messages.
    4. Overriding remembered preferences
      • The service supports direct remember-or-forget behavior when a user explicitly asks the agent to remember or forget something.
      • It also supports item-level CRUD for memory records, so backend logic can create, inspect, update, or delete individual memory items.
      • This supports scenarios where a new instruction replaces an older preference.
    5. Backend management and deletion
      • Yes. Memory can be managed from the backend.
      • Supported operations include creating, reading, updating, listing, and deleting individual memory items.
      • Store-level retention controls are also available, including default TTL for newly created memory entries.
      • Direct remember/forget commands do not override TTL; items can still expire if TTL is configured.
    6. Implementation choices
      • Two supported patterns are documented:
        • Attach the memory search tool to the agent so the agent reads and writes memory during conversations.
        • Use memory store APIs directly to add memories from conversation content and search memories explicitly.
      • For a hosted agent workflow, the quickstart describes wiring a memory store to the agent and using FoundryMemoryProvider, which retrieves relevant memories before each model call and updates the store after each turn.
    7. Recommended implementation path for this scenario
      1. Create a memory store for the agent.
      2. Attach the memory search tool to the agent.
      3. Set per-user scope using "{{$userId}}".
      4. From the Teams/Bot backend, pass x-memory-user-id for each user on response calls.
      5. Keep temporary conversation-only instructions in the active thread/request context instead of persisting them.
      6. Use memory item CRUD or direct remember/forget behavior when preferences must be updated or removed.
      7. Optionally configure TTL if stored memories should expire automatically.
    8. Reference samples and architecture guidance in the provided material
      • The Foundry quickstart shows a hosted agent with persistent memory backed by a memory store.
      • The memory how-to articles cover store creation, agent-tool integration, direct API usage, retention, and item CRUD.

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.