Skip to content

fix(skills): a loaded skill brings the tools it declares - #3903

Closed
kovtcharov wants to merge 3 commits into
amd:mainfrom
kovtcharov:claude/fix-skill-tools-admission
Closed

kovtcharov wants to merge 3 commits into
amd:mainfrom
kovtcharov:claude/fix-skill-tools-admission

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Loading a skill used to leave the tools it declares out of the prompt, so the model had to spend an extra round trip on load_tools before doing anything. In a 168-run benchmark, load_skill github-triage was followed by a manual load_tools shell in almost every run (45 calls), and some runs failed before they got there. Now a skill's declared tools are admitted on every turn its instructions are in the prompt. That includes the shell tool whenever the skill grants a CLI such as gh, even if the skill forgot to list it. A skill whose instructions are hidden this turn, or that was unloaded, holds no tool slots.

Admission stays under the loader's existing tool cap. A skill that needs more tools than the free slots keeps the same ones each turn instead of rotating them. Tools from procedures recalled from memory still flow in unchanged, after the active skills' tools.

Fixes #3901

Test plan

  • pytest tests/unit/test_chat_dynamic_tools.py: new tests load the real github-triage skill and check the shell tool is admitted, the unload path, a skill hidden by the body filter, a grant-only skill, cap enforcement, and ordering and dedup with recalled procedures
  • pytest tests/unit/test_tool_loader_selection.py tests/unit/test_chat_tool_bundles.py tests/unit/test_skill_loader.py tests/unit/test_skill_sets.py tests/unit/test_starter_skills.py tests/unit/test_skill_binary_grants.py tests/unit/test_agent_lazy_skill_prompt.py tests/unit/test_memory_mixin.py tests/unit/test_skills_consume.py tests/unit/test_skill_discovery_integration.py all pass, including an over-cap skill request that stays stable across turns
  • Agent eval (gaia eval agent): runs in the self-hosted CI job once the branch is pushed to amd/gaia. This changes which tools reach the prompt, so it needs an eval before merge.

Loading a skill left its declared tools out of the prompt, so every
skill-driven task spent an extra round trip on load_tools (e.g.
load_skill github-triage followed by load_tools shell) before it could act.

The loaded skills' tools_required now feed the tool loader's SKILL signal,
ahead of recalled-procedure tools and deduped. A shell:execute:<binary>
grant also admits run_shell_command. Unloading a skill drops its
contribution, and admission stays cap-bound.

Fixes amd#3901
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions — but hold the merge until the eval runs

This makes a loaded skill's declared tools show up in the prompt immediately, so the model stops burning a round trip on load_tools first, and it hands a skill the shell tool whenever the skill was granted a CLI like gh. The fix reuses the tool loader's existing skill channel rather than inventing a new one, and the tests exercise the real github-triage skill instead of a stand-in — both good calls.

Two things to settle before merge:

  • The eval you already flagged. This changes which tools the model actually sees, which is exactly the class of change the project requires an eval for. The test plan lists it as pending, so this is a reminder, not a new finding.
  • Loaded skills now compete for a small, fixed number of tool slots — every turn, whether or not the skill is relevant to what the user just asked. On the chat agent's document profile there are only three slots to go around, so one skill that names four tools fills them all: the tools the current question actually needs get dropped, and the skill's own leftover tools swap in and out turn after turn. The flagship agent has more headroom, but loading two skills at once still eats most of it. Worth a conscious decision — either limit how much a single turn's skill list may claim, or only count skills whose instructions are actually in the prompt that turn.

Smaller: one user-facing doc still describes tools_required as purely informational, which is no longer the whole story.

Real-world evidence

N/A — no evidence bundle was produced for this run, and this environment has no pytest available, so I could not re-run the suite myself. The verdict rests on static review plus the test results reported in the PR description. Since the change only alters which tools reach the prompt (no new CLI/API/UI surface), the meaningful proof here is the pending agent eval plus a short transcript of loading a skill and having the next turn use its tools without a load_tools detour.

🔍 Technical details

Issues

🟡 Loaded-skill tools are admitted every turn, independent of the skill-body filter (hub/agents/chat/python/gaia_agent_chat/agent.py:729, src/gaia/agents/base/agent.py:1790)

