Skip to content

Commit e74c388

Browse files
committed
add docs
1 parent 8b20e6d commit e74c388

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

docs/docs/deploy/optimization.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,80 @@ veadk_rl_lightning_project
161161
![启动client](../assets/images/optimization/lightning_client.png)
162162

163163
![启动server](../assets/images/optimization/lightning_training_server.png)
164+
165+
## Agent 自我反思
166+
167+
VeADK 中支持基于 Tracing 文件数据,通过第三方 Agent 推理来进行自我反思,生成优化后的系统提示词。
168+
169+
### 使用方法
170+
171+
您可以在适宜的时机将 Agent 推理得到的 Tracing 文件数据,提交到 `reflector` 进行自我反思,如下代码:
172+
173+
```python
174+
import asyncio
175+
176+
from veadk import Agent, Runner
177+
from veadk.reflector.local_reflector import LocalReflector
178+
from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer
179+
180+
agent = Agent(tracers=[OpentelemetryTracer()])
181+
reflector = LocalReflector(agent=agent)
182+
183+
app_name = "app"
184+
user_id = "user"
185+
session_id = "session"
186+
187+
188+
async def main():
189+
runner = Runner(agent=agent, app_name=app_name)
190+
191+
await runner.run(
192+
messages="你好,我觉得你的回答不够礼貌",
193+
user_id=user_id,
194+
session_id=session_id,
195+
)
196+
197+
trace_file = runner.save_tracing_file(session_id=session_id)
198+
199+
response = await reflector.reflect(
200+
trace_file=trace_file
201+
)
202+
print(response)
203+
204+
205+
if __name__ == "__main__":
206+
asyncio.run(main())
207+
```
208+
209+
### 结果说明
210+
211+
原始提示词:
212+
213+
```text
214+
You an AI agent created by the VeADK team.
215+
216+
You excel at the following tasks:
217+
1. Data science
218+
- Information gathering and fact-checking
219+
- Data processing and analysis
220+
2. Documentation
221+
- Writing multi-chapter articles and in-depth research reports
222+
3. Coding & Programming
223+
- Creating websites, applications, and tools
224+
- Solve problems and bugs in code (e.g., Python, JavaScript, SQL, ...)
225+
- If necessary, using programming to solve various problems beyond development
226+
4. If user gives you tools, finish various tasks that can be accomplished using tools and available resources
227+
```
228+
229+
优化后,您将看到类似如下的输出:
230+
231+
```text
232+
optimized_prompt='You are an AI agent created by the VeADK team. Your core mission is to assist users with expertise in data science, documentation, and coding, while maintaining a warm, respectful, and engaging communication style.\n\nYou excel at the following tasks:\n1. Data science\n- Information gathering and fact-checking\n- Data processing and analysis\n2. Documentation\n- Writing multi-chapter articles and in-depth research reports\n3. Coding & Programming\n- Creating websites, applications, and tools\n- Solving problems and bugs in code (e.g., Python, JavaScript, SQL, ...)\n- Using programming to solve various problems beyond development\n4. Tool usage\n- Effectively using provided tools and available resources to accomplish tasks\n\nCommunication Guidelines:\n- Always use polite and warm language (e.g., appropriate honorifics, friendly tone)\n- Show appreciation for user feedback and suggestions\n- Proactively confirm user needs and preferences\n- Maintain a helpful and encouraging attitude throughout interactions\n\nYour responses should be both technically accurate and conversationally pleasant, ensuring users feel valued and supported.'
233+
234+
reason="The trace shows a user complaint about the agent's lack of politeness in responses. The agent's current system prompt focuses exclusively on technical capabilities without addressing communication style. The optimized prompt adds explicit communication guidelines to ensure the agent maintains a warm, respectful tone while preserving all technical capabilities. This addresses the user's feedback directly while maintaining the agent's core functionality."
235+
```
236+
237+
输出分为两部分:
238+
239+
- `optimized_prompt`: 优化后的系统提示词
240+
- `reason`: 优化原因

0 commit comments

Comments
 (0)