fix(agent): narrow background-review tool schema for local providers - #39997
fix(agent): narrow background-review tool schema for local providers#39997JimStenstrom wants to merge 1 commit into
Conversation
|
Thanks for isolating the local-provider schema mismatch. Problems
Suggested changes
This is an automated hermes-sweeper review. |
The background skill/memory review fork inherits the parent's full tools[] schema so the request body stays byte-identical for the Anthropic/OpenRouter prefix cache, then restricts dispatch via a runtime whitelist. That tradeoff is sound for cache-backed providers but strictly wasteful for a local endpoint: there is no prefix cache to preserve, and a weaker local model imitates the snapshot history (write_file/read_file/terminal calls) and burns turns hitting the dispatch deny-wall. When the resolved review runtime's base_url is a local endpoint (is_local_endpoint), advertise only the toolsets the review can actually use. Classification is keyed on the resolved review runtime (_rt), so an auxiliary.background_review route is judged by the endpoint that actually serves the review, not the parent's. The narrowed set mirrors the runtime whitelist's memory gate: memory is advertised only when the profile has memory or the user profile enabled, so a memory-disabled profile never sees the memory tool re-granted at schema level. Remote providers are unchanged — parent toolsets are preserved for prefix-cache parity, and the runtime whitelist still applies as a belt-and-suspenders net.
1c6a6d0 to
55390c3
Compare
|
Reworked per the review — both points were right, thanks.
Branch rebased onto current main; 9/9 in |
Draft 1 — comment on issue #39996 AND PR #39997 (toolset-narrowing for local providers)Target: #39996 Confirming this from an independent deployment. We hit the exact same failure mode running background_review with the fork routed to a local llama.cpp backend: advertising the parent's full tool schema to the local model caused an outright request failure rather than just wasted turns — one specific tool schema (an MCP plugin's We independently wrote effectively the same fix locally (narrow One thing worth adding to the PR description: because a local backend can build a full JSON-grammar for every schema in Happy to test #39997 against our setup if that'd help move it forward — it's been open since June 5 with no update since July 14. |
What does this PR do?
Narrows the background-review fork's advertised tool schema to
memory+skillswhen the parent runs on a local endpoint (omlx / Ollama / llama.cpp), where there is no prefix cache to preserve. On a local endpoint, advertising the parent's full toolset buys nothing and actively harms: a weaker local model imitates the snapshot history (write_file/terminal/etc.) and burns review turns hitting the dispatch deny-wall (Background review denied non-whitelisted tool: …). Remote/cache-backed providers (Anthropic, OpenRouter) keep full-toolset inheritance sotools[]stays byte-identical for prefix-cache parity (the behavior established by #29704). The gate reuses the existingis_local_endpoint(base_url)predicate; the runtime whitelist remains as the dispatch guard in both cases.Related Issue
Fixes #39996
Type of Change
Changes Made
agent/background_review.py— in_run_review_in_thread, compute_review_enabled_toolsets/_review_disabled_toolsetsviais_local_endpoint(base_url): local →["memory","skills"]/None; otherwise → the parent'senabled_toolsets/disabled_toolsets(unchanged). Comment updated to explain the cache-vs-local tradeoff.tests/run_agent/test_background_review_toolset_restriction.py— two tests:test_background_review_narrows_toolset_for_local_endpoint(local base_url → fork gets["memory","skills"]/None) andtest_background_review_keeps_parent_toolset_for_remote_endpoint(Anthropic base_url → fork still mirrors parent toolsets, cache parity preserved).How to Test
scripts/run_tests.sh tests/run_agent/test_background_review_toolset_restriction.py— passes.customprovider at a local server, run a session with file edits / terminal calls so a bg-review fires. Before: the review session emits non-memory/skill tool calls that hitBackground review denied non-whitelisted tool: …. After: the fork advertises only memory/skills, so those denied calls stop.tools[]is unchanged (cache parity).Checklist
Code
fix(agent):)scripts/run_tests.shand they passDocumentation & Housekeeping