|
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.tracker import LDAIMetricSummary, TokenUsage |
@@ -86,6 +86,80 @@ class ManagedResult: |
86 | 86 | """Optional asyncio Task that resolves to the list of :class:`JudgeResult` instances when awaited.""" |
87 | 87 |
|
88 | 88 |
|
| 89 | +@dataclass |
| 90 | +class GraphMetrics: |
| 91 | + """Contains raw metrics from a single agent graph run.""" |
| 92 | + |
| 93 | + success: bool |
| 94 | + """Whether the graph run succeeded.""" |
| 95 | + |
| 96 | + path: List[str] = field(default_factory=list) |
| 97 | + """Ordered list of node keys visited during the run.""" |
| 98 | + |
| 99 | + duration_ms: Optional[int] = None |
| 100 | + """Wall-clock duration of the graph run in milliseconds.""" |
| 101 | + |
| 102 | + usage: Optional[TokenUsage] = None |
| 103 | + """Optional aggregate token usage information across all nodes in the graph run.""" |
| 104 | + |
| 105 | + node_metrics: Dict[str, LDAIMetrics] = field(default_factory=dict) |
| 106 | + """Per-node metrics keyed by node key.""" |
| 107 | + |
| 108 | + |
| 109 | +@dataclass |
| 110 | +class GraphMetricSummary: |
| 111 | + """Contains a summary of metrics for an agent graph run.""" |
| 112 | + |
| 113 | + success: bool |
| 114 | + """Whether the graph run succeeded.""" |
| 115 | + |
| 116 | + path: List[str] = field(default_factory=list) |
| 117 | + """Ordered list of node keys visited during the run.""" |
| 118 | + |
| 119 | + duration_ms: Optional[int] = None |
| 120 | + """Wall-clock duration of the graph run in milliseconds.""" |
| 121 | + |
| 122 | + usage: Optional[TokenUsage] = None |
| 123 | + """Optional aggregate token usage information across all nodes in the graph run.""" |
| 124 | + |
| 125 | + node_metrics: Dict[str, LDAIMetrics] = field(default_factory=dict) |
| 126 | + """Per-node metrics keyed by node key.""" |
| 127 | + |
| 128 | + resumption_token: Optional[str] = None |
| 129 | + """Optional resumption token from the graph tracker for cross-process resumption.""" |
| 130 | + |
| 131 | + |
| 132 | +@dataclass |
| 133 | +class ManagedGraphResult: |
| 134 | + """Contains the result of a managed agent graph run, including metrics and optional judge evaluations.""" |
| 135 | + |
| 136 | + content: str |
| 137 | + """The graph's final output content.""" |
| 138 | + |
| 139 | + metrics: GraphMetricSummary |
| 140 | + """Aggregated metric summary from the graph tracker for this run.""" |
| 141 | + |
| 142 | + raw: Optional[Any] = None |
| 143 | + """Optional provider-native response object for advanced consumers.""" |
| 144 | + |
| 145 | + evaluations: Optional[asyncio.Task[List[JudgeResult]]] = None |
| 146 | + """Optional asyncio Task that resolves to the list of :class:`JudgeResult` instances when awaited.""" |
| 147 | + |
| 148 | + |
| 149 | +@dataclass |
| 150 | +class AgentGraphRunnerResult: |
| 151 | + """Contains the result of an agent graph runner invocation.""" |
| 152 | + |
| 153 | + content: str |
| 154 | + """The graph's final output content.""" |
| 155 | + |
| 156 | + metrics: GraphMetrics |
| 157 | + """Metrics from the graph run.""" |
| 158 | + |
| 159 | + raw: Optional[Any] = None |
| 160 | + """Optional provider-native response object for advanced consumers.""" |
| 161 | + |
| 162 | + |
89 | 163 | @dataclass |
90 | 164 | class JudgeResult: |
91 | 165 | """Contains the result of a single judge evaluation.""" |
|
0 commit comments