Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions veadk/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
11 changes: 7 additions & 4 deletions veadk/skills/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 22 additions & 15 deletions veadk/tools/skills_tools/register_skills_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import json
import os
import zipfile
import frontmatter
from pathlib import Path
from datetime import datetime

Expand All @@ -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/
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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}."
Expand Down
7 changes: 3 additions & 4 deletions veadk/tools/skills_tools/skills_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from __future__ import annotations

import os
from pathlib import Path
from typing import Any, Dict

Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = ""
Expand Down
7 changes: 0 additions & 7 deletions veadk/tools/skills_tools/skills_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _:
Expand Down