Skip to content

Commit 2ffd34e

Browse files
chore(runner): add runner options for save tracing (#79)
* add runner options for save tracing * fix tutorial * fix typos in agent doc
1 parent 1294b0f commit 2ffd34e

File tree

4 files changed

+136
-112
lines changed

4 files changed

+136
-112
lines changed

docs/docs/agent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ from veadk.tools.demo_tools import get_city_weather
9393
session_id = "..."
9494
prompt = "..."
9595

96-
# define three agents, one for planner, two for write poem and polish
96+
# 定义三个智能体,分别为天气预报智能体、穿衣建议智能体以及一个Planner智能体
9797
weather_reporter = Agent(
9898
name="weather_reporter",
9999
description="A weather reporter agent to report the weather.",

docs/docs/tracing.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@ VeADK 提供可观测(Tracing)的能力,用于记录 Agent 执行过程中
44

55
## 本地观测
66

7-
通过如下方式开启本地观测,并且将运行时数据保存至本地
7+
通过如下方式开启本地观测,并且在 `runner` 的运行函数中指定 `save_tracing_data=True` 来将运行时数据保存至本地
88

99
```python
10+
import asyncio
11+
12+
from veadk import Agent, Runner
13+
from veadk.memory.short_term_memory import ShortTermMemory
1014
from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer
1115

1216
tracer = OpentelemetryTracer()
1317
agent = Agent(tracers=[tracer])
1418

15-
# ... run agent ...
1619

17-
# the data will be automatically saved to local
20+
session_id = "session_id"
21+
22+
runner = Runner(agent=agent, short_term_memory=ShortTermMemory())
23+
24+
prompt = "How is the weather like in Beijing? Besides, tell me which tool you invoked."
25+
26+
# 设置 `save_tracing_data` 来保存运行时的 Tracing 数据
27+
asyncio.run(runner.run(messages=prompt, session_id=session_id, save_tracing_data=True))
28+
1829
print(f"Tracing file path: {tracer._trace_file_path}")
1930
```
2031

veadk/runner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ async def run(
145145
messages: RunnerMessage,
146146
session_id: str,
147147
stream: bool = False,
148+
save_tracing_data: bool = False,
148149
):
149150
converted_messages: list = self._convert_messages(messages)
150151

@@ -159,7 +160,8 @@ async def run(
159160
final_output = await self._run(session_id, converted_message, stream)
160161

161162
# try to save tracing file
162-
self.save_tracing_file(session_id)
163+
if save_tracing_data:
164+
self.save_tracing_file(session_id)
163165

164166
return final_output
165167

@@ -173,6 +175,7 @@ def save_tracing_file(self, session_id: str) -> str:
173175
return ""
174176

175177
if not self.agent.tracers:
178+
logger.warning("No tracer is configured in the agent.")
176179
return ""
177180

178181
try:

0 commit comments

Comments
 (0)