Skip to content

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

Merged
kovtcharov-amd merged 5 commits into
mainfrom
replicate/skill-tools-admission-3903
Sep 25, 2026
Merged

kovtcharov-amd merged 5 commits into
mainfrom
replicate/skill-tools-admission-3903

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Replicates #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 #3901

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

  • feat(skills): show the model every installed skill instead of guessing one #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"] — feat(skills): show the model every installed skill instead of guessing one #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

  • 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.
  • 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.
  • pytest tests/unit/test_memory_mixin.py hub/agents/gaia/python/tests/test_skill_prompt_budget.py — 315 passed.
  • The re-homed ordering test was mutation-checked: reversing the two calls in _process_query_impl makes it fail.
  • 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.

Kalin Ovtcharov and others added 5 commits September 15, 2026 14:58
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 #3901
…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.
# Conflicts:
#	src/gaia/agents/base/agent.py
#	tests/unit/test_skill_discovery_integration.py
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents labels Sep 25, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 25, 2026
Merged via the queue into main with commit e40c638 Sep 25, 2026
43 of 45 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the replicate/skill-tools-admission-3903 branch September 25, 2026 20:12
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

The fix is correct and the test coverage is thorough. The ordering swap (_refresh_active_skill_filter → _refresh_active_tool_filter) is logically required: the tool filter needs to know which skills are active before it can admit their declared tools, so the old order was wrong by construction. The new _loaded_skill_tools() and _active_skill_names() helpers handle all the edge cases cleanly — no-filter (admit all), hidden-this-turn (admit none for that skill), unloaded (stops contributing). BinaryGrants.holders() is a correct inversion of the binary → skills map.

One 🟡 to address and one nit:


🟡 hub/agents/chat/python/CHANGELOG.md has no entry for this fix. The Unreleased section exists and two prior fixes are listed there; this behavioral change — skills' tools_required tools are now admitted without a manual load_tools round-trip — should appear alongside them. Per CLAUDE.md, a behavioral change to a hub agent package must be reflected in its CHANGELOG.

🟢 _active_skill_names() returns Optional[FrozenSet[str]], but get_skills_system_prompt uses it without a None-guard at line 2811 (if skill.name in active:). At runtime this is safe — the call is always in the active_filter is not None branch so None can never reach that line — but a type checker flags it, and a future reader of _active_skill_names won't see the invariant that makes it safe. Either narrow the return type for the non-None case or add an assert active is not None guard.

🔍 Technical details

CHANGELOG gap
hub/agents/chat/python/CHANGELOG.md Unreleased section (currently lines 3–11). Add a bullet like:

  • A loaded skill's tools_required are now admitted into the prompt on every turn its instructions are active, eliminating the manual load_tools round-trip that was otherwise needed after load_skill.

Type-safety gap
src/gaia/agents/base/agent.py:2807 — active = self._active_skill_names() in get_skills_system_prompt, then used at line 2811 as if skill.name in active:. The caller already guards with if active_filter is None: ... return so None never reaches line 2811, but mypy can't see across that guard. A one-liner fix:

active = self._active_skill_names()
assert active is not None  # guarded by the active_filter is None early-return above

Or narrow _active_skill_names with an overload / two helpers so the non-None case has a concrete return type.

Eval gate
PR description notes the agent eval runs in the self-hosted CI job. The eval is the right call here — the change widens what the model sees in the prompt — and the PR description tracks it. Nothing to add.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions.

Loading a skill now also brings the tools that skill says it needs, so the model stops burning a turn asking for them — a real win, cleanly scoped and well covered by tests. One thing to know before trusting the headline number: when the model loads a skill in the middle of answering, the tools still don't arrive until the user's next message, so the extra load_tools call the benchmark counted is only removed from the second turn onward. I reproduced that on this checkout.

Follow-ups worth doing:

  • The extra round trip survives on the turn the skill is loaded. Loading a skill part-way through an answer refreshes the skill's instructions but not the turn's tool set, so the model still has to ask for the shell tool before it can act. Either wire the load path into the same mid-answer tool-admission route the manual loader already uses, or say plainly in the description that the saving starts on the following turn.
  • The agent eval is still unchecked. This changes which tools reach the model, which is exactly the class of change unit tests can't score. The scorecard run is the last open box on the test plan.
  • Always-on skills (the ones that never hide) now hold tool slots on every single turn. That's consistent, but nothing tests it, and it's the case where the budget is consumed permanently rather than per topic.

Real-world evidence

