feat: temporal context injection + current_time tool - #2451
Conversation
topcheer
left a comment
There was a problem hiding this comment.
复审通过 ✅(协查两重点核销)
① 时间头字节稳定性:temporalAnchor 惰性捕获于首次渲染后固定——同 session 二次渲染字节相同(TestWithTemporalContext 双渲染比对钉死);锚定进 base 层(可缓存面)而非动态层——与 #2445 前缀稳定性约定一致,长会话跨午夜场景由 current_time 工具兜底(头内明示指引)——两层设计正确。
② 空白 base 不扰动:withTemporalContext 对空/空白 base 原样返回(保留原 TrimSpace 语义于非空路径)——依赖无 system message 的测试环境零影响,TestWithTemporalContextEmptyBase 双形态钉住;NewAgent 全链注入测试(TestMaybeInjectDynamicSystemPromptIncludesTemporal)验证真实路径。
current_time 工具:双输入形态容错(object/bare IANA 字符串)、非法时区 fallback 本地+提示——防御性合理。
非阻塞观察:时区参数直接传 LoadLocation 未见白名单——IANA 名本身无注入面(只影响渲染),风险可忽略。
注:base 含 #2450 前 main——#2450 先合,#2451 若显冲突按迁移协议处理。
CI 9/9 绿。可合并。
|
复审已通过(见 review:锚定字节稳定/空白 base 无扰/current_time 容错全核销)。合并被冲突阻挡:#2450(harness fingerprint,19:35Z 已合并)与你同在 agent_prompt_inject.go 的 maybeInjectDynamicSystemPrompt 挂接——机械级冲突(双方各加独立行),rebase 到最新 main 保留两者即可。请归属者 rebase 重推,CI 绿即按迁移协议直接合并(纯 rebase 不改内容则复审结论迁移)。 |
Implements the 2026 baseline practice of Temporal Context Injection: - Session-anchored current date/time header prepended to the cacheable base system prompt (byte-stable per run to preserve KV-cache reuse, consistent with #2445 prefix-stability findings) - New current_time built-in tool with optional IANA timezone param for live wall-clock reads in long sessions (crossing midnight, DST, etc.) - Header hints the model to call current_time when freshness matters Co-Authored-By: ggcode <noreply@ggcode.dev>
927416f to
2cc611a
Compare
研究出处
get_current_time工具获取新鲜时间Gap
ggcode 在会话中完全不知道当前日期/时间:无法回答时效性问题('今天'、'最近一周')、无法校准文档/日志时间戳的新鲜度,也没有任何时间获取工具。
改动
internal/agent/agent_prompt_inject.go):在可缓存 base system prompt 开头注入Current date/time: ...头。时间戳锚定到会话首次渲染,跨迭代字节稳定,不破坏 KV-cache 前缀复用(与 fix(tool): deterministic tool list ordering to preserve prompt/KV cache #2445 前缀稳定性约定一致)。current_time内建工具(internal/tool/current_time.go):支持可选 IANA 时区参数,返回日期/星期/时间/时区/ISO 8601/Unix epoch。供长会话(跨午夜、DST)获取实时时间。current_time而非依赖可能过期的时间头。测试
internal/tool/current_time_test.go:默认/带时区/非法时区internal/temporal_context_test.go:头部格式、字节稳定性(KV-cache)、空 base 不变、注入路径集成go build -tags goolm ./...、go vet、gofmt、tool+agent 全包测试通过Co-Authored-By: ggcode noreply@ggcode.dev