|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import asyncio |
6 | | -from dataclasses import dataclass |
| 6 | +from dataclasses import dataclass, field |
7 | 7 | from typing import Any, Callable, Dict, List, Optional |
8 | 8 |
|
9 | 9 | from ldai.models import LDMessage |
@@ -114,6 +114,80 @@ class StructuredResponse: |
114 | 114 | metrics: LDAIMetrics |
115 | 115 |
|
116 | 116 |
|
| 117 | +@dataclass |
| 118 | +class GraphMetrics: |
| 119 | + """Contains raw metrics from a single agent graph run.""" |
| 120 | + |
| 121 | + success: bool |
| 122 | + """Whether the graph run succeeded.""" |
| 123 | + |
| 124 | + path: List[str] = field(default_factory=list) |
| 125 | + """Ordered list of node keys visited during the run.""" |
| 126 | + |
| 127 | + duration_ms: Optional[int] = None |
| 128 | + """Wall-clock duration of the graph run in milliseconds.""" |
| 129 | + |
| 130 | + usage: Optional[TokenUsage] = None |
| 131 | + """Optional aggregate token usage information across all nodes in the graph run.""" |
| 132 | + |
| 133 | + node_metrics: Dict[str, LDAIMetrics] = field(default_factory=dict) |
| 134 | + """Per-node metrics keyed by node key.""" |
| 135 | + |
| 136 | + |
| 137 | +@dataclass |
| 138 | +class GraphMetricSummary: |
| 139 | + """Contains a summary of metrics for an agent graph run.""" |
| 140 | + |
| 141 | + success: bool |
| 142 | + """Whether the graph run succeeded.""" |
| 143 | + |
| 144 | + path: List[str] = field(default_factory=list) |
| 145 | + """Ordered list of node keys visited during the run.""" |
| 146 | + |
| 147 | + duration_ms: Optional[int] = None |
| 148 | + """Wall-clock duration of the graph run in milliseconds.""" |
| 149 | + |
| 150 | + usage: Optional[TokenUsage] = None |
| 151 | + """Optional aggregate token usage information across all nodes in the graph run.""" |
| 152 | + |
| 153 | + node_metrics: Dict[str, LDAIMetrics] = field(default_factory=dict) |
| 154 | + """Per-node metrics keyed by node key.""" |
| 155 | + |
| 156 | + resumption_token: Optional[str] = None |
| 157 | + """Optional resumption token from the graph tracker for cross-process resumption.""" |
| 158 | + |
| 159 | + |
| 160 | +@dataclass |
| 161 | +class ManagedGraphResult: |
| 162 | + """Contains the result of a managed agent graph run, including metrics and optional judge evaluations.""" |
| 163 | + |
| 164 | + content: str |
| 165 | + """The graph's final output content.""" |
| 166 | + |
| 167 | + metrics: GraphMetricSummary |
| 168 | + """Aggregated metric summary from the graph tracker for this run.""" |
| 169 | + |
| 170 | + raw: Optional[Any] = None |
| 171 | + """Optional provider-native response object for advanced consumers.""" |
| 172 | + |
| 173 | + evaluations: Optional[asyncio.Task[List[JudgeResult]]] = None |
| 174 | + """Optional asyncio Task that resolves to the list of :class:`JudgeResult` instances when awaited.""" |
| 175 | + |
| 176 | + |
| 177 | +@dataclass |
| 178 | +class AgentGraphRunnerResult: |
| 179 | + """Contains the result of an agent graph runner invocation.""" |
| 180 | + |
| 181 | + content: str |
| 182 | + """The graph's final output content.""" |
| 183 | + |
| 184 | + metrics: GraphMetrics |
| 185 | + """Metrics from the graph run.""" |
| 186 | + |
| 187 | + raw: Optional[Any] = None |
| 188 | + """Optional provider-native response object for advanced consumers.""" |
| 189 | + |
| 190 | + |
117 | 191 | @dataclass |
118 | 192 | class JudgeResult: |
119 | 193 | """Contains the result of a single judge evaluation.""" |
|
0 commit comments