models.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from __future__ import annotations
  2. from typing import Any, Literal, TypedDict
  3. ChatRole = Literal["user", "assistant"]
  4. TracePhase = Literal["system", "plan", "tool", "summary", "chat", "error"]
  5. class ChatMessage(TypedDict):
  6. role: ChatRole
  7. content: str
  8. class McpToolDescriptor(TypedDict, total=False):
  9. name: str
  10. title: str
  11. description: str
  12. inputSchema: Any
  13. class McpToolResult(TypedDict, total=False):
  14. content: list[dict[str, Any]]
  15. structuredContent: Any
  16. class PlannedToolCall(TypedDict):
  17. name: str
  18. arguments: dict[str, Any]
  19. class ToolObservation(TypedDict, total=False):
  20. name: str
  21. source: Literal["mcp"]
  22. arguments: dict[str, Any]
  23. ok: bool
  24. result: Any
  25. error: str
  26. durationMs: int
  27. class AgentTraceEvent(TypedDict, total=False):
  28. at: str
  29. phase: TracePhase
  30. title: str
  31. detail: str
  32. data: Any
  33. class AgentResultTable(TypedDict):
  34. title: str
  35. columns: list[str]
  36. rows: list[dict[str, str]]
  37. class AgentRunResponse(TypedDict):
  38. content: str
  39. model: str
  40. usedMcp: bool
  41. steps: int
  42. toolCalls: list[ToolObservation]
  43. tables: list[AgentResultTable]
  44. trace: list[AgentTraceEvent]
  45. class AgentState(TypedDict, total=False):
  46. message: str
  47. history: list[ChatMessage]
  48. tools: list[McpToolDescriptor]
  49. plannedToolCalls: list[PlannedToolCall]
  50. observations: list[ToolObservation]
  51. visitedSignatures: list[str]
  52. trace: list[AgentTraceEvent]
  53. steps: int
  54. final: AgentRunResponse