_loaded_skill_tools() returns the union over all of _loaded_skills, and the SKILL tier in ToolLoader.select is cap-bound and admitted ahead of semantic candidates (tool_loader.py:326-349). Concretely, on DOC_CORE_TOOLS (11 core, dynamic_tools_max = 14) there are 3 dynamic slots, so a skill like coding (read_file, edit_file, search_file_content, search_code_index, execute_python_file) fills them: _pick_eviction_victim returns None because every loaded tool is either CORE or admitted-this-turn, so both the skill's remaining tools and every semantic candidate land in skipped_at_cap — for the whole session, not one turn. On the next turn the earlier skill tools are no longer admitted_this_turn, so they become eviction victims for the skill's remaining tools, which is per-turn prompt churn with no steady state. The flagship (dynamic_tools_max = 26, 13 core) is looser, but --skill-set documents (document-brief 6 + data-explore 4) already claims 10 of 13.

The asymmetry is the design question: skill bodies are re-selected per turn (_refresh_active_skill_filter), but skill tools are now unconditional. Aligning them is not a one-liner — _refresh_active_tool_filter runs before _refresh_active_skill_filter in Agent.process_query (agent.py:5052-5057), so _active_skill_filter is a turn stale at selection time. Options worth weighing: bound the per-turn skill contribution to a fraction of the dynamic slots, or reorder the two refreshes and scope admission to active skills. test_loaded_skill_tools_are_cap_bound pins the single-turn behaviour; nothing covers the cross-turn churn.

🟡 Agent eval required before merge — CLAUDE.md lists "tool registration … the JSON tool schema sent to Lemonade" as eval-gated, and this changes the per-turn tool set for every skill-driven task. Already tracked as the unchecked test-plan item; calling it out so it isn't lost.

🟢 Doc drift (docs/guides/composing-skills.mdx:76) — "it does not grant anything" is now incomplete: tools_required decides prompt admission for a loaded skill.

`tools_required` names registry tools the skill's recipe *consumes* — it does not
grant anything, but on an agent with dynamic tool selection a loaded skill's
`tools_required` are admitted into the next turn's prompt (and unloading it stops
that). A name your agent has not registered is logged at load time, so a
skill that cannot execute its own recipe is diagnosable rather than silently
useless.

🟢 "The tools it declares" is narrower than it reads — a skill that provides tools via tools.py (hub/skills/rss-digest, registered as <skill>/<tool> by register_skill_tools) still depends on a semantic match to reach the prompt. That matches #3901's stated scope; the docstring at agent.py:1793 could say tools_required explicitly so the next reader doesn't assume skill-provided tools are covered.

🟢 parsed_permissions() re-parses on every turn (agent.py:1799) — once per loaded skill per selection. The grant state is already materialised on the instance (granted_binaries, populated at load); reading that instead would avoid re-parsing permission strings on the hot path. Negligible today, worth knowing if skill sets grow.

Strengths

  • Reuses the existing CORE > SKILL > SEMANTIC channel rather than adding a parallel path, so cap behaviour, dedup, and the registry-absent drop all come for free — and the tool_loader.py docstring was updated to match the widened contract.
  • Tests load the real hub/skills/github-triage rather than a fixture, which is what catches a drift between the shipped skill and the admission logic; the unload test correctly calls reset_session() to show the signal is gone despite the monotonic loaded set.
  • The grant-only case (shell:execute:gh with no tools_required entry) is handled and tested — that was the second, easier-to-miss half of the issue.

…stop rotating

A loaded skill's tools used to take dynamic tool slots every turn, even on
turns its instructions were hidden, and a skill needing more tools than the
free slots swapped its own tools in and out each turn. Now only skills whose
body renders this turn feed the tool loader (the body filter runs first so it
is current), and a requested tool that is already loaded is held for the turn
instead of being evicted by the next pick. The shell-tool check reads the
skill's live binary grant rather than re-parsing its permissions every turn.
@github-actions github-actions Bot added the documentation Documentation changes label Sep 19, 2026
@kovtcharov

Copy link
Copy Markdown
Contributor Author

A skill's tools now take slots only on turns its instructions are in the prompt. A skill that needs more tools than the free slots keeps the same ones each turn instead of rotating them. The doc and docstring fixes are in, and the eval runs in the self-hosted CI job once a maintainer pushes the branch to amd/gaia.

🔍 Technical details

