Skip to content

规范

Agent Context 最新草案是一套可移植标准,用于表达 context surfaces、context items、source refs、selection and ranking、budget and window、assembly and injection、compaction and summaries、missing-context records、policy refs、evidence refs、telemetry refs 与 context lifecycle events。

Agent Context 拥有“上下文语义”。它不拥有 memory storage、retrieval indexes、prompt templates、model APIs、runtime queues、tool execution、UI rendering、policy decisions、evidence archives、artifact lifecycle、knowledge package authoring 或 skill execution。

范围

Agent Context 标准化以下实现问题:

  1. 用稳定 identity、scope、lifecycle、actor refs、runtime refs、policy refs、evidence refs 与 telemetry refs 表达 context envelopes。
  2. 用 context surfaces 描述 selection 之前可用的候选上下文集合。
  3. 用 context items 表达 kind、content mode、source refs、token estimates、freshness、trust、sensitivity 与 redaction state。
  4. 用 source refs 保留 URI、selectors、digests、authority、provenance links 与 native protocol mappings。
  5. 用 selection and ranking records 记录 candidates、selected items、omitted items、reasons 与 scorer signals。
  6. 用 budget and context-window records 记录 tokens、bytes、items、reserved segments、overflow 与 truncation。
  7. 用 assembly and injection records 说明哪些有序 blocks 对哪个 target 可见。
  8. 用 compaction and summary records 保留 source coverage、replacement facts、loss notes 与 refresh policy。
  9. 用 missing-context records 把已知缺口变成可处理事实。
  10. 用事件类别表达 surface、item、selection、budget、assembly、injection、compaction、missing-context、redaction 与 export 的变化。

Agent Context 定义新的 retrieval engine、vector database、memory store、prompt language、runtime scheduler、UI component library、authorization engine、evidence archive 或 artifact format。

核心对象

对象作用
context_envelopeturn、task、session、tool call、review 或 handoff 的可移植快照。
context_surface某个 scope 下 selection 之前可用的候选上下文。
context_iteminline 或 referenced 的上下文单元。
context_source_reforigin、selector、digest、authority 与 native mapping。
context_selectioncandidate、selected、omitted、ranking 与 rationale facts。
context_budgettoken、byte、item、time 与 visibility limits 以及实际使用量。
context_window面向 target 的有序窗口布局与预留 segment。
context_assembly为某个 target 准备的有序上下文 blocks。
context_injectionassembled context 在何处变为可见的记录。
context_compaction用更短 summary 或 digest 替换大上下文。
context_summarysummary content、coverage、loss notes、validation 与 refresh policy。
missing_context已知 gaps、blockers、questions 与 requested sources。
context_eventcontext 操作的生命周期事件 envelope。

Context envelope

每个导出的 context_envelope 应包含:

字段要求
schema_version必填,Agent Context schema version。
context_id必填,此 context snapshot 的稳定 id。
scope必填:turntasksessiontool_invocationreviewhandoffcustom
lifecycle必填,生命周期状态。
created_at必填,时间戳。
producer推荐,producer id 与 version。
actor_refs推荐,user、agent、model、peer 或 service actors。
runtime_refs推荐,session、thread、turn、task、queue 或 execution refs。
surface_refs推荐,指向 context_surface
item_refs推荐,指向 selected 或 injected context items。
selection_refs推荐,指向 selection records。
budget_ref推荐,指向 budget/window decision。
assembly_refs推荐,指向 target-specific assemblies。
injection_refs推荐,指向 target-specific injections。
compaction_refs当 summary 或 compaction 影响当前 context 时推荐。
missing_context_refs当存在已知 context gaps 时推荐。
policy_refs当 permission、redaction、retention 或 export rules 生效时推荐。
evidence_refs当 context 被 review、replay、export 或 audit 时推荐。
telemetry_refs推荐,trace/span/log/metric correlation refs。

生命周期

Context records 应使用这些生命周期状态:

状态含义
draft正在组装,尚未最终确定。
available候选上下文存在,但不一定被选中。
selected已为某个 scope 选中,但可能还未预算或组装。
assembled已按 target-specific 结构排序。
injected已对 model、tool、UI、runtime、user、reviewer 或 peer agent 可见。
compacted已被 summary 或 digest 替换。
redacted敏感部分已被移除或遮蔽。
expired因 freshness、retention 或 source state 改变而失效。
archived仅用于历史或审计。

Context items

context_item 应包含 item_idcontext_kindtitlecontent_modecontentcontent_refmime_typelanguagesource_refstoken_estimatebyte_sizefreshnesstrust_levelsensitivityredaction_statevisibilityprioritycreated_atmetadata

content_mode 应为:inlinerefsummaryembedded_resourceresource_linkartifact_reftool_result_refopaque

大体积、可变、私密或二进制内容应优先用引用,不要直接嵌入。

Source refs

context_source_ref 应用 source_idurisource_kindselectordigestauthorityprovenance_refsexternal_mappingslicenseretrieved_atmodified_atmetadata 保留来源身份。

