__init__.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. """
  2. Execution - 执行追踪系统
  3. 核心职责:
  4. 1. Trace/Step 模型定义
  5. 2. 存储接口和实现(文件系统)
  6. 3. Step 树可视化(文本/markdown/JSON)
  7. 4. RESTful API(可视化查询,支持 compact/full 视图)
  8. 5. WebSocket 推送(实时更新,支持断线续传)
  9. """
  10. # 模型(核心,无依赖)
  11. from agent.execution.models import Trace, Step, StepType, StepStatus
  12. # 存储接口(核心,无依赖)
  13. from agent.execution.protocols import TraceStore
  14. # 文件系统存储实现(跨进程 + 持久化)
  15. from agent.execution.fs_store import FileSystemTraceStore
  16. # Debug 工具(可视化)
  17. from agent.execution.tree_dump import StepTreeDumper, dump_tree, dump_markdown, dump_json
  18. # API 路由(可选,需要 FastAPI)
  19. def _get_api_router():
  20. """延迟导入 API Router(避免强制依赖 FastAPI)"""
  21. from agent.execution.api import router
  22. return router
  23. def _get_ws_router():
  24. """延迟导入 WebSocket Router(避免强制依赖 FastAPI)"""
  25. from agent.execution.websocket import router
  26. return router
  27. # WebSocket 广播函数(可选,需要 FastAPI)
  28. def _get_broadcast_functions():
  29. """延迟导入 WebSocket 广播函数"""
  30. from agent.execution.websocket import (
  31. broadcast_step_added,
  32. broadcast_step_updated,
  33. broadcast_trace_completed,
  34. )
  35. return broadcast_step_added, broadcast_step_updated, broadcast_trace_completed
  36. # 便捷属性(仅在访问时导入)
  37. @property
  38. def api_router():
  39. return _get_api_router()
  40. @property
  41. def ws_router():
  42. return _get_ws_router()
  43. __all__ = [
  44. # 模型
  45. "Trace",
  46. "Step",
  47. "StepType",
  48. "StepStatus",
  49. # 存储
  50. "TraceStore",
  51. "FileSystemTraceStore",
  52. # Debug/可视化
  53. "StepTreeDumper",
  54. "dump_tree",
  55. "dump_markdown",
  56. "dump_json",
  57. ]