Skip to content

Commit 8bea093

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

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-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_SCHEMA`:用于切换调用 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+
schema = getenv("AGNRKIT_TOOL_SCHEMA", "https", allow_false_values=True).lower()
53+
if schema not in {"http", "https"}:
54+
schema = "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+
schema=schema,
106110
)
107111
logger.debug(f"Invoke run code response: {res}")
108112

veadk/utils/volcengine_sign.py

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

2930

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

6061

6162
# 第二步:签名请求函数
62-
def request(method, date, query, header, ak, sk, action, body):
63+
def request(method, date, query, header, ak, sk, action, body, schema: Literal["http", "https"] = "https"):
6364
# 第三步:创建身份证明。其中的 Service 和 Region 字段是固定的。ak 和 sk 分别代表
6465
# AccessKeyID 和 SecretAccessKey。同时需要初始化签名结构体。一些签名计算时需要的属性也在这里处理。
6566
# 初始化身份证明结构体
@@ -151,7 +152,7 @@ def request(method, date, query, header, ak, sk, action, body):
151152
# 第六步:将 Signature 签名写入 HTTP Header 中,并发送 HTTP 请求。
152153
r = requests.request(
153154
method=method,
154-
url="https://{}{}".format(request_param["host"], request_param["path"]),
155+
url=f"{schema}://{request_param['host']}{request_param['path']}",
155156
headers=header,
156157
params=request_param["query"],
157158
data=request_param["body"],
@@ -175,6 +176,7 @@ def ve_request(
175176
header: dict = {},
176177
query: dict = {},
177178
method: Literal["GET", "POST", "PUT", "DELETE"] = "POST",
179+
schema: Literal["http", "https"] = "https",
178180
):
179181
global Service
180182
Service = service
@@ -186,6 +188,8 @@ def ve_request(
186188
Host = host
187189
global ContentType
188190
ContentType = content_type
191+
global Schema
192+
Schema = schema
189193
AK = ak
190194
SK = sk
191195
now = datetime.datetime.utcnow()
@@ -195,7 +199,15 @@ def ve_request(
195199

196200
try:
197201
response_body = request(
198-
method, now, query, header, AK, SK, action, json.dumps(request_body)
202+
method,
203+
now,
204+
query,
205+
header,
206+
AK,
207+
SK,
208+
action,
209+
json.dumps(request_body),
210+
Schema,
199211
)
200212
return response_body
201213
except Exception as e:

0 commit comments

Comments
 (0)