|
|
hace 1 mes | |
|---|---|---|
| .. | ||
| README.md | hace 1 mes | |
| __init__.py | hace 1 mes | |
| api.py | hace 1 mes | |
| models.py | hace 1 mes | |
| protocols.py | hace 1 mes | |
| store.py | hace 1 mes | |
| tree_dump.py | hace 1 mes | |
| websocket.py | hace 1 mes | |
执行追踪系统负责记录和可视化 Agent 的执行过程:
数据模型 (models.py)
Trace - 一次完整的执行轨迹Step - 执行过程中的一个原子操作(形成树结构)StepType - 步骤类型(思考、动作、结果等)Status - 步骤状态(计划中、执行中、完成、失败)存储接口 (protocols.py, store.py)
TraceStore - Trace 存储接口协议MemoryTraceStore - 内存实现(用于测试)可视化工具 (tree_dump.py)
dump_tree() - 输出文本格式的 step treedump_markdown() - 输出 markdown 格式(可折叠)dump_json() - 输出 JSON 格式API 和实时推送 (api.py, websocket.py)
from agent.execution import MemoryTraceStore, Trace, Step, dump_tree
# 创建存储
store = MemoryTraceStore()
# 创建 Trace
trace = Trace.create(mode="agent", task="Complete task")
trace_id = await store.create_trace(trace)
# 添加 Step
step = Step.create(
trace_id=trace_id,
step_type="thought",
description="Analyzing task"
)
await store.add_step(step)
# 可视化
trace = await store.get_trace(trace_id)
steps = await store.get_trace_steps(trace_id)
dump_tree(trace, steps)
models.py - Trace 和 Step 数据模型protocols.py - TraceStore 接口定义store.py - MemoryTraceStore 实现tree_dump.py - Step tree 可视化工具api.py - RESTful API(可选,需要 FastAPI)websocket.py - WebSocket 推送(可选,需要 FastAPI)__init__.py - 模块导出tree_dump.py 可视化优化api.py 和 websocket.py 开发