Add Runtime.DynamicIdentityHint, a live, per-turn identity fact

Runtime.StaticSystemPrompt is cached and reused verbatim every turn —
right for anything that doesn't change mid-conversation, wrong for a
fact a caller needs to update live (e.g. after a runtime model switch)
and have the model actually notice. A model tends to just repeat what
it already told the user earlier in the same conversation over a
background instruction it read once near the top of a large cached
block, so updating only the static prompt after a switch left the
model insisting it was still whatever it started as.

DynamicIdentityHint rides the same per-turn (uncached) system prompt
slot Run/RunTurn already use for the date line and KG hint, so setting
it takes effect on the very next turn with the same recency the model
grants its own last statement.
This commit is contained in:
sausheong committed 2026-09-07 00:15:23 +08:00
1 parent f624e4c7bd
commit 0ccfdb2a24
5 files changed
+41 -14

No files matched your search

+14 -1
View File
@@ -85,6 +85,19 @@ type Runtime struct {
// prompt cache hits.
StaticSystemPrompt string
// DynamicIdentityHint is caller-set text re-sent, uncached, in every
// turn's system prompt (see buildDynamicSystemPromptSuffix) — unlike
// StaticSystemPrompt, safe to mutate mid-conversation (e.g. after a
// live model switch) and have the very next turn pick it up. Exists
// because a fact baked only into the cached static prompt competes
// poorly against the model's own prior statements already visible in
// message history: asked "which model are you" a second time, a model
// tends to just repeat what it told the user earlier in the same
// conversation over a background instruction it read once at the top
// of a large cached block. Resending the fact fresh, every turn, gives
// it the same recency the model grants its own last answer.
DynamicIdentityHint string
// Permission gates tool execution at dispatch time. nil → allow-all.
Permission tool.PermissionChecker
@@ -437,7 +450,7 @@ func (r *Runtime) Run(ctx context.Context, userMsg string, images []llm.ImageCon
kgCh = nil
}
dynamicSuffix := buildDynamicSystemPromptSuffix(dateLine, kgContext)
dynamicSuffix := buildDynamicSystemPromptSuffix(r.DynamicIdentityHint, dateLine, kgContext)
staticText := r.StaticSystemPrompt
parts := []llm.SystemPromptPart{