events.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. Agent 事件定义
  3. """
  4. from dataclasses import dataclass
  5. from typing import Dict, Any, Literal
  6. AgentEventType = Literal[
  7. # Trace 生命周期
  8. "trace_started", # Trace 开始
  9. "trace_completed", # Trace 完成
  10. "trace_failed", # Trace 失败
  11. # 记忆
  12. "memory_loaded", # 记忆加载完成(skills, experiences)
  13. "experience_extracted", # 提取了经验
  14. # 步骤
  15. "step_started", # 步骤开始
  16. "llm_delta", # LLM 输出增量
  17. "llm_call_completed", # LLM 调用完成
  18. "tool_executing", # 工具执行中
  19. "tool_result", # 工具结果
  20. "conclusion", # 结论(中间或最终)
  21. # 反馈
  22. "feedback_received", # 收到人工反馈
  23. # 等待用户
  24. "awaiting_user_action", # 等待用户确认(工具调用)
  25. ]
  26. @dataclass
  27. class AgentEvent:
  28. """Agent 事件"""
  29. type: AgentEventType
  30. data: Dict[str, Any]
  31. def to_dict(self) -> Dict[str, Any]:
  32. return {"type": self.type, "data": self.data}
  33. def __repr__(self) -> str:
  34. return f"AgentEvent(type={self.type!r}, data={self.data!r})"