diff --git a/veadk/agent.py b/veadk/agent.py index ae20e949..73c11e95 100644 --- a/veadk/agent.py +++ b/veadk/agent.py @@ -361,6 +361,11 @@ def load_skills(self): "You can use the skills by calling the `execute_skills` tool.\n\n" ) + if self.skills_mode == "local": + self.instruction += ( + "You can use the skills by calling the `skills_tool` tool.\n\n" + ) + self.tools.append(SkillsToolset(skills, self.skills_mode)) else: logger.warning("No skills loaded.") diff --git a/veadk/skills/utils.py b/veadk/skills/utils.py index deb69569..b0ca0ab4 100644 --- a/veadk/skills/utils.py +++ b/veadk/skills/utils.py @@ -89,11 +89,14 @@ def load_skills_from_cloud(skill_space_ids: str) -> list[Skill]: secret_key = cred.secret_access_key session_token = cred.session_token + request_body = { + "SkillSpaceId": skill_space_id, + "InnerTags": {"source": "sandbox"}, + } + logger.debug(f"ListSkillsBySpaceId request body: {request_body}") + response = ve_request( - request_body={ - "SkillSpaceId": skill_space_id, - "InnerTags": {"source": "sandbox"}, - }, + request_body=request_body, action="ListSkillsBySpaceId", ak=access_key, sk=secret_key, diff --git a/veadk/tools/skills_tools/register_skills_tool.py b/veadk/tools/skills_tools/register_skills_tool.py index db2c5509..b87c96f4 100644 --- a/veadk/tools/skills_tools/register_skills_tool.py +++ b/veadk/tools/skills_tools/register_skills_tool.py @@ -17,6 +17,7 @@ import json import os import zipfile +import frontmatter from pathlib import Path from datetime import datetime @@ -31,16 +32,12 @@ def register_skills_tool( - skill_name: str, - skill_description: str, skill_local_path: str, tool_context: ToolContext, ) -> str: """Register a skill to the remote skill space by uploading its zip package to TOS and calling the CreateSkill API. Args: - skill_name (str): The name of the skill. - skill_description (str): The description of the skill. skill_local_path (str): The local path of the skill directory. - The format of the skill directory is as follows: skill_local_path/ @@ -68,6 +65,16 @@ def register_skills_tool( logger.error(f"Skill path '{skill_path}' has no SKILL.md file.") return f"Skill path '{skill_path}' has no SKILL.md file." + try: + skill = frontmatter.load(str(skill_readme)) + skill_name = skill.get("name", "") + # skill_description = skill.get("description", "") + except Exception as e: + logger.error( + f"Failed to get skill name and description from {skill_readme}: {e}" + ) + return f"Failed to get skill name and description from {skill_readme}: {e}" + zip_file_path = working_dir / "outputs" / f"{skill_name}.zip" with zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED) as zipf: @@ -138,13 +145,14 @@ def register_skills_tool( x.strip() for x in skill_space_ids.split(",") if x.strip() ] + request_body = { + "TosUrl": tos_url, + "SkillSpaces": skill_space_ids_list, + } + logger.debug(f"CreateSkill request body: {request_body}") + response = ve_request( - request_body={ - "Name": skill_name, - "Description": skill_description, - "TosUrl": tos_url, - "SkillSpaces": skill_space_ids_list, - }, + request_body=request_body, action="CreateSkill", ak=access_key, sk=secret_key, @@ -160,11 +168,10 @@ def register_skills_tool( logger.debug(f"CreateSkill response: {response}") - if "Error" in response: - logger.error( - f"Failed to register skill '{skill_name}': {response['Error']}" - ) - return f"Failed to register skill '{skill_name}': {response['Error']}" + if "ResponseMetadata" in response and "Error" in response["ResponseMetadata"]: + error_details = response["ResponseMetadata"]["Error"] + logger.error(f"Failed to register skill '{skill_name}': {error_details}") + return f"Failed to register skill '{skill_name}': {error_details}" logger.info( f"Successfully registered skill '{skill_name}' to skill space {skill_space_ids_list}." diff --git a/veadk/tools/skills_tools/skills_tool.py b/veadk/tools/skills_tools/skills_tool.py index 435b1642..dad216ee 100644 --- a/veadk/tools/skills_tools/skills_tool.py +++ b/veadk/tools/skills_tools/skills_tool.py @@ -13,7 +13,7 @@ # limitations under the License. from __future__ import annotations - +import os from pathlib import Path from typing import Any, Dict @@ -101,6 +101,7 @@ def _invoke_skill(self, skill_name: str, tool_context: ToolContext) -> str: working_dir = get_session_path(session_id=tool_context.session.id) skill_dir = working_dir / "skills" + region = os.getenv("AGENTKIT_TOOL_REGION", "cn-beijing") if skill_name not in self.skills: # 1. Download skill from TOS if not found locally @@ -114,7 +115,6 @@ def _invoke_skill(self, skill_name: str, tool_context: ToolContext) -> str: try: from veadk.auth.veauth.utils import get_credential_from_vefaas_iam from veadk.integrations.ve_tos.ve_tos import VeTOS - import os access_key = os.getenv("VOLCENGINE_ACCESS_KEY") secret_key = os.getenv("VOLCENGINE_SECRET_KEY") @@ -183,6 +183,7 @@ def _invoke_skill(self, skill_name: str, tool_context: ToolContext) -> str: sk=secret_key, session_token=session_token, bucket_name=tos_bucket, + region=region, ) # Download the skill directory from TOS @@ -216,8 +217,6 @@ def _invoke_skill(self, skill_name: str, tool_context: ToolContext) -> str: from veadk.auth.veauth.utils import get_credential_from_vefaas_iam from veadk.integrations.ve_tos.ve_tos import VeTOS - region = os.getenv("AGENTKIT_TOOL_REGION", "cn-beijing") - access_key = os.getenv("VOLCENGINE_ACCESS_KEY") secret_key = os.getenv("VOLCENGINE_SECRET_KEY") session_token = "" diff --git a/veadk/tools/skills_tools/skills_toolset.py b/veadk/tools/skills_tools/skills_toolset.py index 8cf742af..1399b87b 100644 --- a/veadk/tools/skills_tools/skills_toolset.py +++ b/veadk/tools/skills_tools/skills_toolset.py @@ -83,19 +83,12 @@ async def get_tools( match self.skills_mode: case "local": - logger.info( - "Skills mode=local, adding skills_tool, read_file_tool, write_file_tool, edit_file_tool, bash_tool and register_skills_tool to the agent." - ) return list(self._tools.values()) case "skills_sandbox": - logger.info( - "Skills mode=skills_sandbox, no skills tools are added to the agent." - ) return [] case "aio_sandbox": - logger.info("Skills mode=aio_sandbox: not implemented yet") return [] case _: