From d185201ee8fc492d054fe72b9aa2ec3af970fc87 Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Thu, 10 Sep 2026 15:41:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(ctx):=20ContextPolicy=20tool=20=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E7=AD=96=E7=95=A5(=C2=A713.8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - SDK ToolDef 加 ContextPolicy string(默认 none / 可设 prune) - StageAfterToolcall 后检查工具 ContextPolicy=prune → RelevanceContext.Prune - 所有现有测试通过 --- internal/agent/core/process.go | 6 ++++++ third_party/homeagent-sdk/sdk/plugin.go | 1 + 2 files changed, 7 insertions(+) diff --git a/internal/agent/core/process.go b/internal/agent/core/process.go index 39f9333..529a036 100644 --- a/internal/agent/core/process.go +++ b/internal/agent/core/process.go @@ -305,6 +305,12 @@ func (a *Agent) process(input string, stageCtx *sdk.StageContext) (response stri result = r } } + // ContextPolicy: prune 工具调用后执行上下文裁剪(§13.8) + if def := a.stageHost.ToolDef(tc.Name); def != nil && def.ContextPolicy == "prune" { + if a.context != nil { + a.context.Prune(result, 20, a.docStore) + } + } msgContent := "" if contentOnce { diff --git a/third_party/homeagent-sdk/sdk/plugin.go b/third_party/homeagent-sdk/sdk/plugin.go index ebd234d..8e70255 100644 --- a/third_party/homeagent-sdk/sdk/plugin.go +++ b/third_party/homeagent-sdk/sdk/plugin.go @@ -106,6 +106,7 @@ type ToolDef struct { Parameters map[string]interface{} `json:"parameters"` NoMemory bool `json:"no_memory,omitempty"` // 此工具输出不参与记忆计算,但原文保留 Cleaner func(string) string `json:"-"` // 计算层过滤函数,不改原文;仅在向量化/jieba/蒸馏时调用 + ContextPolicy string `json:"context_policy,omitempty"` // 工具上下文策略:"none"(默认) / "prune" } // IOInjector provides methods for injecting input and interrupts into the agent pipeline.