跳到主内容
@wquguru
精选88Microsoft Foundry 博客(RSS)技巧与观点

微软Foundry生产级AI Agent记忆状态治理架构指南

Architecting Governed Memory State for Production AI Agents with Microsoft Foundry

原文
发到 X
推荐理由

Agent开发者的必读工程实践,给出了从Scope隔离到读写门禁的完整可落地架构,直接解决记忆污染与隐私合规痛点。

A production agent should remember a user's language preference, an unresolved support issue, or a proven workflow. It should not quietly retain credentials, health details, financial data, prompt-injection payloads, or a stale instruction that changes how a tool behaves. The difference is not the model. It is the architecture around the model.

生产环境中的智能体应记住用户的语言偏好、未解决的客服问题或已验证的工作流。它不应悄悄保留凭据、健康详情、财务数据、提示注入载荷或改变工具行为的过时指令。区别不在于模型本身,而在于围绕模型的架构。

Microsoft Foundry Agent Service provides managed memory stores that can extract and retrieve user-profile, chat-summary, and procedural memory. It also supports item-level management, default time-to-live (TTL), and direct remember-or-forget behavior. Those primitives are useful—but a production design still needs application-level policy for scope, purpose, consent, provenance, conflict handling, observability, and deletion.

Microsoft Foundry Agent Service 提供托管内存存储,可提取和检索用户画像、聊天摘要和程序性记忆。它还支持项级管理、默认生存时间(TTL)以及直接的记住或遗忘行为。这些原语很有用——但生产设计仍需要应用层面的策略来规定范围、目的、同意、来源、冲突处理、可观测性和删除机制。

Implementation path Build an identity-bound scope, separate retrieval and write-admission gates, expose user-visible lifecycle controls, and release only after privacy-aware tracing and stateful evaluation pass.

实施路径:构建基于身份的范围,分离读取和写入准入网关,暴露用户可见的生命周期控制,并在通过隐私感知追踪和有状态评估后才发布。

Figure 1. Governed memory state architecture for production AI agents in Microsoft Foundry. Retrieval passes through an authorization gate; candidate memories pass through a separate write-admission gate; lifecycle events flow to an evidence plane.

图 1. Microsoft Foundry 中用于生产 AI 智能体的受控记忆状态架构。读取经过授权网关;候选记忆经过单独的写入准入网关;生命周期事件流向证据平面。

1. Start with a memory contract, not an API call

1. 从记忆契约开始,而非 API 调用

Before provisioning a store, write a one-page memory contract for the agent. It should name the business purpose, allowed memory classes, prohibited content, scope key, default retention, deletion promise, owners, and evidence required for an audit. This turns an ambiguous feature—“the agent remembers”—into a reviewable system behavior.

在配置存储之前,为智能体编写一页纸的记忆契约。它应指明业务目的、允许的记忆类别、禁止的内容、范围键、默认保留期、删除承诺、所有者以及审计所需的证据。这将一个模糊的功能——“智能体会记住”——转变为可审查的系统行为。

Memory classGood production useDefault policy
User profileStable preferences: language, accessibility format, approved product defaults.Read near session start. Long TTL only with clear user value and consent.
Chat summaryDistilled continuity: prior issue, decision, or open commitment.Retrieve by relevance per turn. Shorter TTL; never substitute for the source record.
ProceduralA reusable method that improved repeated task execution.Retrieve only for a matching task. Require stronger provenance and evaluation.
Ephemeral session stateCurrent-step data, tool results, temporary plans, correlation IDs.Keep outside long-term memory; expire with the session or workflow.
记忆类别良好的生产用途默认策略
用户画像稳定偏好:语言、无障碍格式、批准的产品默认值。在会话开始时读取。仅在具有明确用户价值和同意的情况下使用长 TTL。
聊天摘要提炼的连续性:先前的问题、决策或未履行的承诺。按相关性逐轮检索。较短的 TTL;绝不可替代源记录。
程序性一种提高了重复任务执行效率的可复用方法。仅针对匹配的任务检索。需要更强的来源和评估。
临时会话状态当前步骤数据、工具结果、临时计划、关联 ID。保持在长期记忆之外;随会话或工作流过期。

2. Partition state so one user—or purpose—cannot bleed into another

2. 对状态进行分区,防止一个用户或目的相互渗透

Foundry Memory uses a scope value to isolate collections of memory items. Treat that value as a security boundary. For an end-user agent, derive scope from an authenticated, tenant-qualified subject—not from an email address supplied in the prompt. For direct low-level API operations, send the scope explicitly. For an attached memory search tool, the platform can resolve the signed-in user when configured with the supported user placeholder.

Foundry Memory 使用作用域(scope)值来隔离内存项集合。将该值视为安全边界。对于最终用户智能体,应从经过身份验证且具有租户限定性的主体派生作用域,而不是从提示中提供的电子邮件地址派生。对于直接的低级 API 操作,显式发送作用域。对于附加的内存搜索工具,当配置了支持的用户占位符时,平台可以解析已登录用户。

A safe scope is stable enough to survive sessions but opaque enough that logs and operators do not receive a raw personal identifier. A keyed HMAC also prevents a malicious caller from guessing another user's scope.

一个安全的作用域应足够稳定以跨越会话保持有效,同时足够不透明,使得日志和操作员不会接收到原始的个人标识符。带密钥的 HMAC 还能防止恶意调用者猜测其他用户的作用域。

SCOPE DERIVATION

作用域派生

  • Bind scope construction to verified identity claims at the API boundary; never let the model choose or rewrite it.
  • Include purpose when the same user interacts with agents that have materially different retention or risk profiles.
  • Use a separate memory store per agent or trust boundary where possible; do not rely on prompt instructions to separate data.
  • Keep session IDs separate from long-term scope IDs. A new chat session should not create a new user identity
  • 在 API 边界将作用域构建绑定到经过验证的身份声明;绝不允许模型选择或重写它。
  • 当同一用户与具有显著不同保留期或风险配置的智能体交互时,包含用途信息。
  • 尽可能为每个智能体或信任边界使用单独的内存存储;不要依赖提示指令来分离数据。
  • 将会话 ID 与长期作用域 ID 分开。新的聊天会话不应创建新的用户身份。

3. Provision the store with explicit extraction and retention defaults

3. 通过明确的提取和保留默认值配置存储

Provisioning should be repeatable and reviewed like other infrastructure. The current preview SDK surface uses AIProjectClient and a memory-store definition that names both a chat model and an embedding model. Configure extraction deliberately; do not accept broad defaults simply because they are available.

配置过程应可重复并像其他基础设施一样进行审查。当前的预览 SDK 接口使用 AIProjectClient 和一个内存存储定义,其中指定了聊天模型和嵌入模型。应有目的地配置提取功能;不要因为某些宽泛的默认值可用就接受它们。

FOUNDRY MEMORY STORE PROVISIONING

Foundry Memory 存储配置

4. Put a write-admission gate between conversation and durable state

4. 在对话与持久化状态之间设置写入准入门控

Extraction is not authorization. A model can propose a candidate memory, but deterministic application policy must decide whether the candidate is eligible for persistence. This is where the architecture prevents accidental retention and memory poisoning.

提取不是授权。模型可以提议候选内存,但确定性的应用策略必须决定该候选是否具备持久化的资格。这是架构防止意外保留和内存投毒的关键环节。

A practical gate performs five checks: authenticated scope, allowed memory type, purpose and consent, sensitivity classification, and lifecycle metadata. It then deduplicates the candidate and resolves conflicts before calling the memory API. Store the reason for admission separately in an audit record; avoid placing operational metadata inside user-visible memory text.

一个实用的门控执行五项检查:认证的作用域、允许的内存类型、用途与同意、敏感性分类以及生命周期元数据。然后对候选项进行去重并在调用内存 API 之前解决冲突。将准入原因单独存储在审计记录中;避免将操作元数据放置在用户可见的内存文本中。

APPLICATION WRITE-ADMISSION POLICY

应用写入准入策略

For higher-risk agents, require a source allowlist for procedural memory. A procedure inferred from an untrusted webpage, a user-uploaded prompt, or a failed tool run should not become durable operating guidance. Promote procedures only from successful, evaluated trajectories—or through a human-reviewed workflow.

对于高风险智能体,要求程序记忆具备来源白名单。从不受信任的网页、用户上传的提示词或失败的 tool 运行中推断出的程序,不应成为持久的操作指南。仅通过成功且经过评估的轨迹,或通过人工审核的工作流来推广程序。

