WeKnora/internal/agent
Jundong Zhang 40eb34bc84
fix(agent): align web_search count limit with the configured maximum (#4011)
* fix(agent): align web_search count limit with the configured maximum

count 的参数描述写死了 "at most 20",而实际生效的上限来自 agent 配置
(web_search_max_results,常见值 7)。模型按描述填 8/20 就会被 Execute 里的
"count must be between 1 and N" 硬拒——那一轮连 provider 都没被调用,而且在
trace 里与真正的故障同为 span error,无法区分。

- count 的静态描述去掉写死的 20;NewWebSearchTool 再按实际生效的 maxResults
  动态改写 schema 描述(解析失败原样返回,不影响工具可用性)
- count 超范围由"整轮失败"改为"截断到上限",输出里附一句纠正提示,日志降为 Warn。
  同类标量 search_knowledge.limit / search_memory.limit 走的也是截断;且工具本来
  就会静默返回少于 count 条(结果被 URL 校验过滤时 break),同一字段不该两套策略

行为变更:count 传 0/负数/超过上限不再返回 Success=false,而是按上限执行。
TestSearchOptionsAndExplicitPageContent 原先把 count 与非法过滤值并列断言
"必须失败且不得调用 provider",该断言已相应调整,新行为由
TestAgentWebSearchClampsCountToConfiguredMaximum 覆盖。

测试:go test ./internal/agent/tools/... -count=1

* fix(agent): clamp only an over-maximum web_search count

count is documented as 1..maximum, so a value below 1 is a malformed
argument rather than a near miss: reject it before the provider runs and
restore the previous message ("count must be between 1 and N"). Only a
count above the configured maximum is clamped, which keeps the change
scoped to the near-miss case it was meant to fix.

The correction now travels in Data as well as Output. web_search enables
sourceOutput, so once there is at least one row the model reads the
rendered retrieval block, which is rebuilt from Data["results"]; the note
written to Output never reached it. annotateWebSearchNotes restates the
clamp as <count_clamped> inside that block, the same way
annotateSearchNotes surfaces <omitted> and <subset>. The zero-result early
return carries the note too, instead of returning before it is built.

Also documents the clamping in website-docs and moves the added comments
back to English, keeping only the ones that describe what the code does.
2026-10-10 10:27:52 +08:00
..
approval refactor(agent): discover and invoke MCP tools on demand 2026-09-08 12:01:36 +08:00
compaction feat: index and recall images with multimodal embedding models (#3683) 2026-10-08 18:19:53 +08:00
skills feat(lite): install and run skills on the host (#3661) 2026-09-24 21:30:34 +08:00
token refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
tools fix(agent): align web_search count limit with the configured maximum (#4011) 2026-10-10 10:27:52 +08:00
act.go fix(agent): recover tool panics instead of crashing the server 2026-09-25 18:22:14 +08:00
act_order_test.go fix(agent): recover tool panics instead of crashing the server 2026-09-25 18:22:14 +08:00
calibration.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
calibration_test.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
checkpoint.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
const.go fix(models): keep Retry-After on HTTPError and honour it in agent LLM retries 2026-09-29 01:22:15 +08:00
const_test.go fix(browser): support human handoffs and resume interrupted tasks 2026-09-11 23:56:13 +08:00
context_debug.go refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
engine.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
engine_image_test.go feat: auto-describe MCP tool result images via VLM 2026-03-25 21:38:15 +08:00
engine_memory_test.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
engine_test.go fix(llm): treat cut-off streams as broken and tighten LLM retries 2026-09-25 18:22:14 +08:00
finalize.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00
grounding_prompt.go fix(agent): search bound knowledge bases before answering, and pass suggested-question origins (#3400) 2026-09-18 17:00:47 +08:00
grounding_prompt_test.go fix(agent): search bound knowledge bases before answering, and pass suggested-question origins (#3400) 2026-09-18 17:00:47 +08:00
knowledge_base_profile_prompt_test.go feat(knowledge): derive knowledge base descriptions from document profiles (#3370) 2026-09-17 22:21:55 +08:00
langfuse_test.go refactor(agent): introduce modelcontext registry and fix handle-codec bugs 2026-07-27 11:05:43 +08:00
length_truncation_test.go fix(agent): end the turn when the completion cap truncates an answer (#3449) 2026-09-20 13:17:50 +08:00
mcp_exposure_test.go fix(mcp): normalize JSON-encoded argument envelopes 2026-09-09 16:11:52 +08:00
mcp_proxy_test.go fix(mcp): normalize JSON-encoded argument envelopes 2026-09-09 16:11:52 +08:00
observe.go refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
observe_test.go fix(agent): search bound knowledge bases before answering, and pass suggested-question origins (#3400) 2026-09-18 17:00:47 +08:00
prompt_composition_test.go fix(agent): search bound knowledge bases before answering, and pass suggested-question origins (#3400) 2026-09-18 17:00:47 +08:00
prompts.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
prompts_browser.go fix(browser): align BrowserSkill 0.3.0 and repair task lifecycle 2026-09-17 11:54:12 +08:00
prompts_browser_test.go feat(browser): polish connection settings, open tasks in a new window, and streamline prompts (#3193) 2026-09-11 21:28:58 +08:00
prompts_shell_test.go feat(sandbox): run unpinned Lite sessions on the host OS sandbox (#3549) 2026-09-22 19:35:03 +08:00
prompts_wiki.go fix(wiki): 整页重写被补全预算截断时续写,续写用尽则拒绝写回(长名单 146→119) (#3582) 2026-09-23 12:17:07 +08:00
prompts_wiki_test.go refactor(agent): introduce modelcontext registry and fix handle-codec bugs 2026-07-27 11:05:43 +08:00
retry_delay_test.go fix(models): keep Retry-After on HTTPError and honour it in agent LLM retries 2026-09-29 01:22:15 +08:00
steer.go fix(chat): preserve steering continuity and composer focus 2026-09-09 20:15:23 +08:00
steer_test.go fix(chat): preserve steering continuity and composer focus 2026-09-09 20:15:23 +08:00
terminal_event_test.go fix(agent): stop emitting terminal answer events for retryable empty stops 2026-09-14 21:02:15 +08:00
think.go fix(agent): 工具自起 goroutine 的 panic 自行兜底,MCP 预热不再带走进程 (#3846) 2026-10-08 01:24:36 +08:00
tool_goroutine_panic_test.go fix(agent): 工具自起 goroutine 的 panic 自行兜底,MCP 预热不再带走进程 (#3846) 2026-10-08 01:24:36 +08:00
tool_images.go feat: judge image hits by their image in rerank and show them to vision models (#4013) 2026-10-09 13:01:48 +08:00
tool_images_test.go feat: judge image hits by their image in rerank and show them to vision models (#4013) 2026-10-09 13:01:48 +08:00
turn_usage_test.go feat(agent): size agent history by the window and calibrate token estimates (#3413) 2026-09-18 22:51:31 +08:00