diff --git a/src/google/adk/tools/skill_toolset.py b/src/google/adk/tools/skill_toolset.py index 8d46c3ca..34cad5c5 100644 --- a/src/google/adk/tools/skill_toolset.py +++ b/src/google/adk/tools/skill_toolset.py @@ -17,6 +17,7 @@ from __future__ import annotations from typing import Any +from typing import TYPE_CHECKING from google.genai import types @@ -29,6 +30,9 @@ from .base_tool import BaseTool from .base_toolset import BaseToolset from .tool_context import ToolContext +if TYPE_CHECKING: + from ..models.llm_request import LlmRequest + DEFAULT_SKILL_SYSTEM_INSTRUCTION = """You can use specialized 'skills' to help you with complex tasks. You MUST use the skill tools to interact with these skills. Skills are folders of instructions and resources that extend your capabilities for specialized tasks. Each skill folder contains: @@ -38,10 +42,9 @@ Skills are folders of instructions and resources that extend your capabilities f This is very important: -1. Use the `list_skills` tool to discover available skills. -2. If a skill seems relevant to the current user query, you MUST use the `load_skill` tool with `name=""` to read its full instructions before proceeding. -3. Once you have read the instructions, follow them exactly as documented before replying to the user. For example, If the instruction lists multiple steps, please make sure you complete all of them in order. -4. The `load_skill_resource` tool is for viewing files within a skill's directory (e.g., `references/*`, `assets/*`). Do NOT use other tools to access these files. +1. If a skill seems relevant to the current user query, you MUST use the `load_skill` tool with `name=""` to read its full instructions before proceeding. +2. Once you have read the instructions, follow them exactly as documented before replying to the user. For example, If the instruction lists multiple steps, please make sure you complete all of them in order. +3. The `load_skill_resource` tool is for viewing files within a skill's directory (e.g., `references/*`, `assets/*`). Do NOT use other tools to access these files. """ @@ -241,3 +244,11 @@ class SkillToolset(BaseToolset): def _list_skills(self) -> list[models.Frontmatter]: """Lists the frontmatter of all available skills.""" return [s.frontmatter for s in self._skills.values()] + + async def process_llm_request( + self, *, tool_context: ToolContext, llm_request: LlmRequest + ) -> None: + """Processes the outgoing LLM request to include available skills.""" + skill_frontmatters = self._list_skills() + skills_xml = prompt.format_skills_as_xml(skill_frontmatters) + llm_request.append_instructions([skills_xml]) diff --git a/tests/unittests/tools/test_skill_toolset.py b/tests/unittests/tools/test_skill_toolset.py index 9606c498..b747d1f8 100644 --- a/tests/unittests/tools/test_skill_toolset.py +++ b/tests/unittests/tools/test_skill_toolset.py @@ -14,6 +14,7 @@ from unittest import mock +from google.adk.models import llm_request as llm_request_model from google.adk.skills import models from google.adk.tools import skill_toolset from google.adk.tools import tool_context @@ -249,3 +250,23 @@ async def test_load_resource_run_async( tool = skill_toolset.LoadSkillResourceTool(toolset) result = await tool.run_async(args=args, tool_context=tool_context_instance) assert result == expected_result + + +@pytest.mark.asyncio +async def test_process_llm_request( + mock_skill1, mock_skill2, tool_context_instance +): + toolset = skill_toolset.SkillToolset([mock_skill1, mock_skill2]) + llm_req = mock.create_autospec(llm_request_model.LlmRequest, instance=True) + + await toolset.process_llm_request( + tool_context=tool_context_instance, llm_request=llm_req + ) + + llm_req.append_instructions.assert_called_once() + args, _ = llm_req.append_instructions.call_args + instructions = args[0] + assert len(instructions) == 1 + assert "" in instructions[0] + assert "skill1" in instructions[0] + assert "skill2" in instructions[0]