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
1 change: 1 addition & 0 deletions docs/docs/tools/builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

环境变量列表:

Expand Down
4 changes: 4 additions & 0 deletions veadk/tools/builtin_tools/run_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -103,6 +106,7 @@ def run_code(
region=region,
host=host,
header=header,
scheme=scheme,
)
logger.debug(f"Invoke run code response: {res}")

Expand Down
28 changes: 25 additions & 3 deletions veadk/utils/volcengine_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Region = ""
Host = ""
ContentType = ""
Scheme = "https"


def norm_query(params):
Expand Down Expand Up @@ -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。同时需要初始化签名结构体。一些签名计算时需要的属性也在这里处理。
# 初始化身份证明结构体
Expand Down Expand Up @@ -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"],
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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:
Expand Down