Skip to content

Commit 84d0f6a

Browse files
fix: markdown lint error (missing blank line)
1 parent bc7ae04 commit 84d0f6a

File tree

21 files changed

+480
-3
lines changed

21 files changed

+480
-3
lines changed

01-tutorials/workshop/session1/.env.sample renamed to 01-tutorials/workshop/session1/langchain_agent_deploy_sample/.env.sample

File renamed without changes.

01-tutorials/workshop/session1/README.md renamed to 01-tutorials/workshop/session1/langchain_agent_deploy_sample/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
我们将对比 `langchain_agent.py` (原生实现) 和 `agent.py` (AgentKit 适配版),改造过程仅需以下 **3 点** 极小改动:
1010

1111
1. **引入 SDK 并初始化应用**
12+
1213
```python
1314
# 引入 AgentKit SDK
1415
from agentkit.apps import AgentkitSimpleApp
@@ -19,6 +20,7 @@
1920

2021
2. **标记入口函数**
2122
使用 `@app.entrypoint` 装饰器标记您的主逻辑函数。
23+
2224
```python
2325
@app.entrypoint
2426
async def run(payload: dict, headers: dict):
@@ -27,6 +29,7 @@
2729

2830
3. **按照标准协议返回**
2931
将原本直接打印到控制台的输出,改为 `yield` 返回标准 JSON 格式的 Event 数据。
32+
3033
```python
3134
# 原生 LangChain: print(chunk)
3235
# AgentKit 适配:
@@ -76,6 +79,10 @@ session1/
7679
```bash
7780
cp .env.sample .env
7881
# 编辑 .env 文件,填入 OPENAI_API_KEY 等必填项
82+
83+
# 火山引擎访问凭证(必需)
84+
export VOLCENGINE_ACCESS_KEY=<Your Access Key>
85+
export VOLCENGINE_SECRET_KEY=<Your Secret Key>
7986
```
8087

8188
### 调试方法
@@ -91,7 +98,7 @@ uv run langchain_agent.py
9198
uv run agent.py
9299
93100
# 在新终端运行客户端测试
94-
uv run local_client.py
101+
uv run client.py
95102
```
96103

97104
## AgentKit 部署
@@ -119,7 +126,7 @@ agentkit launch
119126

120127
```bash
121128
# <URL> 是 launch 命令输出的服务访问地址
122-
agentkit invoke --url <URL> 'Hello, can you calculate 10 + 20 and tell me the length of the word "AgentKit"?'
129+
agentkit invoke 'Hello, can you calculate 10 + 20 and tell me the length of the word "AgentKit"?'
123130
```
124131

125132
## 示例提示词

01-tutorials/workshop/session1/agent.py renamed to 01-tutorials/workshop/session1/langchain_agent_deploy_sample/agent.py

File renamed without changes.

01-tutorials/workshop/session1/local_client.py renamed to 01-tutorials/workshop/session1/langchain_agent_deploy_sample/client.py

File renamed without changes.

01-tutorials/workshop/session1/langchain_agent.py renamed to 01-tutorials/workshop/session1/langchain_agent_deploy_sample/langchain_agent.py

File renamed without changes.

01-tutorials/workshop/session1/pyproject.toml renamed to 01-tutorials/workshop/session1/langchain_agent_deploy_sample/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[project]
2-
name = "session1"
2+
name = "langchain_agent_deploy_sample"
33
version = "0.1.0"
44
description = "Add your description here"
55
readme = "README.md"

