feat(tools): add rolling window for activated skills in SkillToolset#5745
Open
lwangverizon wants to merge 1 commit into
Open
feat(tools): add rolling window for activated skills in SkillToolset#5745lwangverizon wants to merge 1 commit into
lwangverizon wants to merge 1 commit into
Conversation
Add max_activated_skills parameter to SkillToolset that enforces a rolling window on the number of concurrently activated skills per agent. When the limit is exceeded, the oldest activated skills (and their associated additional tools) are evicted from session state. This addresses unbounded tool context growth during long-running sessions where many skills get loaded but only recent ones are relevant. Key changes: - Add max_activated_skills param to SkillToolset.__init__ - Enforce LRU-style eviction in LoadSkillTool.run_async: re-loading an already active skill promotes it to most-recent position - Always persist state (even for re-activations) to maintain ordering - Default is None (no limit) for backward compatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
2. Or, if no issue exists, describe the change:
Problem:
In long-running sessions, the
SkillToolsetaccumulates activated skills unboundedly. Eachload_skillcall adds tools to the session state, growing the tool context sent to the LLM indefinitely. This can degrade LLM performance as the function declarations list grows, increase token consumption, and in extreme cases exceed context window limits.Unlike AutoGen (static tools at construction) and LangGraph (static tool binding with dynamic routing), ADK's skill system allows mid-session tool expansion — which is powerful but requires bounds.
Solution:
Add an optional
max_activated_skillsparameter toSkillToolsetthat enforces a rolling window (LRU eviction) on concurrently activated skills per agent.Key design decisions:
None(no limit), preserving existing behaviorLoadSkillTool.run_async, no new dependenciesTesting Plan
Unit Tests:
7 new tests added covering:
test_max_activated_skills_evicts_oldest— verifies oldest skill is evicted when limit exceededtest_max_activated_skills_keeps_recent_n— confirms only N most recent skills retainedtest_max_activated_skills_reloading_moves_to_end— validates LRU promotion on re-loadtest_no_max_activated_skills_unlimited— confirms backward compatibility (no limit)test_evicted_skill_tools_not_resolved— verifies evicted tools are excluded fromget_toolstest_evicted_tool_call_raises_value_error— confirms_get_toolraises ValueError for evicted toolstest_rolling_window_full_lifecycle_with_tool_resolution— end-to-end lifecycle testManual End-to-End (E2E) Tests:
Tested with a multi-skill agent using
adk web— confirmed that after exceedingmax_activated_skills=3, older skills are no longer available in the LLM's tool declarations, and re-loading a skill correctly promotes it.Checklist
Additional context
Comparison with other frameworks:
ADK's skill system is uniquely powerful in allowing runtime tool discovery and loading, but this PR ensures it remains bounded and performant in long-running sessions.
Edge case note: If the LLM calls a tool from conversation history that was since evicted,
_get_tool()infunctions.pyraisesValueError. This is recoverable viaon_tool_errorcallbacks. The risk is minimal since evicted tools are removed from the next function declarations, so the LLM won't attempt to call them.