evidence-bundle.md is present and honest about what it could and couldn't do on a no-inference runner. It exercised the real CLI for the exact manifest fields the new code reads (permissions: shell:execute:gh + consumes: run_shell_command on github-triage), booted the Agent UI backend in-process with the changed modules (/api/health, /api/settings, /api/agents all 200/404 as expected), and ran a spot-regression pass over neighbouring routes and gaia skill list|audit. It marks the actual selection behaviour and any UI pixels "pending strix-halo lane", because the loader needs a live embedder. That matches the rubric's CI-lane carve-out, so it isn't a blocker — but it does mean the behaviour itself was proven here only by unit tests, which I ran and which pass (51 in test_chat_dynamic_tools.py, 555 across the skill/grant suites), plus my own reproduction of the mid-turn gap above.

🔍 Technical details

🟡 The SKILL signal doesn't apply on the turn load_skill is called

skill_library_tools.load_skill → Agent.load_skill (src/gaia/agents/base/agent.py:2304-2306) calls rebuild_system_prompt(), which re-renders the skill body but leaves _active_tool_filter untouched; the filter is only recomputed at _process_query_impl (agent.py:5670-5674). So _loaded_skill_tools()'s claim that "an active skill's tools arrive without a separate load_tools round trip" (agent.py:2151) holds from the next user turn only.

Reproduced on this checkout with a real ToolLoader + the real github-triage skill:

turn-start filter: ['c1']
after mid-turn load_skill, _active_tool_filter: ['c1']
skill declares: ['run_shell_command']
next-turn filter: ['c1', 'run_shell_command']

The PR body's benchmark (load_skill github-triage followed by a manual load_tools shell, 45 calls) is precisely the mid-turn shape, so the measured saving may not land where it was measured. ToolLoader.load_bundle (tool_loader.py:443) already exists as the mid-loop admission path the load_tools escape hatch uses via _apply_tool_filter; routing the newly loaded skill's tools_required through it would close this. Flagging rather than suggesting a diff — it's a design call about mid-loop prompt churn.

🟡 Agent eval not run

Test plan item 6 is unchecked. Per CLAUDE.md, changing which tools reach the prompt / the tool schema sent to Lemonade requires gaia eval agent before merge. Worth landing the scorecard (or a link to the self-hosted run) rather than leaving the box open.

🟢 Nits

  1. Duplicate "which skills are showing" logic — skill_library_tools.py:726-728 still hand-rolls set(skill_filter) | always_on, which is now exactly _active_skill_names(). One helper, one behaviour:
            showing = agent._active_skill_names()
  1. No test for always-on skills contributing tools. _active_skill_names() unions _always_on_skill_names, so a manifest skills: entry's tools_required are admitted on every turn regardless of the body filter — the one case where the SKILL tier holds slots permanently. test_skill_hidden_this_turn_holds_no_tool_slots covers the opposite; the always-on path is untested.

  2. BinaryGrants.holders() (src/gaia/skills/binaries.py:2001) returns skill names while the neighbouring binaries() returns binaries and _holders is keyed by binary — the docstring saves it, but granting_skills() would read unambiguously at the call site.

Strengths

  • The ordering change is the subtle part and it's pinned by a mutation-checked test (test_skill_body_filter_runs_before_the_turn_tool_filter) that asserts the sequence directly rather than a downstream symptom.
  • New tests load the real hub/skills/github-triage through a real SkillManager and a real ToolLoader, so they check the manifest contract rather than a mock's shape — including the grant-only skill that omits run_shell_command from tools_required.
  • _active_skill_names() unifies the body-filter and tool-signal notions of "active this turn" instead of adding a second definition; get_skills_system_prompt now reads from the same helper.
  • Cap behaviour is explicit and tested in both directions: over-cap requests settle instead of rotating (test_over_cap_skill_request_settles_instead_of_rotating), and an over-cap skill is bounded rather than starving the loader silently.
  • docs/guides/composing-skills.mdx was updated in the same change, and the surrounding specs (docs/spec/agent-skills.mdx, docs/plans/skill-format.mdx) don't contradict the new behaviour.

pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Sep 27, 2026
…md#4374)

Replicates amd#4145 (`kovtcharov/gaia` fork, push access blocked) onto a
branch this session can push to. No content changes beyond conflict
resolution against current `main`.