Selectors 可以使用 text quote、text position、byte range、line range、JSON Pointer、CSS selector、XPath、page region、media time range 或 custom selector types。实现应让 selector 足够稳定,以支持 evidence review 与 replay。

Selection and ranking

context_selection 应包含 selection_idsurface_idqueryintentcandidate_item_refsselected_item_refsomitted_item_refsranking_signalsselection_policybudget_refrationaleactor_refmodel_refcreated_atmetadata

Omitted context 是一等事实。如果一个 item 可用但未被选中,selection record 应说明原因:budget、低相关性、source stale、policy block、重复覆盖、不支持的 media、privacy risk 或 permission missing。

Budget and window

context_budget 应包含 budget_idtargetmax_tokensreserved_tokensmax_bytesmax_itemsactual_tokensactual_bytesactual_itemsoverflow_strategytruncation_recordswindow_segmentscreated_at

初始 overflow_strategyrejecttruncate_tailtruncate_middlesummarize_oldestsummarize_low_prioritydefer_to_retrievalask_for_choicepolicy_blockcustom

Assembly and injection

context_assembly 应包含 assembly_idtargetordered_blockswrapping_policyseparator_policyvisibilitybudget_refsource_item_refsredaction_statecreated_at

context_injection 应包含 injection_idassembly_idtargetinjection_pointnative_idvisibilityfinal_refhashcreated_atmetadata

初始 injection_pointsystem_promptdeveloper_promptmessage_historyuser_message_appendixtool_argumenttool_visible_resourceruntime_metadataui_panelreview_exportpeer_agent_messageartifact_inputcustom

Compaction and summaries

context_compaction 应包含 compaction_idscopesource_item_refssummary_refmethodtriggercoverageloss_notesvalidationreplacement_policycreated_atmetadata

初始 methodextractive_summaryabstractive_summarystructured_digestrolling_summarysemantic_memory_updatehuman_curated_summaryprovider_context_editingcustom

Compaction 不应静默擦除 source context。它应该记录替换了什么、为什么替换、如何 refresh,以及引入了哪些不确定性或损失。

Missing context

missing_context 应包含 missing_idscopequestionneeded_forseveritycandidate_sourcesblocked_actionsrequested_fromstatusresolution_refscreated_atmetadata

初始 severityinfolowmediumhighblocking

兼容的 UI、runtime 或 peer-agent bridge 可以把 missing_context 转成用户问题、retrieval request、tool invocation、policy request 或 peer-agent task。

Policy and redaction

Agent Context 记录 policy 事实,但不做 policy decision。Context records 应通过 policy_refs 链接到 policy decisions,并在相关位置记录 sensitivityretention_hintredaction_stateredaction_methodredacted_by

初始 redaction_statenonemaskedremovedsummarizedencrypted_refpolicy_blockedunknown

外部映射

Agent Context 应保留 native ids,而不是替换它们。

Native sourceMapping fields
MCPserver_idmcp_session_idresource_uriresource_templateprompt_nameroot_urijsonrpc_request_id
A2Aagent_card_urltask_idcontext_idmessage_idpart_idartifact_idskill_id
OpenTelemetrytrace_idspan_idevent_nameconversation_idsystemoperation_nametoken_usage
Model APIresponse_idmessage_idprompt_cache_keytool_call_idinput_tokenscached_input_tokens
Web Annotationtargetselector_typestartendexactprefixsuffix
W3C PROVentityactivityagentwasDerivedFromwasAttributedTowasGeneratedBy
CloudEventsidsourcetypesubjecttimedatacontenttype
JSON Schema$id$schema$reftypepropertiesrequiredadditionalProperties

事件类别

兼容实现应发出或导出这些事件类别:

  • context.surface.created
  • context.surface.updated
  • context.item.added
  • context.item.updated
  • context.item.removed
  • context.selection.started
  • context.selection.completed
  • context.budget.applied
  • context.assembly.created
  • context.injection.applied
  • context.compaction.started
  • context.compaction.completed
  • context.summary.created
  • context.missing.detected
  • context.missing.requested
  • context.missing.resolved
  • context.redaction.applied
  • context.exported

兼容性要求

兼容的 Agent Context 实现应:

  1. 为重要 turn、task、tool call 与 handoff 导出 context envelopes。
  2. 保留 native source ids 与 protocol ids。
  3. 在 selection 非平凡时记录 selected 与 omitted context。
  4. 在上下文受限时记录 token 或 size budgets。
  5. 分开记录 assembly 与 injection target。
  6. 记录 compaction sources 与 summary replacement facts。
  7. 当 Agent 知道输入缺口会影响质量或安全时记录 missing context。
  8. 通过 refs 连接 policy、evidence、artifact、tool、runtime、UI、knowledge 与 telemetry facts,而不是嵌入完整外部对象。

Draft standard for portable agent context surfaces, selection, budgets, injection, compaction, and missing-context facts.