llm: add dynamic tool loading (DTL) — Kimi system-tools + Anthropic tool-reference
Nightly Build / build (push) Successful in 6m51s

Replace the old session_mcp_grants/stack_mcp_grants table pair with
a single activated_tools table that anchors each activation at the
assistant message_id that triggered it. The durable write moves from
the activate_tools tool itself to the round loop (handle_tool_call),
which has the message_id the DTL serializer positions injected tool
blocks against.

Introduce DtlMode (None / AnthropicToolReference / KimiSystemTools),
resolved per model from capabilities (opt-in via tool_search)
combined with the provider's dtl_format(). The message builder inserts
Kimi system {tools} blocks at the activation position, or emits
Anthropic tool_reference markers on the tool result. The tool-def
surface (all_tool_defs) switches shape: Anthropic declares everything
deferred; Kimi omits activated tools from the top-level array (system
takes over); None keeps the old grant-set logic.

Anthropic client: accept structured system arrays (cache_control on
the static block when DTL is active), carry defer_loading through
conversion, emit tool_reference blocks on result messages. Prompt
caching enabled exactly when DTL is active (anthropic provider).

MCP server list in the prompt is now a static catalogue (not split
Available/Active) — the split invalidated the cache on every activation.
Groundwork for providers.yaml dtl: key; Moonshot/Kimi providers wired
with kimi_system_tools and the k3* enrich now adds tool_search.
Compactor re-anchors activations whose message was compacted away.
This commit is contained in:
2026-07-24 20:48:04 +01:00
parent 3c52587dee
commit d1d0a2af26
21 changed files with 579 additions and 226 deletions
+5 -1
View File
@@ -14,6 +14,8 @@
# base_url_overridable: the DB instance's base_url overrides this default
# api_key: required | optional | none (default: required)
# prompt_cache: true | false (default: false)
# dtl: DTL wire format for this provider's models that carry
# the `tool_search` capability: kimi_system_tools (default: none)
# ui: { color, icon, description } (color/icon required)
# fields: UI form fields [{ key, label, required, secret }]
# models: remote catalog config — omit to disable listing:
@@ -46,6 +48,7 @@ providers:
- id: moonshot
name: "Moonshot AI pay-as-you-go"
base_url: "https://api.moonshot.ai/v1"
dtl: kimi_system_tools
ui:
color: "#2563eb"
icon: "bi-moon-stars"
@@ -64,6 +67,7 @@ providers:
- id: moonshot_code
name: "Moonshot AI Kimi Code"
base_url: "https://api.kimi.com/coding/v1"
dtl: kimi_system_tools
ui:
color: "#000000"
icon: "bi-code-slash"
@@ -81,7 +85,7 @@ providers:
# Fills the metadata the endpoint may omit (endpoint values always win):
# k3 → 1M context + native vision and video input; kimi-for-coding → 256k.
enrich:
- { match: "k3*", context_length: 1048576, vision: true, add_capabilities: [video] }
- { match: "k3*", context_length: 1048576, vision: true, add_capabilities: [video, tool_search] }
- { match: "kimi-for-coding*", context_length: 262144 }
reasoning:
# k3 exposes a graded reasoning_effort ("disabled" routes to K2.6);