01-tutorials/workshop/session1/requirements.txt renamed to 01-tutorials/workshop/session1/langchain_agent_deploy_sample/requirements.txt

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTKIT_TOOL_ID=t-yebeztqadco2eybtg59c
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Session 1 - 带有 Sandbox 工具的智能体
2+
3+
## 概述
4+
5+
本示例演示了一个集成代码沙箱(Sandbox)执行能力的智能体。该智能体可以编写并执行 Python 代码,用于解决数学计算、模拟实验或逻辑谜题等任务。
6+
7+
## 核心功能
8+
9+
1. **Sandbox集成**:集成安全沙箱环境,支持 Python 代码的动态生成与执行。
10+
2. **复杂计算**:利用 Python 强大的计算库解决自然语言难以处理的数学和逻辑问题。
11+
3. **AgentKit 适配**:符合 AgentKit 标准协议,支持云端部署和流式交互。
12+
13+
## Agent 能力
14+
15+
本 Agent 具备以下基础能力:
16+
17+
- **代码执行**:通过 `run_code` 工具在沙箱中执行 Python 代码。
18+
- **动态计算**:编写算法解决复杂计算问题(如蒙特卡洛模拟)。
19+
- **结果反馈**:执行结果直接反馈给智能体,辅助生成最终答案。
20+
21+
## 目录结构说明
22+
23+
```bash
24+
sandbox_tool_sample/
25+
├── agent.py # 智能体核心逻辑,集成了 run_code 工具
26+
├── client.py # 本地测试客户端
27+
├── agentkit.yaml # AgentKit 部署配置文件
28+
├── .env # 环境变量配置文件
29+
└── README.md # 说明文档
30+
```
31+
32+
## 本地运行
33+
34+
### 1. 前置准备
35+
36+
在 AgentKit 平台创建沙箱工具,获取工具 ID,步骤如下:
37+
38+
1. 登录 AgentKit 平台进入 Sandbox 页面
39+
40+
![toolpage](./assets/images/tool_page.png)
41+
42+
2. 创建沙箱工具
43+
44+
![create](./assets/images/tool_create.png)
45+
46+
3. 获取工具 ID
47+
48+
![get](./assets/images/tool_id.png)
49+
50+
环境配置:确保已安装 `uv` 并配置好环境变量。
51+
52+
```bash
53+
uv sync
54+
source .venv/bin/activate
55+
cp .env.sample .env
56+
# 编辑 .env 文件,填入必要的 AGENTKIT_TOOL_ID 环境变量
57+
58+
# 火山引擎访问凭证(必需)
59+
export VOLCENGINE_ACCESS_KEY=<Your Access Key>
60+
export VOLCENGINE_SECRET_KEY=<Your Secret Key>
61+
```
62+
63+
### 2. 启动服务与测试
64+
65+
首先,使用以下命令启动智能体服务(默认监听 8000 端口):
66+
67+
```bash
68+
uv run agent.py
69+
```
70+
71+
在保持服务运行的同时,打开一个新的终端窗口,运行本地测试客户端:
72+
73+
```bash
74+
uv run client.py
75+
```
76+
77+
`client.py` 会向智能体发送请求,验证其代码生成与执行能力。
78+
79+
## AgentKit 部署
80+
81+
部署过程完全自动化,支持 `.env` 环境变量自动同步。
82+
83+
### 1. 初始化配置
84+
85+
```bash
86+
agentkit config
87+
```
88+
89+
此命令会以交互方式引导您完成配置,生成 `agentkit.yaml` 文件。
90+
91+
### 2. 部署上线
92+
93+
```bash
94+
agentkit launch
95+
```
96+
97+
`agentkit launch` 会将智能体部署到 AgentKit 平台,并自动同步本地 `.env` 中的环境变量。
98+
99+
### 3. 在线测试
100+
101+
部署完成后,您可以使用 CLI 直接调用云端智能体:
102+
103+
```bash
104+
agentkit invoke '帮我通过蒙特卡洛模拟算一下圆周率 PI 的值'
105+
```
106+
107+
## 示例提示词
108+
109+
- "帮我通过蒙特卡洛模拟算一下圆周率 PI 的值"
110+
- "用 Python 计算第 100 个斐波那契数"
111+
- "生成一个 10 个随机数的列表并排序"
112+
113+
## 效果展示
114+
115+
- **代码生成**:Agent 会根据问题自动生成 Python 代码。
116+
- **执行反馈**:Sandbox 执行代码并返回 stdout/stderr,Agent 根据输出回答问题。
117+
118+
## 常见问题
119+
120+
- **Q: 为什么代码执行失败?**
121+
- A: 请检查 AGENTKIT_TOOL_ID 是否正确,以及网络是否通畅。
122+
- **Q: 沙箱支持哪些库?**
123+
- A: 默认支持 Python 标准库。
124+
125+
## 代码许可
126+
127+
本工程遵循 Apache 2.0 License。
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import logging
2+
import os
3+
4+
from google.adk.agents import RunConfig
5+
from google.adk.agents.run_config import StreamingMode
6+
from google.genai.types import Content, Part
7+
from veadk import Agent, Runner
8+
from veadk.memory.short_term_memory import ShortTermMemory
9+
from veadk.tools.builtin_tools.web_search import web_search
10+
from veadk.tools.builtin_tools.run_code import run_code
11+
12+
from agentkit.apps import AgentkitAgentServerApp
13+
14+
short_term_memory = ShortTermMemory(backend="local")
15+
16+
from agentkit.apps import AgentkitSimpleApp
17+
18+
logger = logging.getLogger(__name__)
19+
20+
app_name = "agent_with_runcode"
21+
22+
agent: Agent = Agent(
23+
name="code_agent",
24+
model_name="doubao-seed-1-6-251015",
25+
description="A fun Python coding assistant",
26+
instruction="你是一个有趣的Python代码实验员。你的任务是利用沙箱环境解决各种有趣的问题。比如:通过蒙特卡洛方法模拟概率问题,生成有趣的ASCII艺术字,或者通过算法解决逻辑谜题。请尽量使用 Python 标准库,必须使用 `run_code` 工具执行代码并向用户展示结果。避免复杂的外部依赖安装。",
27+
tools=[run_code],
28+
)
29+
30+
runner = Runner(agent=agent, app_name=app_name)
31+
root_agent = agent
32+
33+
agent_server_app = AgentkitAgentServerApp(
34+
agent=agent, short_term_memory=short_term_memory,
35+
)
36+
37+
if __name__ == "__main__":
38+
agent_server_app.run(host="0.0.0.0", port=8000)
39+

0 commit comments

Comments
 (0)