From 1a8fe8fded1d224948d7f4f2ae8b52188af584d8 Mon Sep 17 00:00:00 2001 From: "liulei.88" Date: Thu, 11 Dec 2025 23:11:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(tools):=20=E6=B7=BB=E5=8A=A0=20AGNRKIT=5FT?= =?UTF-8?q?OOL=5FSCHEMA=20=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20http/https=20=E5=8D=8F=E8=AE=AE=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持通过环境变量配置 AgentKit Tools 的调用协议,默认为 https --- docs/docs/tools/builtin.md | 1 + veadk/tools/builtin_tools/run_code.py | 4 ++++ veadk/utils/volcengine_sign.py | 28 ++++++++++++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/docs/tools/builtin.md b/docs/docs/tools/builtin.md index b262e875..5d232513 100644 --- a/docs/docs/tools/builtin.md +++ b/docs/docs/tools/builtin.md @@ -146,6 +146,7 @@ veADK 集成了以下火山引擎工具: - `AGENTKIT_TOOL_ID`:用于调用火山引擎AgentKit Tools的沙箱环境Id - `AGENTKIT_TOOL_HOST`:用于调用火山引擎AgentKit Tools的EndPoint - `AGENTKIT_TOOL_SERVICE_CODE`:用于调用AgentKit Tools的ServiceCode + - `AGENTKIT_TOOL_SCHEME`:用于切换调用 AgentKit Tools 的协议,允许 `http`/`https`,默认 `https` 环境变量列表: diff --git a/veadk/tools/builtin_tools/run_code.py b/veadk/tools/builtin_tools/run_code.py index 4e05fe2d..8a1c0fe5 100644 --- a/veadk/tools/builtin_tools/run_code.py +++ b/veadk/tools/builtin_tools/run_code.py @@ -49,6 +49,9 @@ def run_code( host = getenv( "AGENTKIT_TOOL_HOST", service + "." + region + ".volces.com" ) # temporary host for code run tool + scheme = getenv("AGENTKIT_TOOL_SCHEME", "https", allow_false_values=True).lower() + if scheme not in {"http", "https"}: + scheme = "https" logger.debug(f"tools endpoint: {host}") session_id = tool_context._invocation_context.session.id @@ -103,6 +106,7 @@ def run_code( region=region, host=host, header=header, + scheme=scheme, ) logger.debug(f"Invoke run code response: {res}") diff --git a/veadk/utils/volcengine_sign.py b/veadk/utils/volcengine_sign.py index b47b6571..db8f5c68 100644 --- a/veadk/utils/volcengine_sign.py +++ b/veadk/utils/volcengine_sign.py @@ -25,6 +25,7 @@ Region = "" Host = "" ContentType = "" +Scheme = "https" def norm_query(params): @@ -59,7 +60,17 @@ def hash_sha256(content: str): # 第二步:签名请求函数 -def request(method, date, query, header, ak, sk, action, body): +def request( + method, + date, + query, + header, + ak, + sk, + action, + body, + scheme: Literal["http", "https"] = "https", +): # 第三步:创建身份证明。其中的 Service 和 Region 字段是固定的。ak 和 sk 分别代表 # AccessKeyID 和 SecretAccessKey。同时需要初始化签名结构体。一些签名计算时需要的属性也在这里处理。 # 初始化身份证明结构体 @@ -151,7 +162,7 @@ def request(method, date, query, header, ak, sk, action, body): # 第六步:将 Signature 签名写入 HTTP Header 中,并发送 HTTP 请求。 r = requests.request( method=method, - url="https://{}{}".format(request_param["host"], request_param["path"]), + url=f"{scheme}://{request_param['host']}{request_param['path']}", headers=header, params=request_param["query"], data=request_param["body"], @@ -175,6 +186,7 @@ def ve_request( header: dict = {}, query: dict = {}, method: Literal["GET", "POST", "PUT", "DELETE"] = "POST", + scheme: Literal["http", "https"] = "https", ): global Service Service = service @@ -186,6 +198,8 @@ def ve_request( Host = host global ContentType ContentType = content_type + global Scheme + Scheme = scheme AK = ak SK = sk now = datetime.datetime.utcnow() @@ -195,7 +209,15 @@ def ve_request( try: response_body = request( - method, now, query, header, AK, SK, action, json.dumps(request_body) + method, + now, + query, + header, + AK, + SK, + action, + json.dumps(request_body), + Scheme, ) return response_body except Exception as e: