-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmanaged_agent_graph.py
More file actions
65 lines (51 loc) · 2.16 KB
/
managed_agent_graph.py
File metadata and controls
65 lines (51 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""ManagedAgentGraph — LaunchDarkly managed wrapper for agent graph execution."""
from typing import Any
from ldai.providers import AgentGraphResult, AgentGraphRunner
from ldai.providers.types import GraphMetricSummary, ManagedGraphResult
class ManagedAgentGraph:
"""
LaunchDarkly managed wrapper for AI agent graph execution.
Holds an AgentGraphRunner. Wraps the runner result in a
:class:`~ldai.providers.types.ManagedGraphResult` and builds a
:class:`~ldai.providers.types.GraphMetricSummary` from the runner's metrics.
Obtain an instance via ``LDAIClient.create_agent_graph()``.
"""
def __init__(
self,
runner: AgentGraphRunner,
):
"""
Initialize ManagedAgentGraph.
:param runner: The AgentGraphRunner to delegate execution to
"""
self._runner = runner
async def run(self, input: Any) -> ManagedGraphResult:
"""
Run the agent graph with the given input.
:param input: The input prompt or structured input for the graph
:return: ManagedGraphResult containing the content, metric summary, raw response,
and an optional evaluations task (currently always ``None`` for graphs —
per-graph evaluations will be added in a future PR).
"""
result: AgentGraphResult = await self._runner.run(input)
# Build a GraphMetricSummary from the runner result's LDAIMetrics.
# path and node_metrics will be populated once graph runners are migrated
# to return AgentGraphRunnerResult with GraphMetrics (PR 11).
metrics = result.metrics
summary = GraphMetricSummary(
success=metrics.success,
usage=metrics.usage,
duration_ms=getattr(metrics, 'duration_ms', None),
)
return ManagedGraphResult(
content=result.output,
metrics=summary,
raw=result.raw,
evaluations=None,
)
def get_agent_graph_runner(self) -> AgentGraphRunner:
"""
Return the underlying AgentGraphRunner for advanced use.
:return: The AgentGraphRunner instance
"""
return self._runner