Skip to content

Commit 3867b8f

Browse files
committed
refactor: remove deprecated ModelResponse, StructuredResponse, AgentResult and compat shims
1 parent 301e24c commit 3867b8f

9 files changed

Lines changed: 24 additions & 243 deletions

File tree

packages/sdk/server-ai/src/ldai/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@
3434
from ldai.providers import (
3535
AgentGraphResult,
3636
AgentGraphRunner,
37-
AgentGraphRunnerResult,
38-
AgentResult,
3937
AgentRunner,
40-
GraphMetrics,
41-
GraphMetricSummary,
42-
ManagedGraphResult,
4338
ManagedResult,
4439
Runner,
4540
RunnerResult,
@@ -53,12 +48,7 @@
5348
'Evaluator',
5449
'AgentRunner',
5550
'AgentGraphRunner',
56-
'AgentResult',
5751
'AgentGraphResult',
58-
'AgentGraphRunnerResult',
59-
'GraphMetrics',
60-
'GraphMetricSummary',
61-
'ManagedGraphResult',
6252
'ManagedResult',
6353
'Runner',
6454
'RunnerResult',

packages/sdk/server-ai/src/ldai/managed_agent_graph.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
from typing import Any
44

55
from ldai.providers import AgentGraphResult, AgentGraphRunner
6-
from ldai.providers.types import GraphMetricSummary, ManagedGraphResult
76

87

98
class ManagedAgentGraph:
109
"""
1110
LaunchDarkly managed wrapper for AI agent graph execution.
1211
13-
Holds an AgentGraphRunner. Wraps the runner result in a
14-
:class:`~ldai.providers.types.ManagedGraphResult` and builds a
15-
:class:`~ldai.providers.types.GraphMetricSummary` from the runner's metrics.
12+
Holds an AgentGraphRunner. Auto-tracking of path,
13+
tool calls, handoffs, latency, and invocation success/failure is handled
14+
by the runner implementation.
1615
1716
Obtain an instance via ``LDAIClient.create_agent_graph()``.
1817
"""
@@ -28,33 +27,17 @@ def __init__(
2827
"""
2928
self._runner = runner
3029

31-
async def run(self, input: Any) -> ManagedGraphResult:
30+
async def run(self, input: Any) -> AgentGraphResult:
3231
"""
3332
Run the agent graph with the given input.
3433
34+
Delegates to the underlying AgentGraphRunner, which handles
35+
execution and all auto-tracking internally.
36+
3537
:param input: The input prompt or structured input for the graph
36-
:return: ManagedGraphResult containing the content, metric summary, raw response,
37-
and an optional evaluations task (currently always ``None`` for graphs —
38-
per-graph evaluations will be added in a future PR).
38+
:return: AgentGraphResult containing the output, raw response, and metrics
3939
"""
40-
result: AgentGraphResult = await self._runner.run(input)
41-
42-
# Build a GraphMetricSummary from the runner result's LDAIMetrics.
43-
# path and node_metrics will be populated once graph runners are migrated
44-
# to return AgentGraphRunnerResult with GraphMetrics (PR 11).
45-
metrics = result.metrics
46-
summary = GraphMetricSummary(
47-
success=metrics.success,
48-
usage=metrics.usage,
49-
duration_ms=getattr(metrics, 'duration_ms', None),
50-
)
51-
52-
return ManagedGraphResult(
53-
content=result.output,
54-
metrics=summary,
55-
raw=result.raw,
56-
evaluations=None,
57-
)
40+
return await self._runner.run(input)
5841

5942
def get_agent_graph_runner(self) -> AgentGraphRunner:
6043
"""

packages/sdk/server-ai/src/ldai/managed_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from ldai import log
55
from ldai.models import AICompletionConfig, LDMessage
66
from ldai.providers.runner import Runner
7-
from ldai.providers.types import JudgeResult, ManagedResult
7+
from ldai.providers.types import JudgeResult, ManagedResult, RunnerResult
88
from ldai.tracker import LDAIConfigTracker
99

1010

@@ -46,7 +46,7 @@ async def run(self, prompt: str) -> ManagedResult:
4646
config_messages = self._ai_config.messages or []
4747
all_messages = config_messages + self._messages
4848

49-
result = await tracker.track_metrics_of_async(
49+
result: RunnerResult = await tracker.track_metrics_of_async(
5050
lambda r: r.metrics,
5151
lambda: self._model_runner.run(all_messages),
5252
)

packages/sdk/server-ai/src/ldai/providers/__init__.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,24 @@
66
from ldai.providers.runner_factory import RunnerFactory
77
from ldai.providers.types import (
88
AgentGraphResult,
9-
AgentGraphRunnerResult,
10-
AgentResult,
11-
GraphMetrics,
12-
GraphMetricSummary,
139
JudgeResult,
1410
LDAIMetrics,
15-
ManagedGraphResult,
1611
ManagedResult,
17-
ModelResponse,
1812
RunnerResult,
19-
StructuredResponse,
2013
ToolRegistry,
2114
)
2215

2316
__all__ = [
2417
'AIProvider',
2518
'AgentGraphResult',
2619
'AgentGraphRunner',
27-
'AgentGraphRunnerResult',
28-
'AgentResult',
2920
'AgentRunner',
30-
'GraphMetrics',
31-
'GraphMetricSummary',
3221
'JudgeResult',
3322
'LDAIMetrics',
34-
'ManagedGraphResult',
3523
'ManagedResult',
36-
'ModelResponse',
3724
'ModelRunner',
3825
'Runner',
3926
'RunnerFactory',
4027
'RunnerResult',
41-
'StructuredResponse',
4228
'ToolRegistry',
4329
]

packages/sdk/server-ai/src/ldai/providers/agent_runner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Protocol, runtime_checkable
22

3-
from ldai.providers.types import AgentResult
3+
from ldai.providers.types import RunnerResult
44

55

66
@runtime_checkable
@@ -18,11 +18,11 @@ class AgentRunner(Protocol):
1818
the caller just passes input.
1919
"""
2020

21-
async def run(self, input: Any) -> AgentResult:
21+
async def run(self, input: Any) -> RunnerResult:
2222
"""
2323
Run the agent with the given input.
2424
2525
:param input: The input to the agent (string prompt or structured input)
26-
:return: AgentResult containing the output, raw response, and metrics
26+
:return: RunnerResult containing the agent's content, metrics, and optional raw/parsed fields
2727
"""
2828
...

packages/sdk/server-ai/src/ldai/providers/ai_provider.py

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from abc import ABC
2-
from typing import Any, Dict, List, Optional
2+
from typing import Any, Optional
33

44
from ldai import log
5-
from ldai.models import LDMessage
6-
from ldai.providers.types import ModelResponse, StructuredResponse, ToolRegistry
5+
from ldai.providers.types import ToolRegistry
76

87

98
class AIProvider(ABC):
@@ -16,51 +15,6 @@ class AIProvider(ABC):
1615
create_model(), create_agent(), and create_agent_graph().
1716
"""
1817

19-
async def invoke_model(self, messages: List[LDMessage]) -> ModelResponse:
20-
"""
21-
Invoke the chat model with an array of messages.
22-
23-
Default implementation takes no action and returns a placeholder response.
24-
Provider implementations should override this method.
25-
26-
:param messages: Array of LDMessage objects representing the conversation
27-
:return: ModelResponse containing the model's response
28-
"""
29-
log.warning('invoke_model not implemented by this provider')
30-
31-
from ldai.models import LDMessage
32-
from ldai.providers.types import LDAIMetrics
33-
34-
return ModelResponse(
35-
message=LDMessage(role='assistant', content=''),
36-
metrics=LDAIMetrics(success=False, usage=None),
37-
)
38-
39-
async def invoke_structured_model(
40-
self,
41-
messages: List[LDMessage],
42-
response_structure: Dict[str, Any],
43-
) -> StructuredResponse:
44-
"""
45-
Invoke the chat model with structured output support.
46-
47-
Default implementation takes no action and returns a placeholder response.
48-
Provider implementations should override this method.
49-
50-
:param messages: Array of LDMessage objects representing the conversation
51-
:param response_structure: Dictionary of output configurations keyed by output name
52-
:return: StructuredResponse containing the structured data
53-
"""
54-
log.warning('invoke_structured_model not implemented by this provider')
55-
56-
from ldai.providers.types import LDAIMetrics
57-
58-
return StructuredResponse(
59-
data={},
60-
raw_response='',
61-
metrics=LDAIMetrics(success=False, usage=None),
62-
)
63-
6418
def create_model(self, config: Any) -> Optional[Any]:
6519
"""
6620
Create a configured model executor for the given AI config.
Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from typing import Any, Dict, List, Protocol, runtime_checkable
1+
from typing import List, Protocol, runtime_checkable
22

33
from ldai.models import LDMessage
4-
from ldai.providers.types import ModelResponse, StructuredResponse
4+
from ldai.providers.types import RunnerResult
55

66

77
@runtime_checkable
@@ -14,25 +14,11 @@ class ModelRunner(Protocol):
1414
and with what parameters — the caller just passes messages.
1515
"""
1616

17-
async def invoke_model(self, messages: List[LDMessage]) -> ModelResponse:
17+
async def invoke_model(self, messages: List[LDMessage]) -> RunnerResult:
1818
"""
1919
Invoke the model with an array of messages.
2020
2121
:param messages: Array of LDMessage objects representing the conversation
22-
:return: ModelResponse containing the model's response and metrics
23-
"""
24-
...
25-
26-
async def invoke_structured_model(
27-
self,
28-
messages: List[LDMessage],
29-
response_structure: Dict[str, Any],
30-
) -> StructuredResponse:
31-
"""
32-
Invoke the model with structured output support.
33-
34-
:param messages: Array of LDMessage objects representing the conversation
35-
:param response_structure: Dictionary defining the JSON schema for output structure
36-
:return: StructuredResponse containing the structured data
22+
:return: RunnerResult containing the model's response and metrics
3723
"""
3824
...

0 commit comments

Comments
 (0)