feat(skills): inject session state into SKILL.md via adk_inject_state#5405
Open
Koichi73 wants to merge 3 commits intogoogle:mainfrom
Open
feat(skills): inject session state into SKILL.md via adk_inject_state#5405Koichi73 wants to merge 3 commits intogoogle:mainfrom
Koichi73 wants to merge 3 commits intogoogle:mainfrom
Conversation
Let SKILL.md bodies reference session state variables with the same
`{var}` / `{var?}` / `{artifact.name}` syntax already supported in
`LlmAgent.instruction`. The behavior is opt-in per skill through the
frontmatter metadata flag `adk_inject_state: true`, so existing SKILL.md
files are unaffected.
Interpolation is applied in `LoadSkillTool.run_async` using the existing
`instructions_utils.inject_session_state` helper, so skills reuse the
agent's state read mechanism without any new public concepts.
Collaborator
|
Hi @Koichi73 , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit tests before we can proceed with the review. |
…related to this PR)
0347b39 to
cd647b5
Compare
Author
|
Hi @rohityan, the failing test is I've pushed an empty commit to retrigger CI, but the workflow is waiting for maintainer approval. Could you approve it when you have a moment? 🙏 |
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
Problem: SKILL.md bodies cannot reference session state the same way
LlmAgent.instructioncan. Today the only way to surface a state value inside a skill is to register a custom getter tool throughSkillToolset(additional_tools=[...])and tell the model to call it. That is boilerplate for a capability the agent already has.Solution: Reuse the existing
instructions_utils.inject_session_statehelper fromLoadSkillTool. When a skill opts in withmetadata.adk_inject_state: truein its frontmatter, the skill body is interpolated with the same{var}/{var?}/{artifact.name}syntax thatLlmAgent.instructionsupports. The feature is strictly additive and gated on an opt-in flag, so existing SKILL.md files are unaffected.Testing Plan
Unit Tests:
Added to
tests/unittests/tools/test_skill_toolset.py:test_load_skill_run_async_injects_state_when_opt_intest_load_skill_run_async_skips_injection_when_opt_outtest_load_skill_run_async_skips_injection_when_metadata_absentAdded to
tests/unittests/skills/test_models.py:test_metadata_adk_inject_state_booltest_metadata_adk_inject_state_rejected_as_stringExisting mock fixtures for
skill1/skill2frontmatter now explicitly setmetadata = {}, documenting the default and preventing autospec-mock leakage into the new opt-in check.pytestsummary:Manual End-to-End (E2E) Tests:
metadata: {adk_inject_state: true}toSKILL.mdfrontmatter and reference a state variable in the body, e.g.The user prefers {temperature_unit?}.session.state["temperature_unit"] = "celsius"before the agent runs.adk runoradk web) and trigger the skill. Theload_skilltool response now contains the instructions with{temperature_unit}expanded tocelsius.adk_inject_state: falseand re-run — the same SKILL.md returns the literal{temperature_unit?}string, confirming backward compatibility.Checklist
Additional context
This is the read side of a two-part effort to connect SKILL.md with session state. A follow-up PR will propose an
output_key-style facility for writing state from a skill. Splitting the two keeps each review small and focused.