Skip to content

Commit 6ead37a

Browse files
authored
feat: adapt skills to byteplus (#500)
* feat: adapt skills to byteplus * fix: fix hosts of execute_skills and run_code
1 parent 918c0f4 commit 6ead37a

File tree

6 files changed

+75
-15
lines changed

6 files changed

+75
-15
lines changed

veadk/agent.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,19 @@ def load_skills(self):
379379
else:
380380
logger.debug("Successfully get AK/SK from environment variables.")
381381

382+
provider = (os.getenv("CLOUD_PROVIDER") or "").lower()
383+
if provider == "byteplus":
384+
sld = "byteplusapi"
385+
default_region = "ap-southeast-1"
386+
else:
387+
sld = "volcengineapi"
388+
default_region = "cn-beijing"
389+
382390
service = os.getenv("AGENTKIT_TOOL_SERVICE_CODE", "agentkit")
383-
region = os.getenv("AGENTKIT_TOOL_REGION", "cn-beijing")
384-
host = service + "." + region + ".volcengineapi.com"
391+
region = os.getenv("AGENTKIT_TOOL_REGION", default_region)
392+
host = os.getenv(
393+
"AGENTKIT_SKILL_HOST", service + "." + region + f".{sld}.com"
394+
)
385395

386396
res = ve_request(
387397
request_body={"ToolId": tool_id},

veadk/skills/utils.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,19 @@ def load_skills_from_cloud(skill_space_ids: str) -> list[Skill]:
7575
for skill_space_id in skill_space_ids_list:
7676
try:
7777
service = os.getenv("AGENTKIT_TOOL_SERVICE_CODE", "agentkit")
78-
region = os.getenv("AGENTKIT_TOOL_REGION", "cn-beijing")
79-
host = os.getenv("AGENTKIT_SKILL_HOST", "open.volcengineapi.com")
78+
79+
provider = (os.getenv("CLOUD_PROVIDER") or "").lower()
80+
if provider == "byteplus":
81+
sld = "byteplusapi"
82+
default_region = "ap-southeast-1"
83+
else:
84+
sld = "volcengineapi"
85+
default_region = "cn-beijing"
86+
87+
region = os.getenv("AGENTKIT_TOOL_REGION", default_region)
88+
host = os.getenv(
89+
"AGENTKIT_SKILL_HOST", service + "." + region + f".{sld}.com"
90+
)
8091

8192
access_key = os.getenv("VOLCENGINE_ACCESS_KEY")
8293
secret_key = os.getenv("VOLCENGINE_SECRET_KEY")

veadk/tools/builtin_tools/execute_skills.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,18 @@ def execute_skills(
8787
service = getenv(
8888
"AGENTKIT_TOOL_SERVICE_CODE", "agentkit"
8989
) # temporary service for code run tool
90-
region = getenv("AGENTKIT_TOOL_REGION", "cn-beijing")
90+
91+
cloud_provider = (os.getenv("CLOUD_PROVIDER") or "").lower()
92+
if cloud_provider == "byteplus":
93+
sld = "bytepluses"
94+
default_region = "ap-southeast-1"
95+
else:
96+
sld = "volces"
97+
default_region = "cn-beijing"
98+
99+
region = getenv("AGENTKIT_TOOL_REGION", default_region)
91100
host = getenv(
92-
"AGENTKIT_TOOL_HOST", service + "." + region + ".volces.com"
101+
"AGENTKIT_TOOL_HOST", service + "." + region + f".{sld}.com"
93102
) # temporary host for code run tool
94103
logger.debug(f"tools endpoint: {host}")
95104

@@ -99,7 +108,6 @@ def execute_skills(
99108
tool_user_session_id = agent_name + "_" + user_id + "_" + session_id
100109
logger.debug(f"tool_user_session_id: {tool_user_session_id}")
101110

102-
cloud_provider = getenv("CLOUD_PROVIDER", "", allow_false_values=True)
103111
scheme = getenv("AGENTKIT_TOOL_SCHEME", "https", allow_false_values=True).lower()
104112
if scheme not in {"http", "https"}:
105113
scheme = "https"
@@ -141,7 +149,9 @@ def execute_skills(
141149
service="sts",
142150
version="2018-01-01",
143151
region=region,
144-
host="sts.volcengineapi.com",
152+
host="sts.volcengineapi.com"
153+
if cloud_provider != "byteplus"
154+
else "open.byteplusapi.com",
145155
header=header,
146156
)
147157
try:

veadk/tools/builtin_tools/run_code.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,18 @@ def run_code(
4545
service = getenv(
4646
"AGENTKIT_TOOL_SERVICE_CODE", "agentkit"
4747
) # temporary service for code run tool
48-
region = getenv("AGENTKIT_TOOL_REGION", "cn-beijing")
48+
49+
cloud_provider = (os.getenv("CLOUD_PROVIDER") or "").lower()
50+
if cloud_provider == "byteplus":
51+
sld = "bytepluses"
52+
default_region = "ap-southeast-1"
53+
else:
54+
sld = "volces"
55+
default_region = "cn-beijing"
56+
57+
region = getenv("AGENTKIT_TOOL_REGION", default_region)
4958
host = getenv(
50-
"AGENTKIT_TOOL_HOST", service + "." + region + ".volces.com"
59+
"AGENTKIT_TOOL_HOST", service + "." + region + f".{sld}.com"
5160
) # temporary host for code run tool
5261
scheme = getenv("AGENTKIT_TOOL_SCHEME", "https", allow_false_values=True).lower()
5362
if scheme not in {"http", "https"}:

veadk/tools/skills_tools/download_skills_tool.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,18 @@ def download_skills_tool(
6565
secret_key = cred.secret_access_key
6666
session_token = cred.session_token
6767

68+
cloud_provider = (os.getenv("CLOUD_PROVIDER") or "").lower()
69+
if cloud_provider == "byteplus":
70+
sld = "byteplusapi"
71+
default_region = "ap-southeast-1"
72+
else:
73+
sld = "volces"
74+
default_region = "cn-beijing"
75+
6876
# Get service configuration
6977
service = os.getenv("AGENTKIT_TOOL_SERVICE_CODE", "agentkit")
70-
region = os.getenv("AGENTKIT_TOOL_REGION", "cn-beijing")
71-
host = os.getenv("AGENTKIT_SKILL_HOST", "open.volcengineapi.com")
78+
region = os.getenv("AGENTKIT_TOOL_REGION", default_region)
79+
host = os.getenv("AGENTKIT_SKILL_HOST", service + "." + region + f".{sld}.com")
7280

7381
# Ensure download path exists
7482
download_dir = Path(download_path)

veadk/tools/skills_tools/register_skills_tool.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,19 @@ def register_skills_tool(
8787
try:
8888
from veadk.auth.veauth.utils import get_credential_from_vefaas_iam
8989

90+
cloud_provider = (os.getenv("CLOUD_PROVIDER") or "").lower()
91+
if cloud_provider == "byteplus":
92+
sld = "byteplusapi"
93+
default_region = "ap-southeast-1"
94+
else:
95+
sld = "volces"
96+
default_region = "cn-beijing"
97+
9098
agentkit_tool_service = os.getenv("AGENTKIT_TOOL_SERVICE_CODE", "agentkit")
91-
agentkit_skill_host = os.getenv("AGENTKIT_SKILL_HOST", "open.volcengineapi.com")
92-
region = os.getenv("AGENTKIT_TOOL_REGION", "cn-beijing")
99+
region = os.getenv("AGENTKIT_TOOL_REGION", default_region)
100+
agentkit_skill_host = os.getenv(
101+
"AGENTKIT_SKILL_HOST", agentkit_tool_service + "." + region + f".{sld}.com"
102+
)
93103

94104
access_key = os.getenv("VOLCENGINE_ACCESS_KEY")
95105
secret_key = os.getenv("VOLCENGINE_SECRET_KEY")
@@ -109,7 +119,9 @@ def register_skills_tool(
109119
service="sts",
110120
version="2018-01-01",
111121
region=region,
112-
host="sts.volcengineapi.com",
122+
host="sts.volcengineapi.com"
123+
if cloud_provider != "byteplus"
124+
else "open.byteplusapi.com",
113125
header={"X-Security-Token": session_token},
114126
)
115127
try:

0 commit comments

Comments
 (0)