You need to enable JavaScript to run this app.
文档中心
AgentKit

AgentKit

复制全文
下载 pdf
Sandbox Tool
InvokeTool - 在工具中执行命令
复制全文
下载 pdf
InvokeTool - 在工具中执行命令
调用 InvokeTool 接口在沙箱工具实例中执行命令。​
接口说明​
注意​
调用本接口时,服务地址与其他接口不同,请区分不同地域使用https://agentkit.<regionid>.volces.com。​
请求参数​
下方仅列出该接口特有的请求参数和部分公共参数。更多信息请见公共参数。​
​
参数​
类型​
是否必选​
示例值​
描述​
Action​
String​
是​
InvokeTool​
要执行的操作,取值:InvokeTool。​
ToolId​
String​
是​
t-yebi04gb28o2eybt****​
工具ID。​
OperationType​
​
String​
是​
​
RunCode​
操作类型。​
  • 取值:RunCode。即使用代码执行命令,决定最后调用沙箱实例的接口如/v1/jupyter/execute。​
OperationPayload​
​
String​
是​
{ "code": "print('helloworld')", "timeout": 30, "kernel_name": "python3"}​
请求沙箱实例中接口的具体参数,取值:​
  • code:需要执行的python代码。​
  • timeout:代码执行超时时长。​
  • kernel_name:内核名称,例如python3、python3.11、python3.12,默认为python3。​
SessionId​
String​
否​
s-yecrzqygw0o2eybt****​
指定执行请求的会话ID。传入参数但未传入取值时则创建一个新的会话。​
说明​
  • 由于工具的生命周期结束时,SessionId也会随之不可用,因此建议优先使用UserSessionId执行请求。​
  • 如果SessionId和UserSessionId都不传入,则默认创建新的UserSessionId。​
UserSessionId​
String​
否​
session-1​
指定执行请求的用户会话信息,可以通过该字段指定执行请求的会话实例实现上下文隔离。​
  • 传入参数且传入取值时:根据传入的会话信息执行请求,如果会话信息不存在则创建一个新的会话。​
  • 传入参数但不传入取值时:创建一个新的会话。​
说明​
如果SessionId和UserSessionId都不传入,则默认创建新的UserSessionId。​
Ttl​
Integer​
否​
1800​
会话实例存活时长,即工具在一次 “用户 - 工具交互会话” 中,保持用户状态、操作上下文不丢失的有效时长。会话过期后,只需重新登录或重启操作即可。​
  • 单位:秒。​
  • 取值范围:60~86400。​
  • 默认值为:1800。​
​
返回参数​
下方仅列出本接口特有的返回参数。更多信息请参见返回结构。​
​
参数​
类型​
示例值​
描述​
ToolId​
String​
tool-3tigy72q3u3vj0x2****​
工具ID。​
UserSessionId​
String​
session-1​
用户会话信息。​
SessionId​
​
String​
s-yecrzqygw0o2eybt****​
会话ID。​
Endpoint​
String​
https://sd5acdbuo20h0ng5g****.apigateway-****.volceapi.com/?faasInstanceName=vefaas-****​
工具访问域名。​
​
InternalEndpoint​
String​
https://sd5acdbuo20h0ng5g****.apigateway-****.volceapi-inner.com/?faasInstanceName=vefaas-****​
工具内网访问域名。​
Result​
String​
{​
"success": true,​
"message": "Code executed successfully",​
"data": {​
"kernel_name": "python3",​
"session_id": "",​
"status": "ok",​
"execution_count": 1,​
"outputs": [​
{​
"output_type": "stream",​
"name": "stdout",​
"text": "helloworld",​
"data": null,​
"metadata": {},​
"execution_count": null,​
"ename": null,​
"evalue": null,​
"traceback": null​
}​
],​
"code": "print('helloworld')",​
"msg_id": ""​
}​
}​
工具执行结果。​
​
请求示例​
​
POST https://agentkit.cn-beijing.volces.com?Action=InvokeTool&Version=2025-10-30 HTTP/1.1​
Content-Type: application/json​
{​
"ToolId": "t-yebi04gb28o2eybt****",​
"UserSessionId": "session-1",​
"OperationType": "RunCode",​
"OperationPayload": "{\"code\": \"print('helloworld')\",\"timeout\": 30,\"kernel_name\": \"python3\"}"​
}​
​
返回示例​
​
{​
"ResponseMetadata": {​
"RequestId": "02176751173569200000000000000000000ffffac10029*******",​
"Action": "InvokeTool",​
"Version": "2025-10-30",​
"Service": "agentkit",​
"Region": "cn-beijing"​
},​
"Result": {​
"ToolId": "t-yebi04gb28o2eybt****",​
"UserSessionId": "session-1",​
"SessionId": "s-yecrzqygw0o2eybt****",​
"Endpoint": "https://sd5acdbuo20h0ng5g****.apigateway-****.volceapi.com/?faasInstanceName=vefaas-****",​
"InternalEndpoint": "",​
"Result": "{\n \"success\": true,\n \"message\": \"Code executed successfully\",\n \"data\": {\n \"kernel_name\": \"python3\",\n \"session_id\": \"****\",\n \"status\": \"ok\",\n \"execution_count\": 1,\n \"outputs\": [\n {\n \"output_type\": \"stream\",\n \"name\": \"stdout\",\n \"text\": \"helloworld\\n\",\n \"data\": null,\n \"metadata\": {},\n \"execution_count\": null,\n \"ename\": null,\n \"evalue\": null,\n \"traceback\": null\n }\n ],\n \"code\": \"print('helloworld')\",\n \"msg_id\": \"****\"\n }\n}"​
}​
}​
​
错误码​
您可访问公共错误码,获取更多错误码信息。​
最近更新时间:2026.02.05 11:20:44
这个页面对您有帮助吗?
有用
有用
无用
无用