GAIA could claim it saved a file it never wrote this turn, or turn a
long workshop transcript into a condensed list presented as complete.
Now a save counts only when that exact file was written and read back,
and a long document is extracted page by page into a full inventory in
which every item keeps a verbatim quote from the source. The result is
kept in memory, and anything unfinished is reported as incomplete.
Ordinary questions ("What time does the store close?") behave exactly as
on `main`.

Fixes amd#3983 and amd#4141; related to amd#4009. Closes amd#4145.

## Test plan

- [x] `python -m pytest tests/unit/agents/ -q`: 1,663 pass, 51 skip. The
one failure (`test_symlinked_directory_is_the_same_output`) is this
Windows box lacking the symlink privilege, not the code.
- [x] `python -m pytest tests/unit/ -k "memory" -q`: 1,136 pass. The one
failure (`test_memory_discovery.py::TestCredentialManagerContractShape`)
reproduces on pristine `main`.
- [x] `python -m pytest tests/unit/ -k "inventory or transcript or
overlap or youtube or extract" -q`: 547 pass; remaining failures are a
local `mcp` package version mismatch and a live-Lemonade ASR test.
- [x] `black --check` / `isort --check-only` clean on every touched
file.
- [ ] Reporter check: Patrick reruns the original workshop transcript.
- [ ] Judged `gaia eval agent` run: deferred by maintainer; the
completion gate changes final answers, so decide before merge.

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

**What a reviewer should know**

- **Saves**
- A request that names a file, folder or disk is a hard obligation: the
file must be written and read back this turn.
- A save claim is checked hard when a save was requested, a disk tool
ran, or the answer says "I" or "we" saved something. Any other claim
gets one correction and then stands, as on `main`.
- A file written through the shell counts only when a successful call
modified it. The agent's scratch folder never counts as the user's save.
- **Extraction**
- Pages are 4K characters with 600 characters of overlap, snapped to a
line, sentence or word boundary. Each page gets two passes, a retry on
an unusable reply, and a 16K-token output budget.
- Cloud models are asked for no reasoning: a reasoning model spent
50–100 s per page and ran past the 30-minute limit on a 74K file.
- Quote matching ignores case and spacing, but only on whole words. The
stored quote is always the source text at its exact offsets.
- An item is placed by the span of its name when the name is copied from
the quote, otherwise by its quote.
- Merging never fails a run and never drops an item. Differing
descriptions are both kept, and uncertain cases keep both entries,
marked "(may repeat item N)".
- **Exports**
- JSON records give each field its own key and CSV gives each field its
own column. The framework reads the saved file back in full and requires
an exact match, and hand edits to it are refused.

**Adversarial coverage (from amd#4145)**

- A planted-item oracle (about 20,000 items, repeated names, paraphrased
labels, repeats across pages and passes) finds no lost, absorbed or
wrongly merged items.
- In 60,000 hostile replies, no exception escaped the tool, and every
quote matched the source at its offsets.
- Live runs on Fireworks `deepseek-v4p1-flash` against real YouTube
auto-captions of 13K, 21K and 74K characters; the 74K end-to-end agent
run saved and verified 111 items in 122 s. Local Gemma-4-E4B completed
the 13K file (63 items).

**Conflicts resolved against current `main`**

Two, both in `src/gaia/agents/base/agent.py`, plus an additive one in
the flagship `CHANGELOG.md`:

1. **Turn-sealing order vs. amd#3707 (mid-turn followups).** `main` added a
`_drain_followups` check that re-enters the loop rather than sealing the
answer; amd#4145 replaced the same lines with `finalize_answer` + the
completion-evidence gate. Kept both, drain first: a late user message
still gets folded into the running turn, and the completion gate then
runs on the answer that actually seals.
2. **Duplicated `_refresh_active_skill_filter` vs. amd#4369 (a loaded skill
brings its tools).** amd#4369 hoisted that call to *before*
`_refresh_active_tool_filter`; amd#4145 still carried it in its old
position below, so a naive merge called it twice per turn. Dropped the
duplicate and kept `main`'s hoisted call — the extraction block that
follows reads `_active_skill_filter`, so running it earlier is strictly
correct.

**Verification of the resolution**

- Per-file diff of (merge-base → amd#4145 head) against (current `main` →
this branch): byte-identical on every file except the one blank line the
de-duplication above removes. That rules out the silent near-identical
duplication a large auto-merge can introduce.
- `compile()` (not just `ast.parse`, which does not reject repeated
keyword arguments) over every `.py` in `src/`, `tests/`, `hub/` and
`scripts/`: clean. Repo-wide sweep for stray conflict markers: none.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Co-authored-by: f <f@f>
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

1 participant