5. Retrieve selectively and label memory as untrusted context

5. 选择性检索并将记忆标记为不可信上下文

More retrieved memory is not better memory. Retrieve profile facts once near the start of a session, retrieve summaries only when relevant to the current turn, and retrieve procedures only when the intent and tool contract match. Apply a minimum score, freshness rules, type allowlists, and a token budget before the content reaches the model.

检索到的记忆越多并不代表质量越好。在会话开始时检索一次用户画像事实,仅在相关时检索摘要,仅在意图和 tool 契约匹配时检索程序。在内容进入模型之前,应用最低分数、新鲜度规则、类型白名单和 token 预算。

POST-RETRIEVAL FILTER

检索后过滤

6. Design remember, forget, inspect, and correct as product features

6. 将记住、忘记、检查和纠正设计为产品功能

Governance becomes real when a user can see and change what the agent retains. Provide four explicit operations: remember a fact, forget a fact, list retained memories, and correct a memory. The UI should preview the normalized fact, its purpose, and its expected retention before committing it.

当用户能够查看并更改智能体保留的内容时,治理才变得切实可行。提供四个明确的操作:记住一个事实、忘记一个事实、列出已保留的记忆以及纠正记忆。UI 应在提交前预览标准化后的事实、其用途及其预期保留期限。

  • Authenticate the caller and derive the scope server-side.
  • Parse the request into a typed command; the model may assist, but the endpoint owns validation.
  • Apply the same sensitivity and purpose gate used for automatic extraction.
  • Use an idempotency key so retries do not create duplicate facts.
  • Write an audit event containing actor, scope hash, operation, policy version, outcome, and correlation ID.
  • For “forget,” delete or tombstone the target, invalidate caches, and verify that subsequent retrieval no longer returns it.
  • 对调用者进行身份验证,并在服务器端派生作用域。
  • 将请求解析为类型化命令;模型可以提供辅助,但端点负责验证。
  • 应用与自动提取相同的敏感性和目的门控机制。
  • 使用幂等键,以确保重试不会创建重复的事实。
  • 写入包含执行者、作用域哈希、操作、策略版本、结果和相关 ID 的审计事件。
  • 对于“忘记”操作,删除或标记目标为墓碑状态,使缓存失效,并验证后续检索不再返回该目标。

LIFECYCLE ENDPOINT PATTERN

生命周期端点模式

The repository in this example is an application abstraction over the supported Foundry memory-management API. Keeping the contract in your application prevents preview SDK changes from leaking across the codebase and makes lifecycle tests deterministic.

本示例中的存储库是对受支持的 Foundry 记忆管理 API 的应用层抽象。将契约保留在应用程序内部,可防止预览版 SDK 的变更泄露到整个代码库,并使生命周期测试具有确定性。

7. Keep thread storage, memory, and enterprise records distinct

7. 保持线程存储、记忆和企业记录相互独立

A thread is a conversation transcript. A memory is distilled context selected for future use. A system of record is authoritative business data. They can refer to one another, but they must not be collapsed into one store or one retention policy.

线程是对话转录。记忆是为未来使用而提炼的上下文。系统记录是权威的业务数据。它们可以相互引用,但绝不能合并为一个存储或一种保留策略。

State planeUse it forDo not use it as
Foundry Memory StoreExtracted profile, summary, and procedural memories used across interactions.The authoritative customer profile, consent system, or case database.
Agent thread storageMessages, model transactions, and thread continuity. Standard setup can use Azure Cosmos DB for NoSQL.A curated long-term preference store or immutable audit ledger.
Enterprise system of recordAuthoritative case, order, entitlement, policy, and consent data.Prompt history or model-generated inference.
Evidence planeTraces, evaluations, policy outcomes, deletion receipts, and operational metrics.Raw sensitive prompt capture by default.
状态平面用于不作为
铸造内存存储跨交互使用的提取后的配置文件、摘要和程序性记忆。权威的客户配置文件、同意系统或案例数据库。
代理线程存储消息、模型事务和线程连续性。标准设置可使用 Azure Cosmos DB for NoSQL。精心策划的长期偏好存储或不可变的审计账本。
企业记录系统权威的案例、订单、权限、策略和同意数据。提示历史或模型生成的推理。
证据平面追踪、评估、策略结果、删除收据和操作指标。默认情况下捕获原始敏感提示。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件