Skip to content

Commit c02ba62

Browse files
chore(docs): update docus (#216)
* chore(docs): update docus * feat: add cli kb * update trouble shooting * fix picture bugs
1 parent f6e964e commit c02ba62

File tree

9 files changed

+246
-67
lines changed

9 files changed

+246
-67
lines changed

docs/content/1.introduction/4.troubleshooting.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ navigation:
3333

3434
2. **安装依赖失败,显示依赖安装空间不足**
3535
- VeFaaS 最大依赖安装大小默认为 250 MB,若需更大空间,请联系 VeFaaS 产品团队扩容。
36+
37+
3. **显示`[apig_gateway][][get_info][Error] ExceededQuota`**
38+
- ![网关超额报错](/images/troubleshooting-03.jpeg)
39+
- 火山引擎 APIG 中,Serveless 类型的网关实例最多只能有1个。需要指定唯一的网关实例。

docs/content/3.agent/1.agent.md

Lines changed: 97 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -93,55 +93,7 @@ print(response) # 北京天气晴朗,气温25°C。
9393

9494
下面提供了不同类型工作流智能体的定义方法:
9595

96-
#### 顺序类 `SequentialAgent`
97-
98-
#### 循环类 `LoopAgent`
99-
100-
```python [loop_agent.py]
101-
102-
```
103-
104-
#### 并行类 `ParallelAgent`
105-
106-
```python [parallel_agent.py]
107-
108-
```
109-
110-
### 选项
111-
112-
工作流 Agent 采用统一的参数:
113-
114-
::field-group
115-
::field{name="name" type="string"}
116-
智能体的名称
117-
::
118-
119-
::field{name="description" type="string"}
120-
默认为 `DEFAULT_DESCRIPTION` - 智能体的描述,在 A2A 场景下会有帮助
121-
::
122-
123-
::field{name="instruction" type="string"}
124-
默认为 `DEFAULT_INSTRUCTION` - 智能体的指令,例如函数调用的原则
125-
::
126-
127-
::field{name="sub_agents" type="list[BaseAgent]"}
128-
默认为 `[]` - 提供给该智能体的子智能体列表
129-
::
130-
131-
::field{name="tracers" type="list[BaseTracer]"}
132-
默认为 `[]` - 提供给该智能体的 tracer
133-
::
134-
::
135-
136-
::note
137-
更多兼容字段请参考 [Google ADK Agents 定义](https://github.com/google/adk-python/blob/main/src/google/adk/agents/)
138-
::
139-
140-
## 多智能体协作
141-
142-
使用 VeADK 可以构建多 Agent 协作, 主 Agent 通过 `sub_agents` 机制协调多个子 Agent 完成复杂任务。
143-
144-
### 自主决策 Agent
96+
#### LLM 模式
14597

14698
利用能够自主决策的 Agent 来定义一个生活提醒智能体,分别定义了三个智能体:
14799

@@ -182,9 +134,9 @@ print(response)
182134
# It's a comfortable and warm day. You can choose light and breathable clothes. For example, a short - sleeved T - shirt or a thin shirt paired with casual pants or a skirt would be great. Since it's sunny, don't forget to wear a hat and sunglasses to protect yourself from the sun. Also, you can carry a light jacket in case the temperature drops in the evening, but it might not be necessary. Enjoy your day in Beijing!
183135
```
184136

185-
### `SequentialAgent`
137+
#### 顺序类 `SequentialAgent`
186138

187-
```python [sequential_agent.py]
139+
```python[seq_agent.py]
188140
import asyncio
189141
190142
from veadk import Agent, Runner
@@ -210,14 +162,106 @@ response = asyncio.run(runner.run("你好"))
210162
print(response)
211163
```
212164

213-
### `LoopAgent`
165+
#### 循环类 `LoopAgent`
214166

215167
```python [loop_agent.py]
168+
import asyncio
169+
from veadk import Agent, Runner
170+
from veadk.agents.loop_agent import LoopAgent
171+
from google.adk.tools.tool_context import ToolContext
172+
173+
def exit_loop(tool_context: ToolContext):
174+
print(f" [Tool Call] exit_loop triggered by {tool_context.agent_name}")
175+
tool_context.actions.escalate = True
176+
return {}
177+
178+
planner_agent = Agent(
179+
name="planner_agent",
180+
description="Decomposes a complex task into smaller actionable steps.",
181+
instruction=(
182+
"Given the user's goal and current progress, decide the NEXT step to take. You don't need to execute the step, just describe it clearly. "
183+
"If all steps are done, respond with 'TASK COMPLETE'."
184+
),
185+
)
216186

187+
executor_agent = Agent(
188+
name="executor_agent",
189+
description="Executes a given step and returns the result.",
190+
instruction="Execute the provided step and describe what was done or what result was obtained. If you received 'TASK COMPLETE', you must call the 'exit_loop' function. Do not output any text.",
191+
tools=[exit_loop],
192+
)
193+
194+
root_agent = LoopAgent(
195+
sub_agents=[planner_agent, executor_agent],
196+
max_iterations=3, # Limit the number of loops to prevent infinite loops
197+
)
198+
199+
runner = Runner(root_agent)
200+
201+
response = asyncio.run(runner.run("帮我写一首三行的小诗,主题是秋天"))
202+
203+
print(response)
217204
```
218205

219-
### `ParallelAgent`
206+
#### 并行类 `ParallelAgent`
220207

221208
```python [parallel_agent.py]
209+
import asyncio
210+
211+
from veadk import Agent, Runner
212+
from veadk.agents.parallel_agent import ParallelAgent
213+
214+
pros_agent = Agent(
215+
name="pros_agent",
216+
description="An expert that identifies the advantages of a topic.",
217+
instruction="List and explain the positive aspects or advantages of the given topic.",
218+
)
222219

220+
cons_agent = Agent(
221+
name="cons_agent",
222+
description="An expert that identifies the disadvantages of a topic.",
223+
instruction="List and explain the negative aspects or disadvantages of the given topic.",
224+
)
225+
226+
root_agent = ParallelAgent(sub_agents=[pros_agent, cons_agent])
227+
228+
runner = Runner(root_agent)
229+
230+
response = asyncio.run(runner.run("请分析 LLM-as-a-Judge 这种评测模式的优劣"))
231+
232+
print(response)
223233
```
234+
235+
### 选项
236+
237+
工作流 Agent 采用统一的参数:
238+
239+
::field-group
240+
::field{name="name" type="string"}
241+
智能体的名称
242+
::
243+
244+
::field{name="description" type="string"}
245+
默认为 `DEFAULT_DESCRIPTION` - 智能体的描述,在 A2A 场景下会有帮助
246+
::
247+
248+
::field{name="instruction" type="string"}
249+
默认为 `DEFAULT_INSTRUCTION` - 智能体的指令,例如函数调用的原则
250+
::
251+
252+
::field{name="sub_agents" type="list[BaseAgent]"}
253+
默认为 `[]` - 提供给该智能体的子智能体列表
254+
::
255+
256+
::field{name="tracers" type="list[BaseTracer]"}
257+
默认为 `[]` - 提供给该智能体的 tracer
258+
::
259+
::
260+
261+
::note
262+
更多兼容字段请参考 [Google ADK Agents 定义](https://github.com/google/adk-python/blob/main/src/google/adk/agents/)
263+
::
264+
265+
## 多智能体协作
266+
267+
使用 VeADK 可以构建多 Agent 协作, 主 Agent 通过 `sub_agents` 机制协调多个子 Agent 完成复杂任务。

docs/content/6.memory/3.long-term-memory.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,47 @@ VeADK 的长期记忆通常存储在数据库中,通过如下方式定义一
1212
```python
1313
from veadk.memory.long_term_memory import LongTermMemory
1414

15-
long_term_memory = LongTermMemory()
15+
# 由于长期记忆需要构建索引,因此你必须在初始化长期记忆时定义 `app_name` 以及 `user_id`
16+
long_term_memory = LongTermMemory(app_name="my_app_name", user_id="user_id")
1617
```
1718

1819
通过如下例子说明长期记忆:
1920

2021
以下示例展示了如何在 VeADK 中使用长期记忆实现跨会话的信息保留与调用。开发者可以通过 `save_session_to_long_term_memory` 方法,将某一会话中的知识性信息存入长期记忆存储后端。在新的会话中,即使上下文为空,Agent 依然能够基于长期记忆准确回忆并回答相关问题。
2122

2223
```python
24+
import asyncio
25+
2326
from veadk import Agent, Runner
2427
from veadk.memory.long_term_memory import LongTermMemory
25-
from veadk.memory.short_term_memory import ShortTermMemory
2628

27-
session_id = "..."
28-
new_session_id = "..."
29+
app_name = "ltm_demo"
30+
user_id = "temp_user"
31+
32+
teaching_session_id = "teaching_session"
33+
student_session_id = "student_session"
34+
35+
long_term_memory = LongTermMemory(backend="local", app_name=app_name, user_id=user_id)
2936

30-
long_term_memory = LongTermMemory(backend=...) # default backend is `opensearch`
31-
agent = Agent(long_term_memory=long_term_memory) # agent with long term memort backend
37+
agent = Agent(long_term_memory=long_term_memory)
3238

3339
runner = Runner(
3440
agent=agent,
35-
app_name="...",
36-
user_id="...",
37-
short_term_memory=ShortTermMemory(),
41+
app_name=app_name,
42+
user_id=user_id,
3843
)
39-
teaching_prompt = "..."
40-
await runner.run(messages=teaching_prompt, session_id=session_id)
44+
45+
teaching_prompt = "My secret is 0xabcd"
46+
asyncio.run(runner.run(messages=teaching_prompt, session_id=teaching_session_id))
4147

4248
# save the teaching prompt and answer in long term memory
43-
await runner.save_session_to_long_term_memory(session_id=session_id)
49+
asyncio.run(runner.save_session_to_long_term_memory(session_id=teaching_session_id))
4450

4551
# now, let's validate this in a new session
46-
student_prompt = "..."
47-
response = await runner.run(messages=student_prompt, session_id=new_session_id)
52+
student_prompt = "What is my secret?"
53+
response = asyncio.run(
54+
runner.run(messages=student_prompt, session_id=student_session_id)
55+
)
4856
print(response)
4957
```
5058

docs/content/90.cli/1.overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ VeADK 提供如下命令便捷您的操作:
1414
| `veadk prompt` | 优化智能体系统提示词 | 借助火山引擎 PromptPilot 产品 |
1515
| `veadk web` | 支持长短期记忆、知识库的前端调试界面 | 兼容 Google ADK web |
1616
| `veadk eval` | 支持不同后端的评测 | 评测后端包括 `adk``deepeval`,评测数据集源包括 Google ADK 评测集格式文件,以及 Tracing 文件 |
17+
| `veadk kb` | 知识库相关操作 | 向知识库添加本地文件或目录 |

docs/content/90.cli/2.commands.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,45 @@ veadk web --session_service_uri="mysql+pymysql://{user}:{password}@{host}/{datab
8484
火山引擎 Secret Key
8585
::
8686
::
87+
88+
## 知识库操作
89+
90+
您可以通过 `veadk kb add` 命令来向您的知识库添加本地文件或者目录。例如,准备如下目录:
91+
92+
::code-tree{default-value="knowledges/id.txt"}
93+
94+
```txt [knowledges/id.txt]
95+
My id is 20250101.
96+
```
97+
98+
::
99+
100+
之后,将 `knowledges/id.txt` 中的内容存入到 OpenSearch 知识库中:
101+
102+
```bash
103+
# 知识库的相关配置将会从环境变量中读取
104+
veadk kb add --backend opensearch --app_name=cmd_app --path=./knowledges
105+
```
106+
107+
可使用如下代码测试:
108+
109+
```python
110+
import asyncio
111+
112+
from veadk import Agent, Runner
113+
from veadk.knowledgebase import KnowledgeBase
114+
115+
app_name = "cmd_app"
116+
117+
knowledgebase = KnowledgeBase(backend="opensearch", app_name=app_name)
118+
119+
agent = Agent(knowledgebase=knowledgebase)
120+
121+
runner = Runner(agent=agent, app_name=app_name)
122+
123+
response = asyncio.run(
124+
runner.run(messages="Please help me to fetch my ID from my knowledgebase")
125+
)
126+
127+
print(response) # Your ID is 20250101.
128+
```

docs/nuxt.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ export default {
33
extends: ['docus'],
44
app: {
55
baseURL: '/veadk-python/'
6+
},
7+
image: {
8+
provider: 'none' // 禁用 IPX 图片优化
69
}
710
}
42.5 KB
Loading

veadk/cli/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from veadk.cli.cli_deploy import deploy
1919
from veadk.cli.cli_eval import eval
2020
from veadk.cli.cli_init import init
21+
from veadk.cli.cli_kb import kb
2122
from veadk.cli.cli_pipeline import pipeline
2223
from veadk.cli.cli_prompt import prompt
2324
from veadk.cli.cli_web import web
@@ -39,6 +40,7 @@ def veadk():
3940
veadk.add_command(web)
4041
veadk.add_command(pipeline)
4142
veadk.add_command(eval)
43+
veadk.add_command(kb)
4244

4345
if __name__ == "__main__":
4446
veadk()

0 commit comments

Comments
 (0)