| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- """
- Trace Storage Protocol - Trace 存储接口定义
- 使用 Protocol 定义接口,允许不同的存储实现(内存、PostgreSQL、Neo4j 等)
- """
- from typing import Protocol, List, Optional, runtime_checkable
- from agent.execution.models import Trace, Step
- @runtime_checkable
- class TraceStore(Protocol):
- """Trace + Step 存储接口"""
- # ===== Trace 操作 =====
- async def create_trace(self, trace: Trace) -> str:
- """
- 创建新的 Trace
- Args:
- trace: Trace 对象
- Returns:
- trace_id
- """
- ...
- async def get_trace(self, trace_id: str) -> Optional[Trace]:
- """获取 Trace"""
- ...
- async def update_trace(self, trace_id: str, **updates) -> None:
- """
- 更新 Trace
- Args:
- trace_id: Trace ID
- **updates: 要更新的字段
- """
- ...
- async def list_traces(
- self,
- mode: Optional[str] = None,
- agent_type: Optional[str] = None,
- uid: Optional[str] = None,
- status: Optional[str] = None,
- limit: int = 50
- ) -> List[Trace]:
- """列出 Traces"""
- ...
- # ===== Step 操作 =====
- async def add_step(self, step: Step) -> str:
- """
- 添加 Step
- Args:
- step: Step 对象
- Returns:
- step_id
- """
- ...
- async def get_step(self, step_id: str) -> Optional[Step]:
- """获取 Step"""
- ...
- async def get_trace_steps(self, trace_id: str) -> List[Step]:
- """获取 Trace 的所有 Steps(按 sequence 排序)"""
- ...
- async def get_step_children(self, step_id: str) -> List[Step]:
- """获取 Step 的子节点"""
- ...
|