mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-06-04 13:30:32 +08:00
`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)