Skip to content

feat(agents): dynamic tool-loader with bundle-gated activation for #688 - #958

Closed
theonlychant wants to merge 6 commits into
amd:mainfrom
theonlychant:feat/tool-loader
Closed

theonlychant wants to merge 6 commits into
amd:mainfrom
theonlychant:feat/tool-loader

Conversation

@theonlychant

Copy link
Copy Markdown
Contributor

Summary

Implements dynamic tool-loader with bundle-gated activation for GAIA's
agent system, reducing token usage by only exposing tools relevant to
the current conversation context.

Why

The full tool registry is passed to the LLM on every turn, consuming
tokens for tools that are unlikely to be used. Bundle-gated activation
loads tools on-demand based on keyword matching and activation policies
(always, session, keyword), reducing context window pressure and
improving response quality.

Linked issue

Closes #688

Changes

  • Added src/gaia/agents/base/tool_loader.py - ToolLoader with bundle
    registration, keyword-based activation, and session/always/keyword policies
  • Added force_activate(bundle_name) public method to avoid direct _state access
  • Wired reset_session() into conversation-start path in ChatAgent
  • Tightened filesystem and browser keyword regexes to use word boundaries
  • Added src/gaia/agents/base/tool_loader.py unit tests

Test plan

  • pytest tests/unit/test_tool_loader.py - all passing
  • python util/lint.py --all - no failures
  • Manual: start a chat session and verify only relevant tool bundles
    activate based on conversation context

Checklist

  • I have linked a GitHub issue above (Closes #688).
  • I have described why this change is being made, not just what changed.
  • I have run linting and tests locally.
  • I have updated documentation if user-visible behavior changed.

…d#688

Signed-off-by: theonlychant <sacehenry@gmail.com>
@github-actions github-actions Bot added tests Test changes agents labels May 5, 2026
Signed-off-by: theonlychant <sacehenry@gmail.com>
Comment thread src/gaia/agents/chat/agent.py
Signed-off-by: theonlychant <sacehenry@gmail.com>
Signed-off-by: theonlychant <sacehenry@gmail.com>
Signed-off-by: theonlychant <sacehenry@gmail.com>

@itomek itomek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three of the prior #854 review items this PR's description claims are fixed are still present in the code. Inline comments mark each spot. Two ways forward: (A) land the fixes the prior review asked for; (B) update the PR description to match what actually shipped. I'd push for A — the regex false positives in particular will mis-route real conversations.


Generated by Claude Code

Comment thread src/gaia/agents/chat/agent.py Outdated
Comment thread src/gaia/agents/chat/agent.py Outdated
Comment thread src/gaia/agents/chat/agent.py Outdated
Comment thread src/gaia/agents/base/tool_loader.py
Comment thread src/gaia/agents/chat/agent.py
…t_session

Signed-off-by: theonlychant <sacehenry@gmail.com>
@theonlychant
theonlychant marked this pull request as draft May 5, 2026 16:08
@theonlychant

theonlychant commented May 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Three of the prior #854 review items this PR's description claims are fixed are still present in the code. Inline comments mark each spot. Two ways forward: (A) land the fixes the prior review asked for; (B) update the PR description to match what actually shipped. I'd push for A — the regex false positives in particular will mis-route real conversations.

Generated by Claude Code

I did that for both this PR and the other one in #854 to be honest I'm not sure if I need this PR right now or do I need to close this but I'll keep this for now if things get messy again

@itomek itomek self-assigned this May 6, 2026
@theonlychant
theonlychant marked this pull request as ready for review May 7, 2026 18:46
@itomek

itomek commented May 8, 2026

Copy link
Copy Markdown
Collaborator

@theonlychant based on comments, I'm closing the PR for now. If you find that we need to reopen it, let us know.

@itomek itomek closed this May 8, 2026
pull Bot pushed a commit to bhardwajRahul/gaia that referenced this pull request Jun 5, 2026
…#688) (amd#1447)

## Why this matters

Issue amd#688 (dynamic tool loading, p0/consumer) has burned **four PRs**
(amd#811/amd#922/amd#957/amd#958), all closing unmerged on the same recurring gaps.
The root cause isn't the contributors — it's that the spec in the issue
body **drifted from the actual code**, so every attempt built against a
stale picture and reviews kept catching it late. Before the next
contributor (who's asked to take it) writes a line, this lands one
canonical, code-accurate spec at `docs/spec/tool-loader.mdx` so design
and implementation can't diverge again — it's reviewed in the same repo
as the code that will implement it.

It also reframes the **why**: not the discredited "~12K tokens" cleanup,
but the two problems users and the architecture actually feel —
**cold-start time-to-first-token** (the first query prefills the whole
tool block) and **scaling slope** (every tool added taxes every turn
forever).

The most important correction: tool descriptions reach the model via
**two render paths** (text prompt for non-tool-calling models; the
native `tools=` schema param for tool-calling models). A selector that
filters only the text path — as the original spec and prior PRs did —
gives tool-calling models **zero** benefit. The spec makes filtering
both a hard requirement, and documents the cache-thrash trap that turns
a first-turn TTFT win into an every-turn tax if selection isn't stable.

## Test plan

- [x] `python -c "import json; json.load(open('docs/docs.json'))"` — nav
JSON valid
- [x] New page `spec/tool-loader` registered under Core Framework in
`docs.json`
- [ ] Mintlify preview renders `docs/spec/tool-loader.mdx` (tables,
`<Note>`/`<Warning>`, internal anchor link)
- [ ] Maintainer sign-off on the design direction before implementation
begins (open questions are left explicitly for the implementer's design
sketch)

---------

Co-authored-by: Ovtcharov <kovtchar@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic tool loading based on conversation context via memory

2 participants