Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ from veadk.tools.demo_tools import get_city_weather
session_id = "..."
prompt = "..."

# define three agents, one for planner, two for write poem and polish
# 定义三个智能体,分别为天气预报智能体、穿衣建议智能体以及一个Planner智能体
weather_reporter = Agent(
name="weather_reporter",
description="A weather reporter agent to report the weather.",
Expand Down
17 changes: 14 additions & 3 deletions docs/docs/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ VeADK 提供可观测(Tracing)的能力,用于记录 Agent 执行过程中

## 本地观测

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

```python
import asyncio

from veadk import Agent, Runner
from veadk.memory.short_term_memory import ShortTermMemory
from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer

tracer = OpentelemetryTracer()
agent = Agent(tracers=[tracer])

# ... run agent ...

# the data will be automatically saved to local
session_id = "session_id"

runner = Runner(agent=agent, short_term_memory=ShortTermMemory())

prompt = "How is the weather like in Beijing? Besides, tell me which tool you invoked."

# 设置 `save_tracing_data` 来保存运行时的 Tracing 数据
asyncio.run(runner.run(messages=prompt, session_id=session_id, save_tracing_data=True))

print(f"Tracing file path: {tracer._trace_file_path}")
```

Expand Down
5 changes: 4 additions & 1 deletion veadk/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ async def run(
messages: RunnerMessage,
session_id: str,
stream: bool = False,
save_tracing_data: bool = False,
):
converted_messages: list = self._convert_messages(messages)

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

# try to save tracing file
self.save_tracing_file(session_id)
if save_tracing_data:
self.save_tracing_file(session_id)

return final_output

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

if not self.agent.tracers:
logger.warning("No tracer is configured in the agent.")
return ""

try:
Expand Down
Loading