feat(agent): 新增通用 {{.Now}} 提示词变量(每轮实时渲染)
- 各 agent 渲染路径(chat/worker/mainagent/goals/planner)统一提供 Now(nowStr());
自定义会话 agent 每次触发都会重新 renderSystem,故 {{.Now}} 每轮实时刷新
- server 端 globalPromptVars + withGlobalVars:在保存校验/变量列表/预览/详情放行
{{.Now}},否则引用它的自定义提示词会被 validateTemplate 拒绝
- 无 DB 迁移(handler 层注入通用变量,不动 agent_prompt_vars 表)
- 用途:配合固定的开始时间戳相减,判断"已运行多久/是否进入最后N小时"
- 新增 agent/prompt_now_test.go:{{.Now}} 渲染实时时间、未知变量安全回退
This commit is contained in:
1 parent
7afff7e5f5
commit
7064216188
8 files changed
+86
-14
No files matched your search
+5
-4
@@ -58,12 +58,13 @@ func chatWorkDirSpec(workDir string) string {
|
||||
// chatSystem renders the DB-managed prompt body for agentKey. Custom agents have
|
||||
// no per-key in-code default, so DefaultAssistantPrompt is the render fallback.
|
||||
func chatSystem(agentKey, workDir string) string {
|
||||
return renderSystem(agentKey, DefaultAssistantPrompt, chatVars{}) + chatWorkDirSpec(workDir)
|
||||
return renderSystem(agentKey, DefaultAssistantPrompt, chatVars{Now: nowStr()}) + chatWorkDirSpec(workDir)
|
||||
}
|
||||
|
||||
// chatVars carries no runtime variables today — a custom prompt referencing any
|
||||
// {{.X}} simply fails to render and falls back to DefaultAssistantPrompt.
|
||||
type chatVars struct{}
|
||||
// chatVars carries the runtime variables a custom agent's prompt may reference.
|
||||
// Now (server wall-clock, refreshed each turn) is the only one today; any other
|
||||
// {{.X}} fails to render and falls back to DefaultAssistantPrompt.
|
||||
type chatVars struct{ Now string }
|
||||
|
||||
// Chat runs ONE turn of a conversation with the agent identified by agentKey,
|
||||
// resuming prior history keyed by sessionID. maxTurns is the per-turn agent step
|
||||
|
||||
Reference in new issue
Block a user