|
| 1 | +# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +from typing import Dict, List, Optional |
| 18 | + |
| 19 | +try: |
| 20 | + from typing_extensions import override |
| 21 | +except ImportError: |
| 22 | + from typing import override |
| 23 | + |
| 24 | +from google.adk.agents.readonly_context import ReadonlyContext |
| 25 | +from google.adk.tools import BaseTool, FunctionTool |
| 26 | +from google.adk.tools.base_toolset import BaseToolset |
| 27 | + |
| 28 | +from veadk.skills.skill import Skill |
| 29 | +from veadk.tools.skills_tools import ( |
| 30 | + SkillsTool, |
| 31 | + read_file_tool, |
| 32 | + write_file_tool, |
| 33 | + edit_file_tool, |
| 34 | + bash_tool, |
| 35 | + register_skills_tool, |
| 36 | +) |
| 37 | +from veadk.utils.logger import get_logger |
| 38 | + |
| 39 | +logger = get_logger(__name__) |
| 40 | + |
| 41 | + |
| 42 | +class SkillsToolset(BaseToolset): |
| 43 | + """Toolset that provides Skills functionality for domain expertise execution. |
| 44 | +
|
| 45 | + This toolset provides skills access through specialized tools: |
| 46 | + 1. SkillsTool - Discover and load skill instructions |
| 47 | + 2. ReadFileTool - Read files with line numbers |
| 48 | + 3. WriteFileTool - Write/create files |
| 49 | + 4. EditFileTool - Edit files with precise replacements |
| 50 | + 5. BashTool - Execute shell commands |
| 51 | + 6. RegisterSkillsTool - Register new skills into the remote skill space |
| 52 | +
|
| 53 | + Skills provide specialized domain knowledge and scripts that the agent can use |
| 54 | + to solve complex tasks. The toolset enables discovery of available skills, |
| 55 | + file manipulation, and command execution. |
| 56 | + """ |
| 57 | + |
| 58 | + def __init__(self, skills: Dict[str, Skill], skills_mode: str) -> None: |
| 59 | + """Initialize the skills toolset. |
| 60 | +
|
| 61 | + Args: |
| 62 | + skills: A dictionary of skill. |
| 63 | + skills_mode: The mode of skills operation, e.g., "skills_sandbox". |
| 64 | + """ |
| 65 | + super().__init__() |
| 66 | + |
| 67 | + self.skills_mode = skills_mode |
| 68 | + |
| 69 | + self._tools = { |
| 70 | + "skills": SkillsTool(skills), |
| 71 | + "read_file": FunctionTool(read_file_tool), |
| 72 | + "write_file": FunctionTool(write_file_tool), |
| 73 | + "edit_file": FunctionTool(edit_file_tool), |
| 74 | + "bash": FunctionTool(bash_tool), |
| 75 | + "register_skills": FunctionTool(register_skills_tool), |
| 76 | + } |
| 77 | + |
| 78 | + @override |
| 79 | + async def get_tools( |
| 80 | + self, readonly_context: Optional[ReadonlyContext] = None |
| 81 | + ) -> List[BaseTool]: |
| 82 | + """Return tools according to selected skills_mode.""" |
| 83 | + |
| 84 | + match self.skills_mode: |
| 85 | + case "local": |
| 86 | + logger.info( |
| 87 | + "Skills mode=local, adding skills_tool, read_file_tool, write_file_tool, edit_file_tool, bash_tool and register_skills_tool to the agent." |
| 88 | + ) |
| 89 | + return list(self._tools.values()) |
| 90 | + |
| 91 | + case "skills_sandbox": |
| 92 | + logger.info( |
| 93 | + "Skills mode=skills_sandbox, no skills tools are added to the agent." |
| 94 | + ) |
| 95 | + return [] |
| 96 | + |
| 97 | + case "aio_sandbox": |
| 98 | + logger.info("Skills mode=aio_sandbox: not implemented yet") |
| 99 | + return [] |
| 100 | + |
| 101 | + case _: |
| 102 | + logger.warning( |
| 103 | + f"Unknown skills_mode: {self.skills_mode}, returning empty tool list." |
| 104 | + ) |
| 105 | + return [] |
0 commit comments