All in bf64e55e.

  • Skill tools claiming slots every turn: two parts.
    • _loaded_skill_tools() now counts only skills active this turn. It uses a new _active_skill_names(), which get_skills_system_prompt() also uses, so the tools and bodies go by the same rule. _refresh_active_skill_filter now runs before _refresh_active_tool_filter in _process_query_impl, so selection sees this turn's filter, not last turn's. Discovery still runs first.
    • ToolLoader.select now holds a SKILL-listed tool that is already loaded for the rest of the turn, so a later SKILL or semantic pick can't evict it. That removes the churn you traced. An over-cap request keeps its first tools, and the rest wait for a free slot or load_tools.
    • Tests: test_skill_hidden_this_turn_holds_no_tool_slots and test_over_cap_skill_request_settles_instead_of_rotating (3 turns, 1 slot, 2 requested tools → t1 every turn; the old code alternated). The order test in test_skill_discovery_integration.py now expects discover, bodies, tools.
    • On the doc-profile 3-slot case: ChatAgent has no body filter (every loaded body renders every turn), so on that profile a loaded skill is always active and keeps its slots. That matches CORE > SKILL > SEMANTIC, and the churn is gone. In practice ChatAgent has no load_skill tool, no manifest skills, and the loader off by default, so this path is only reachable programmatically.
  • Eval: not run here (needs the self-hosted CI job). The box stays unticked.
  • composing-skills.mdx:76: used your text, with one wording change. "admitted into the next turn's prompt" became "admitted into the prompt on each turn its instructions are active", which is accurate under the active-only rule.
  • Docstring: now says tools_required explicitly and that tools a skill provides through tools.py still arrive by semantic match.
  • parsed_permissions() per turn: now reads the live grant ledger through a new BinaryGrants.holders(), called once per selection.
  • Test stubs that copy Agent methods (test_agent_lazy_skill_prompt, test_adaptive_skills, test_skill_prompt_budget) gained _active_skill_names.
  • Test runs: the test-plan suites plus test_skill_discovery_integration: 921 passed, 16 skipped. hub/agents/gaia/python/tests plus the skill discovery/retriever/synthesis suites: 434 passed. Three failures (test_full_tool_bundles ×2, test_manifest_tools_count_matches_real_registry) and test_tool_loader_token_budget (4) fail the same way on the unmodified PR head and on origin/main in this environment.

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Heads-up for merge order: #3765 deletes tests/unit/test_skill_discovery_integration.py along with the per-turn skill matcher. This PR's check that skill bodies are chosen before tools (test_discovery_runs_before_the_turn_tool_filter, now expecting ["discover", "bodies", "tools"]) lives in that file. If #3765 merges first, the test needs a new home that expects ["bodies", "tools"]. The code conflict in _process_query_impl resolves the same way: drop the _discover_skills_for_turn call and keep _refresh_active_skill_filter before _refresh_active_tool_filter.

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Merged main in — 99 commits behind, no conflicts. Re-ran the suites on the merge result and they still pass, so this is only a freshness update.

Heads-up for whoever merges second: this PR edits tests/unit/test_skill_discovery_integration.py, which #3765 deletes outright. Whichever lands first, the other will need that hunk dropped.

🔍 Technical details

Merge commit only — no hand resolution. Net vs main: 11 files, +261/−22.

Tests on the merge result: test_chat_dynamic_tools.py, test_tool_loader_selection.py, test_starter_skills.py, test_adaptive_skills.py, test_agent_lazy_skill_prompt.py, test_skill_discovery_integration.py, hub/agents/gaia/python/tests/test_skill_prompt_budget.py — 370 passed, 15 skipped.

kovtcharov pushed a commit to kovtcharov/gaia that referenced this pull request Sep 25, 2026
Replicates amd#3903 (kovtcharov/gaia fork, push access blocked) onto a
branch this session can push to.

Loading a skill used to leave the tools it declares out of the prompt,
so the model had to spend an extra round trip on `load_tools` before
doing anything. In a 168-run benchmark, `load_skill github-triage` was
followed by a manual `load_tools shell` in almost every run (45 calls),
and some runs failed before they got there. Now a skill's declared tools
are admitted on every turn its instructions are in the prompt. That
includes the shell tool whenever the skill grants a CLI such as `gh`,
even if the skill forgot to list it. A skill whose instructions are
hidden this turn, or that was unloaded, holds no tool slots.

