|
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 |
@@ -87,6 +87,81 @@ class ManagedResult: |
87 | 87 | evaluations: Optional[asyncio.Task[List[JudgeResult]]] = None |
88 | 88 |
|
89 | 89 |
|
| 90 | +@dataclass |
| 91 | +class GraphMetrics: |
| 92 | + """ |
| 93 | + Metrics from a single agent graph run. |
| 94 | +
|
| 95 | + Returned by graph runner implementations (e.g. ``OpenAIAgentGraphRunner``, |
| 96 | + ``LangGraphAgentGraphRunner``) and consumed by :class:`ManagedAgentGraph` to |
| 97 | + build a :class:`GraphMetricSummary`. |
| 98 | +
|
| 99 | + ``path`` is the ordered list of node keys visited during the run. |
| 100 | + ``node_metrics`` maps node keys to the :class:`LDAIMetrics` recorded for each |
| 101 | + node. Both fields default to empty so that runners that do not yet populate |
| 102 | + them remain compatible. |
| 103 | + """ |
| 104 | + success: bool |
| 105 | + path: List[str] = field(default_factory=list) |
| 106 | + duration_ms: Optional[int] = None |
| 107 | + usage: Optional[TokenUsage] = None |
| 108 | + node_metrics: Dict[str, LDAIMetrics] = field(default_factory=dict) |
| 109 | + |
| 110 | + |
| 111 | +@dataclass |
| 112 | +class GraphMetricSummary: |
| 113 | + """ |
| 114 | + Summary of metrics for an agent graph run, as returned by |
| 115 | + :attr:`ManagedGraphResult.metrics`. |
| 116 | +
|
| 117 | + Mirrors :class:`LDAIMetricSummary` for single-model invocations but adds |
| 118 | + graph-specific fields (``path``, ``node_metrics``). |
| 119 | +
|
| 120 | + ``resumption_token`` is set from the graph tracker at instantiation so it is |
| 121 | + always available on the returned result. |
| 122 | + """ |
| 123 | + success: bool |
| 124 | + path: List[str] = field(default_factory=list) |
| 125 | + duration_ms: Optional[int] = None |
| 126 | + usage: Optional[TokenUsage] = None |
| 127 | + node_metrics: Dict[str, LDAIMetrics] = field(default_factory=dict) |
| 128 | + resumption_token: Optional[str] = None |
| 129 | + |
| 130 | + |
| 131 | +@dataclass |
| 132 | +class ManagedGraphResult: |
| 133 | + """ |
| 134 | + Result returned by :class:`~ldai.ManagedAgentGraph` after a single graph run. |
| 135 | +
|
| 136 | + ``metrics`` is a :class:`GraphMetricSummary` built from the runner result and |
| 137 | + the graph tracker. |
| 138 | + ``evaluations`` is an optional asyncio Task that resolves to a list of |
| 139 | + :class:`JudgeResult` instances when awaited. |
| 140 | + """ |
| 141 | + content: str |
| 142 | + metrics: GraphMetricSummary |
| 143 | + raw: Optional[Any] = None |
| 144 | + evaluations: Optional[asyncio.Task[List[JudgeResult]]] = None |
| 145 | + |
| 146 | + |
| 147 | +@dataclass |
| 148 | +class AgentGraphRunnerResult: |
| 149 | + """ |
| 150 | + Result returned by an agent graph runner (e.g. ``OpenAIAgentGraphRunner``). |
| 151 | +
|
| 152 | + This is the new runner-layer return type for graph runners. ``evaluations`` |
| 153 | + is intentionally absent — evaluations are dispatched by the managed layer |
| 154 | + and live on :class:`ManagedGraphResult`. |
| 155 | +
|
| 156 | + .. note:: |
| 157 | + Graph runners have not yet been migrated to return this type (that is |
| 158 | + PR 11). Until then, :class:`AgentGraphResult` is still in use. |
| 159 | + """ |
| 160 | + content: str |
| 161 | + metrics: GraphMetrics |
| 162 | + raw: Optional[Any] = None |
| 163 | + |
| 164 | + |
90 | 165 | @dataclass |
91 | 166 | class ModelResponse: |
92 | 167 | """ |
@@ -166,6 +241,12 @@ class AgentResult: |
166 | 241 | class AgentGraphResult: |
167 | 242 | """ |
168 | 243 | Result from an agent graph run. |
| 244 | +
|
| 245 | + .. deprecated:: |
| 246 | + Use :class:`AgentGraphRunnerResult` (runner layer) and |
| 247 | + :class:`ManagedGraphResult` (managed layer) instead. This type is |
| 248 | + retained for backward compatibility with existing graph runners until |
| 249 | + PR 11 migrates them to return :class:`AgentGraphRunnerResult`. |
169 | 250 | """ |
170 | 251 | output: str |
171 | 252 | raw: Any |
|
0 commit comments