File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff 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
1014from veadk.tracing.telemetry.opentelemetry_tracer import OpentelemetryTracer
1115
1216tracer = OpentelemetryTracer()
1317agent = 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+
1829print (f " Tracing file path: { tracer._trace_file_path} " )
1930```
2031
Original file line number Diff line number Diff 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 :
You can’t perform that action at this time.
0 commit comments