Admission stays under the loader's existing tool cap. A skill that needs
more tools than the free slots keeps the same ones each turn instead of
rotating them. Tools from procedures recalled from memory still flow in
unchanged, after the active skills' tools.

Fixes amd#3901

Three things changed during conflict resolution against current main,
all forced by amd#3765 landing first:

- amd#3765 deleted `tests/unit/test_skill_discovery_integration.py`, which
is where the original PR's turn-ordering test lived. It is re-homed into
`tests/unit/test_chat_dynamic_tools.py` and now expects `["bodies",
"tools"]` — amd#3765 also removed the proactive per-turn skill discovery
step the old assertion named.
- Main runs the tool filter before the skill-body filter; this PR needs
the reverse, because the tool filter admits the `tools_required` of
whichever skills are active this turn. The two calls are swapped.
- Main independently landed the loader-side half of this fix (a
still-named skill tool is held rather than evicted). Main's version is
kept — it also reports the tool on every turn it is named, which its own
test asserts — and the duplicate the merge produced is dropped. The
loader change here is now documentation plus one added regression test.

No other content changes.

## Test plan
- [x] `pytest tests/unit/test_chat_dynamic_tools.py
tests/unit/test_tool_loader_selection.py
tests/unit/test_chat_tool_bundles.py tests/unit/test_skill_loader.py` —
105 passed. New tests load the real `github-triage` skill and check the
shell tool is admitted, the unload path, a skill hidden by the body
filter, a grant-only skill, cap enforcement, and ordering and dedup with
recalled procedures.
- [x] `pytest tests/unit/test_skill_sets.py
tests/unit/test_starter_skills.py tests/unit/test_skill_binary_grants.py
tests/unit/test_agent_lazy_skill_prompt.py
tests/unit/test_adaptive_skills.py tests/unit/test_skills_consume.py` —
817 passed, 15 skipped.
- [x] `pytest tests/unit/test_memory_mixin.py
hub/agents/gaia/python/tests/test_skill_prompt_budget.py` — 315 passed.
- [x] The re-homed ordering test was mutation-checked: reversing the two
calls in `_process_query_impl` makes it fail.
- [x] `python util/lint.py --black --isort` clean.
- [ ] Agent eval (`gaia eval agent`): this changes which tools reach the
prompt, so it needs an eval before merge. Runs in the self-hosted CI job
now that the branch is on amd/gaia.

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Ovtcharov <[email protected]>
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Replicated as #4369 — fork push access (kovtcharov/gaia) was revoked mid-review, so this PR could no longer be refreshed against main. #3765 landed first, so three things changed: the ordering test moved out of the deleted test_skill_discovery_integration.py into test_chat_dynamic_tools.py and now expects ["bodies", "tools"]; the skill-body and tool filters were swapped in _process_query_impl; and main's own version of the loader-side fix was kept over this PR's duplicate. Closing in favor of the replacement.

pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Sep 26, 2026
amd#4021)

When the agent loaded a skill partway through a turn, the skill's
instructions reached the prompt but its tools didn't reach the tool list
until the next turn. After loading github-triage, whose recipe is "run
every GitHub command through `run_shell_command`", the agent had no
shell tool. It ran `gh` through `run_python` instead, in all 3 benchmark
tasks that loaded the skill (9 calls). For a user, that means an
approval prompt for every GitHub read, where the skill's grant needs
none. Loading a skill now makes its tools callable on the very next
step.

## Test plan
- [ ] `python -m pytest tests/unit/test_skill_tools_same_turn.py`
passes. On main the two reproducing tests fail.
- [ ] Agents without a per-turn tool subset are unchanged
(`test_no_tool_subset_stays_no_tool_subset`).
- [ ] A required tool the agent doesn't have is not added
(`test_a_required_tool_this_agent_lacks_is_not_invented`).

<details>
<summary>🔍 Technical details</summary>

`Agent.load_skill` now adds the skill's `tools_required` and its own
namespaced tools to an active `_active_tool_filter`. It goes through
`_apply_tool_filter`, the same path the `load_tools` escape hatch uses
mid-turn, so both render paths pick it up on the next model call. This
covers a fresh load and a reload of an already-loaded skill. amd#3903
admits active skills' `tools_required` at the next turn's selection.
This PR covers the turn the skill was loaded in, and the two compose.
The helper is module-level because five test stubs borrow
`Agent.load_skill` onto plain classes.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(skills): loading a skill doesn't load the tools it declares

2 participants