Skip to content

Commit 981fe54

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents c0ed951 + 831329d commit 981fe54

File tree

15 files changed

+448
-37
lines changed

15 files changed

+448
-37
lines changed

docs/content/5.tools/3.sandbox-tools.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,73 @@ navigation:
55
icon: i-lucide-codesandbox
66
---
77

8-
提供多种沙箱工具:
8+
## 概述
99

10+
VeADK 提供多种沙箱工具,为 Agent 的执行与操作提供安全、隔离的运行环境。目前支持以下几种类型:
11+
- Code sandbox
1012
- Computer sandbox (TBD)
1113
- Browser sandbox (TBD)
12-
- Code sandbox (TBD)
14+
15+
当前,VeADK 支持两种方式调用 Code Sandbox:
16+
- (推荐)内建工具 [`run_code`](https://www.volcengine.com/docs/86681/1847934):该方式通过 AgentKit tools 调用,配置过程可自定义代码生成模型。通过设置环境变量 `AGENTKIT_TOOL_ID` 或者在 config.yaml 中添加配置即可开始使用:
17+
```yaml
18+
agentkit:
19+
tool:
20+
id: <your_id>
21+
```
22+
- MCP 工具 [`code_sandbox`](https://www.volcengine.com/mcp-marketplace/detail?name=Code-Sandbox%20MCP):该方式通过 MCP(Model Context Protocol) 调用 Code Sandbox 工具,具体步骤为:
23+
- 在 VeFaaS 一键部署 [Code Sandbox Agent 应用](https://www.volcengine.com/docs/6662/1538139),配置过程中可自定义代码生成模型;
24+
- 部署成功后,在部署的 Code sanbox 的应用详情标签页获取**访问地址**,地址形式是:{YOUR_URL}/?token={YOUR_TOKEN};
25+
- 为 Code sandbox [创建 MCP Server](https://www.volcengine.com/mcp-marketplace/detail?name=Code-Sandbox%20MCP) 并配置环境变量:
26+
```bash
27+
SANDBOX_API={YOUR_URL}
28+
AUTH_TOKEN={YOUR_TOKEN}
29+
```
30+
- 最后,将上述 Code sanbox 访问地址设置环境变量 `TOOL_CODE_SANDBOX_URL` 或者在 config.yaml 中添加配置即可开始使用:
31+
```yaml
32+
tool:
33+
code_sandbox:
34+
url: <your_url>
35+
```
36+
37+
38+
## 使用
39+
以下示例展示了在 VeADK 中如何通过两种方式调用沙箱工具来执行代码。
40+
41+
示例一:使用内建工具 `run_code`:
42+
43+
```python [agent.py]
44+
import asyncio
45+
from veadk import Agent, Runner
46+
from veadk.tools.builtin_tools.run_code import run_code
47+
48+
agent = Agent(
49+
instruction="你是一名资深的代码专家。请通过调用 run_code 工具执行代码、调试、并展示运行结果。",
50+
tools=[run_code]
51+
)
52+
53+
runner = Runner(agent=agent)
54+
55+
response = asyncio.run(runner.run(messages="请用Python写一个函数,计算斐波那契数列的前10项,并打印出来。"))
56+
57+
print(response)
58+
```
59+
60+
示例二:使用 MCP 工具 `code_sandbox`
61+
62+
```python [agent.py]
63+
import asyncio
64+
from veadk import Agent, Runner
65+
from veadk.tools.sandbox.code_sandbox import code_sandbox
66+
67+
agent = Agent(
68+
instruction="你是一名资深的代码专家。请通过调用 code_sandbox 工具执行代码、调试、并展示运行结果。",
69+
tools=[code_sandbox]
70+
)
71+
72+
runner = Runner(agent=agent)
73+
74+
response = asyncio.run(runner.run(messages="请用Python写一个函数,计算斐波那契数列的前10项,并打印出来。"))
75+
76+
print(response)
77+
```

veadk/a2a/ve_a2a_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(
3535
runner=Runner(
3636
agent=agent,
3737
app_name=app_name,
38+
short_term_memory=short_term_memory,
3839
),
3940
)
4041

veadk/agent.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from veadk.tracing.base_tracer import BaseTracer
4949
from veadk.utils.logger import get_logger
5050
from veadk.utils.patches import patch_asyncio, patch_tracer
51+
from veadk.tools.builtin_tools.agent_authorization import check_agent_authorization
5152
from veadk.version import VERSION
5253

5354
patch_tracer()
@@ -123,6 +124,8 @@ class Agent(LlmAgent):
123124
)
124125
"""
125126

127+
enable_authz: bool = False
128+
126129
def model_post_init(self, __context: Any) -> None:
127130
super().model_post_init(None) # for sub_agents init
128131

@@ -184,6 +187,18 @@ def model_post_init(self, __context: Any) -> None:
184187
load_memory.custom_metadata["backend"] = self.long_term_memory.backend
185188
self.tools.append(load_memory)
186189

190+
if self.enable_authz:
191+
if self.before_agent_callback:
192+
if isinstance(self.before_agent_callback, list):
193+
self.before_agent_callback.append(check_agent_authorization)
194+
else:
195+
self.before_agent_callback = [
196+
self.before_agent_callback,
197+
check_agent_authorization,
198+
]
199+
else:
200+
self.before_agent_callback = check_agent_authorization
201+
187202
logger.info(f"VeADK version: {VERSION}")
188203

189204
logger.info(f"{self.__class__.__name__} `{self.name}` init done.")

veadk/cli/cli_clean.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@click.command()
2626
@click.option(
27-
"--vefaas-application-name",
27+
"--vefaas-app-name",
2828
required=True,
2929
help="VeFaaS application name to clean",
3030
)
@@ -39,7 +39,7 @@
3939
help="Volcengine secret key, if not set, will use the value of environment variable VOLCENGINE_SECRET_KEY",
4040
)
4141
def clean(
42-
vefaas_application_name: str, volcengine_access_key: str, volcengine_secret_key: str
42+
vefaas_app_name: str, volcengine_access_key: str, volcengine_secret_key: str
4343
) -> None:
4444
"""
4545
Clean and delete a VeFaaS application from the cloud.
@@ -49,7 +49,7 @@ def clean(
4949
and monitor the deletion process until completion.
5050
5151
Args:
52-
vefaas_application_name (str): The name of the VeFaaS application to delete
52+
vefaas_app_name (str): The name of the VeFaaS application to delete
5353
volcengine_access_key (str): Volcengine access key for authentication.
5454
If None, will use VOLCENGINE_ACCESS_KEY environment variable
5555
volcengine_secret_key (str): Volcengine secret key for authentication.
@@ -63,24 +63,22 @@ def clean(
6363
if not volcengine_secret_key:
6464
volcengine_secret_key = getenv("VOLCENGINE_SECRET_KEY")
6565

66-
confirm = input(f"Confirm delete cloud app {vefaas_application_name}? (y/N): ")
66+
confirm = input(f"Confirm delete cloud app {vefaas_app_name}? (y/N): ")
6767
if confirm.lower() != "y":
6868
click.echo("Delete cancelled.")
6969
return
7070
else:
7171
vefaas_client = VeFaaS(
7272
access_key=volcengine_access_key, secret_key=volcengine_secret_key
7373
)
74-
vefaas_application_id = vefaas_client.find_app_id_by_name(
75-
vefaas_application_name
76-
)
74+
vefaas_application_id = vefaas_client.find_app_id_by_name(vefaas_app_name)
7775
vefaas_client.delete(vefaas_application_id)
7876
click.echo(
79-
f"Cloud app {vefaas_application_name} delete request has been sent to VeFaaS"
77+
f"Cloud app {vefaas_app_name} delete request has been sent to VeFaaS"
8078
)
8179
while True:
8280
try:
83-
id = vefaas_client.find_app_id_by_name(vefaas_application_name)
81+
id = vefaas_client.find_app_id_by_name(vefaas_app_name)
8482
if not id:
8583
break
8684
time.sleep(3)

veadk/cli/cli_deploy.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
@click.command()
2424
@click.option(
25-
"--access-key",
25+
"--volcengine-access-key",
2626
default=None,
2727
help="Volcengine access key",
2828
)
2929
@click.option(
30-
"--secret-key",
30+
"--volcengine-secret-key",
3131
default=None,
3232
help="Volcengine secret key",
3333
)
@@ -52,8 +52,8 @@
5252
@click.option("--use-adk-web", is_flag=True, help="Whether to use ADK Web")
5353
@click.option("--path", default=".", help="Local project path")
5454
def deploy(
55-
access_key: str,
56-
secret_key: str,
55+
volcengine_access_key: str,
56+
volcengine_secret_key: str,
5757
vefaas_app_name: str,
5858
veapig_instance_name: str,
5959
veapig_service_name: str,
@@ -77,9 +77,9 @@ def deploy(
7777
5. Cleaning up temporary files
7878
7979
Args:
80-
access_key: Volcengine access key for API authentication. If not provided,
80+
volcengine_access_key: Volcengine access key for API authentication. If not provided,
8181
will use VOLCENGINE_ACCESS_KEY environment variable
82-
secret_key: Volcengine secret key for API authentication. If not provided,
82+
volcengine_secret_key: Volcengine secret key for API authentication. If not provided,
8383
will use VOLCENGINE_SECRET_KEY environment variable
8484
vefaas_app_name: Name of the target Volcengine FaaS application where the
8585
project will be deployed
@@ -111,10 +111,10 @@ def deploy(
111111

112112
logger = get_logger(__name__)
113113

114-
if not access_key:
115-
access_key = getenv("VOLCENGINE_ACCESS_KEY")
116-
if not secret_key:
117-
secret_key = getenv("VOLCENGINE_SECRET_KEY")
114+
if not volcengine_access_key:
115+
volcengine_access_key = getenv("VOLCENGINE_ACCESS_KEY")
116+
if not volcengine_secret_key:
117+
volcengine_secret_key = getenv("VOLCENGINE_SECRET_KEY")
118118

119119
user_proj_abs_path = Path(path).resolve()
120120
template_dir_path = Path(vefaas.__file__).parent / "template"

veadk/cli/cli_update.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
help="Volcengine secret key for authentication. Defaults to VOLCENGINE_SECRET_KEY environment variable.",
3434
)
3535
@click.option(
36-
"--application-name",
36+
"--vefaas-app-name",
3737
required=True,
3838
help="Name of the cloud application to update.",
3939
)
@@ -45,7 +45,7 @@
4545
def update(
4646
volcengine_access_key: str,
4747
volcengine_secret_key: str,
48-
application_name: str,
48+
vefaas_app_name: str,
4949
path: str,
5050
) -> None:
5151
"""Update function code of a deployed cloud application on Volcengine FaaS.
@@ -65,7 +65,7 @@ def update(
6565
If not provided, uses VOLCENGINE_ACCESS_KEY environment variable.
6666
volcengine_secret_key: Volcengine platform secret key for authentication.
6767
If not provided, uses VOLCENGINE_SECRET_KEY environment variable.
68-
application_name: Name of the existing cloud application to update.
68+
vefaas_app_name: Name of the existing cloud application to update.
6969
path: Local directory path containing the updated agent project.
7070
Defaults to current directory if not specified.
7171
@@ -93,11 +93,11 @@ def update(
9393
try:
9494
# Update function code
9595
updated_app = engine.update_function_code(
96-
application_name=application_name,
96+
application_name=vefaas_app_name,
9797
path=path,
9898
)
9999

100-
logger.info(f"Successfully updated cloud application '{application_name}'")
100+
logger.info(f"Successfully updated cloud application '{vefaas_app_name}'")
101101
logger.info(f"Endpoint: {updated_app.vefaas_endpoint}")
102102
logger.info(f"Application ID: {updated_app.vefaas_application_id}")
103103

veadk/configs/auth_configs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class VeIdentityConfig(BaseSettings):
3939
If not provided, the endpoint will be auto-generated based on the region.
4040
"""
4141

42+
role_session_name: str = "veadk_default_assume_role_session"
43+
"""Role session name, used to distinguish different sessions in audit logs.
44+
"""
45+
4246
def get_endpoint(self) -> str:
4347
"""Get the endpoint URL for Identity service.
4448

0 commit comments

Comments
 (0)