Skip to content

Commit 70f372d

Browse files
author
liulei.88
committed
feat(tools): 添加 AGNRKIT_TOOL_SCHEMA 环境变量支持 http/https 协议切换
支持通过环境变量配置 AgentKit Tools 的调用协议,默认为 https
1 parent dfd49e1 commit 70f372d

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

docs/docs/tools/builtin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ veADK 集成了以下火山引擎工具:
146146
- `AGENTKIT_TOOL_ID`:用于调用火山引擎AgentKit Tools的沙箱环境Id
147147
- `AGENTKIT_TOOL_HOST`:用于调用火山引擎AgentKit Tools的EndPoint
148148
- `AGENTKIT_TOOL_SERVICE_CODE`:用于调用AgentKit Tools的ServiceCode
149+
- `AGNRKIT_TOOL_SCHEME`:用于切换调用 AgentKit Tools 的协议,允许 `http`/`https`,默认 `https`
149150

150151
环境变量列表:
151152

veadk/tools/builtin_tools/run_code.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def run_code(
4949
host = getenv(
5050
"AGENTKIT_TOOL_HOST", service + "." + region + ".volces.com"
5151
) # temporary host for code run tool
52+
scheme = getenv("AGNRKIT_TOOL_SCHEME", "https", allow_false_values=True).lower()
53+
if scheme not in {"http", "https"}:
54+
scheme = "https"
5255
logger.debug(f"tools endpoint: {host}")
5356

5457
session_id = tool_context._invocation_context.session.id
@@ -103,6 +106,7 @@ def run_code(
103106
region=region,
104107
host=host,
105108
header=header,
109+
scheme=scheme,
106110
)
107111
logger.debug(f"Invoke run code response: {res}")
108112

veadk/utils/volcengine_sign.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Region = ""
2626
Host = ""
2727
ContentType = ""
28+
Scheme = "https"
2829

2930

3031
def norm_query(params):
@@ -59,7 +60,17 @@ def hash_sha256(content: str):
5960

6061

6162
# 第二步:签名请求函数
62-
def request(method, date, query, header, ak, sk, action, body):
63+
def request(
64+
method,
65+
date,
66+
query,
67+
header,
68+
ak,
69+
sk,
70+
action,
71+
body,
72+
scheme: Literal["http", "https"] = "https",
73+
):
6374
# 第三步:创建身份证明。其中的 Service 和 Region 字段是固定的。ak 和 sk 分别代表
6475
# AccessKeyID 和 SecretAccessKey。同时需要初始化签名结构体。一些签名计算时需要的属性也在这里处理。
6576
# 初始化身份证明结构体
@@ -151,7 +162,7 @@ def request(method, date, query, header, ak, sk, action, body):
151162
# 第六步:将 Signature 签名写入 HTTP Header 中,并发送 HTTP 请求。
152163
r = requests.request(
153164
method=method,
154-
url="https://{}{}".format(request_param["host"], request_param["path"]),
165+
url=f"{scheme}://{request_param['host']}{request_param['path']}",
155166
headers=header,
156167
params=request_param["query"],
157168
data=request_param["body"],
@@ -175,6 +186,7 @@ def ve_request(
175186
header: dict = {},
176187
query: dict = {},
177188
method: Literal["GET", "POST", "PUT", "DELETE"] = "POST",
189+
scheme: Literal["http", "https"] = "https",
178190
):
179191
global Service
180192
Service = service
@@ -186,6 +198,8 @@ def ve_request(
186198
Host = host
187199
global ContentType
188200
ContentType = content_type
201+
global Scheme
202+
Scheme = scheme
189203
AK = ak
190204
SK = sk
191205
now = datetime.datetime.utcnow()
@@ -195,7 +209,15 @@ def ve_request(
195209

196210
try:
197211
response_body = request(
198-
method, now, query, header, AK, SK, action, json.dumps(request_body)
212+
method,
213+
now,
214+
query,
215+
header,
216+
AK,
217+
SK,
218+
action,
219+
json.dumps(request_body),
220+
Scheme,
199221
)
200222
return response_body
201223
except Exception as e:

0 commit comments

Comments
 (0)