Skip to content

feat(skills): inject session state into SKILL.md via adk_inject_state#5405

Open
Koichi73 wants to merge 3 commits intogoogle:mainfrom
Koichi73:feat/skill-md-inject-state
Open

feat(skills): inject session state into SKILL.md via adk_inject_state#5405
Koichi73 wants to merge 3 commits intogoogle:mainfrom
Koichi73:feat/skill-md-inject-state

Conversation

@Koichi73
Copy link
Copy Markdown

Link to Issue or Description of Change

Problem: SKILL.md bodies cannot reference session state the same way LlmAgent.instruction can. Today the only way to surface a state value inside a skill is to register a custom getter tool through SkillToolset(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_state helper from LoadSkillTool. When a skill opts in with metadata.adk_inject_state: true in its frontmatter, the skill body is interpolated with the same {var} / {var?} / {artifact.name} syntax that LlmAgent.instruction supports. The feature is strictly additive and gated on an opt-in flag, so existing SKILL.md files are unaffected.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added to tests/unittests/tools/test_skill_toolset.py:

  • test_load_skill_run_async_injects_state_when_opt_in
  • test_load_skill_run_async_skips_injection_when_opt_out
  • test_load_skill_run_async_skips_injection_when_metadata_absent

Added to tests/unittests/skills/test_models.py:

  • test_metadata_adk_inject_state_bool
  • test_metadata_adk_inject_state_rejected_as_string

Existing mock fixtures for skill1 / skill2 frontmatter now explicitly set metadata = {}, documenting the default and preventing autospec-mock leakage into the new opt-in check.

pytest summary:

$ pytest tests/unittests/tools/test_skill_toolset.py tests/unittests/skills/test_models.py
111 passed, 7 warnings in 11.39s

Manual End-to-End (E2E) Tests:

  1. In a skill directory, add metadata: {adk_inject_state: true} to SKILL.md frontmatter and reference a state variable in the body, e.g. The user prefers {temperature_unit?}.
  2. Seed session state with session.state["temperature_unit"] = "celsius" before the agent runs.
  3. Run the agent (adk run or adk web) and trigger the skill. The load_skill tool response now contains the instructions with {temperature_unit} expanded to celsius.
  4. Remove or set adk_inject_state: false and re-run — the same SKILL.md returns the literal {temperature_unit?} string, confirming backward compatibility.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

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.

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.
@adk-bot adk-bot added the tools [Component] This issue is related to tools label Apr 20, 2026
@rohityan rohityan self-assigned this Apr 20, 2026
@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Apr 20, 2026
@rohityan
Copy link
Copy Markdown
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.

@Koichi73 Koichi73 force-pushed the feat/skill-md-inject-state branch from 0347b39 to cd647b5 Compare April 21, 2026 00:16
@Koichi73
Copy link
Copy Markdown
Author

Hi @rohityan, the failing test is test_parallel_function_execution_timing, a known-flaky timing-based test (see b92b288) unrelated to this PR's changes. It passes 5/5 locally on Python 3.12 (macOS).

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? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support session state interpolation in SKILL.md via adk_inject_state

3 participants