WeKnora/internal/agent/tools
young1lin 29bec4204a fix(agent/tools): sort function definitions for deterministic ordering
`ToolRegistry.GetFunctionDefinitions` and `ListTools` previously ranged
over the internal map directly. Go map iteration is intentionally
randomized, so the resulting `tools` array reshuffled on every request.

That reshuffling silently breaks provider-side prompt caches that key on
a byte-level prefix match — most visibly Qwen explicit caching, which
requires the messages (system + tools + history) to be byte-identical up
to the `cache_control` marker. With random ordering the serialized tools
block changes every call, so the cache prefix never matches and the
hit rate stays at 0%.

Sort by tool name in both functions. Output is now byte-stable across
calls and `cache_control: ephemeral` can actually take effect.

Tests in registry_test.go cover:
- Deterministic ordering across 50 iterations
- JSON byte-stability across 20 iterations (the real motivation)
- Field projection (Name / Description / Parameters)
- Empty registry returns `[]` not `null`
- ListTools sorting
- First-wins duplicate registration policy (GHSA-67q9-58vj-32qx)
2026-05-25 16:47:14 +08:00
..
capabilities.go fix(agent): exclude wiki-only KBs from quick-answer (RAG) mode 2026-05-12 16:27:28 +08:00
data_analysis.go fix(data-analysis): capture LOCAL_STORAGE_BASE_DIR at init time (#1040) 2026-05-06 11:19:56 +08:00
data_analysis_duckdb_test.go test(agent): add end-to-end DuckDB excel tests and fix sheet enumeration (#1007) 2026-04-24 19:57:56 +08:00
data_analysis_materialize_test.go fix(agent): materialize knowledge files to temp path for DuckDB (#1007) 2026-04-24 19:57:56 +08:00
data_analysis_test.go feat: data_analysis sql validation & type processing 2026-04-28 23:47:34 +08:00
data_schema.go feat: add organization management features 2026-02-09 11:40:25 +08:00
database_query.go feat(database): enhance DatabaseQueryTool with search scope filtering 2026-03-31 10:52:01 +08:00
definitions.go feat: Introduce Wiki Fixer agent and related functionalities 2026-04-22 21:18:08 +08:00
exec_context.go fix(agent): 加固 MCP 工具人审批的跨实例与并发语义 2026-05-10 22:57:12 +08:00
final_answer.go fix(agent): terminate ReAct loop on final_answer regardless of arg parse success 2026-04-23 19:36:28 +08:00
final_answer_test.go fix(agent): terminate ReAct loop on final_answer regardless of arg parse success 2026-04-23 19:36:28 +08:00
get_document_info.go feat: Update agent type presets and prompt templates for improved knowledge base handling 2026-04-22 21:18:34 +08:00
grep_chunks.go refactor(agent): simplify grep_chunks tool to a single regex query 2026-05-20 19:34:27 +08:00
json_repair.go feat: Enhance agent retrieval strategies and regex handling 2026-04-22 21:18:21 +08:00
json_repair_test.go feat: Enhance agent retrieval strategies and regex handling 2026-04-22 21:18:21 +08:00
knowledge_search.go refactor(api): drop deprecated tenant ConversationConfig field and KV write path 2026-05-18 17:28:58 +08:00
list_knowledge_chunks.go feat: Update agent type presets and prompt templates for improved knowledge base handling 2026-04-22 21:18:34 +08:00
mcp_tool.go fix(agent): 加固 MCP 工具人审批的跨实例与并发语义 2026-05-10 22:57:12 +08:00
mcp_tool_image_test.go feat: auto-describe MCP tool result images via VLM 2026-03-25 21:38:15 +08:00
mcp_tool_test.go feat(tests): add comprehensive tests for MCPTool functionality 2026-03-25 22:08:29 +08:00
normalize_id.go feat(agent): enhance tool execution and message sanitization 2026-03-25 22:08:29 +08:00
normalize_id_test.go feat(agent): enhance tool execution and message sanitization 2026-03-25 22:08:29 +08:00
param_cast.go refactor(prompt): streamline context handling in templates 2026-03-25 22:08:29 +08:00
param_cast_test.go refactor(prompt): streamline context handling in templates 2026-03-25 22:08:29 +08:00
param_validate.go feat(agent): implement memory consolidation and context management 2026-03-25 22:08:29 +08:00
param_validate_test.go feat(agent): implement memory consolidation and context management 2026-03-25 22:08:29 +08:00
query_knowledge_graph.go fix(agent): correct graph config reporting 2026-05-06 11:04:55 +08:00
query_knowledge_graph_test.go test(agent): expand graph query regression fixture 2026-05-06 11:04:55 +08:00
registry.go fix(agent/tools): sort function definitions for deterministic ordering 2026-05-25 16:47:14 +08:00
registry_test.go fix(agent/tools): sort function definitions for deterministic ordering 2026-05-25 16:47:14 +08:00
sanitize_messages.go feat(agent): enhance tool execution and message sanitization 2026-03-25 22:08:29 +08:00
sanitize_messages_test.go feat(agent): enhance tool execution and message sanitization 2026-03-25 22:08:29 +08:00
sequentialthinking.go refactor(prompt): streamline context handling in templates 2026-03-25 22:08:29 +08:00
skill_execute.go feat: optimize security and deployment of agent skills 2026-02-04 20:08:49 +08:00
skill_read.go feat: support agent skills 2026-02-04 20:08:49 +08:00
strip_think.go refactor(agent): remove query display from DatabaseQuery component and update tool result structure 2026-03-25 22:08:29 +08:00
strip_think_test.go refactor(agent): remove query display from DatabaseQuery component and update tool result structure 2026-03-25 22:08:29 +08:00
todo_write.go feat: use language-neutral English prompts for multilingual LLM responses 2026-03-06 21:08:12 +08:00
tool.go feat: use language-neutral English prompts for multilingual LLM responses 2026-03-06 21:08:12 +08:00
truncate.go feat(agent): implement memory consolidation and context management 2026-03-25 22:08:29 +08:00
truncate_test.go feat(agent): implement memory consolidation and context management 2026-03-25 22:08:29 +08:00
web_fetch.go fix(security): support IPv6 in SSRF validation via whitelist mechanism 2026-03-31 20:45:15 +08:00
web_search.go fix(web-search): normalize default tenant web search config at runtime 2026-04-30 15:28:35 +08:00
wiki_delete_page.go feat: Implement wiki editing functionalities and UI components 2026-04-22 21:18:08 +08:00
wiki_flag_issue.go feat: Introduce `wiki_flag_issue` tool for reporting wiki page issues 2026-04-22 21:17:38 +08:00
wiki_index_overview_test.go perf(wiki): move ingest log to event table and index to on-demand API 2026-05-08 21:48:52 +08:00
wiki_read_issue.go feat: Introduce Wiki Fixer agent and related functionalities 2026-04-22 21:18:08 +08:00
wiki_read_source_doc.go feat: Enhance agent retrieval strategies and regex handling 2026-04-22 21:18:21 +08:00
wiki_rename_page.go feat: Implement wiki editing functionalities and UI components 2026-04-22 21:18:08 +08:00
wiki_replace_text.go feat: Implement wiki editing functionalities and UI components 2026-04-22 21:18:08 +08:00
wiki_tools.go perf(wiki): move ingest log to event table and index to on-demand API 2026-05-08 21:48:52 +08:00
wiki_tools_test.go feat: Add Wiki Researcher agent and system prompt for enhanced knowledge retrieval 2026-04-22 21:17:35 +08:00
wiki_update_issue.go feat: Introduce Wiki Fixer agent and related functionalities 2026-04-22 21:18:08 +08:00
wiki_write_page.go feat: Implement wiki editing functionalities and UI components 2026-04-22 21:18:08 +08:00