Skip to content

Commit fbb0b4b

Browse files
authored
fix!: ModelResponse was replaced by RunnerResult (#157)
fix!: StructuredResponse replaced by RunnerResult with new "parsed" property fix!: AgentResult replaced by RunnerResult and Managed Result fix!: Removed ModelRunner and AgentRunner protocols fix!: Removed invoke_method, invoke_structured_model from AIProvider base class.
1 parent 301e24c commit fbb0b4b

8 files changed

Lines changed: 5 additions & 203 deletions

File tree

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
AgentGraphResult,
3636
AgentGraphRunner,
3737
AgentGraphRunnerResult,
38-
AgentResult,
39-
AgentRunner,
4038
GraphMetrics,
4139
GraphMetricSummary,
4240
ManagedGraphResult,
@@ -51,9 +49,7 @@
5149
__all__ = [
5250
'LDAIClient',
5351
'Evaluator',
54-
'AgentRunner',
5552
'AgentGraphRunner',
56-
'AgentResult',
5753
'AgentGraphResult',
5854
'AgentGraphRunnerResult',
5955
'GraphMetrics',

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
)
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
from ldai.providers.agent_graph_runner import AgentGraphRunner
2-
from ldai.providers.agent_runner import AgentRunner
32
from ldai.providers.ai_provider import AIProvider
4-
from ldai.providers.model_runner import ModelRunner
53
from ldai.providers.runner import Runner
64
from ldai.providers.runner_factory import RunnerFactory
75
from ldai.providers.types import (
86
AgentGraphResult,
97
AgentGraphRunnerResult,
10-
AgentResult,
118
GraphMetrics,
129
GraphMetricSummary,
1310
JudgeResult,
1411
LDAIMetrics,
1512
ManagedGraphResult,
1613
ManagedResult,
17-
ModelResponse,
1814
RunnerResult,
19-
StructuredResponse,
2015
ToolRegistry,
2116
)
2217

@@ -25,19 +20,14 @@
2520
'AgentGraphResult',
2621
'AgentGraphRunner',
2722
'AgentGraphRunnerResult',
28-
'AgentResult',
29-
'AgentRunner',
3023
'GraphMetrics',
3124
'GraphMetricSummary',
3225
'JudgeResult',
3326
'LDAIMetrics',
3427
'ManagedGraphResult',
3528
'ManagedResult',
36-
'ModelResponse',
37-
'ModelRunner',
3829
'Runner',
3930
'RunnerFactory',
4031
'RunnerResult',
41-
'StructuredResponse',
4232
'ToolRegistry',
4333
]

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

Lines changed: 0 additions & 28 deletions
This file was deleted.

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.

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

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

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from dataclasses import dataclass, field
77
from typing import Any, Callable, Dict, List, Optional
88

9-
from ldai.models import LDMessage
109
from ldai.tracker import LDAIMetricSummary, TokenUsage
1110

1211
# Type alias for a registry of tools available to an agent.
@@ -87,33 +86,6 @@ class ManagedResult:
8786
"""Optional asyncio Task that resolves to the list of :class:`JudgeResult` instances when awaited."""
8887

8988

90-
@dataclass
91-
class ModelResponse:
92-
"""
93-
Response from a model invocation.
94-
95-
.. deprecated::
96-
Use :class:`RunnerResult` (from a runner) and :class:`ManagedResult`
97-
(from the managed layer) instead.
98-
"""
99-
message: LDMessage
100-
metrics: LDAIMetrics
101-
evaluations: Optional[asyncio.Task[List[JudgeResult]]] = None
102-
103-
104-
@dataclass
105-
class StructuredResponse:
106-
"""
107-
Structured response from AI models.
108-
109-
.. deprecated::
110-
Structured output is now represented by :attr:`RunnerResult.parsed`.
111-
"""
112-
data: Dict[str, Any]
113-
raw_response: str
114-
metrics: LDAIMetrics
115-
116-
11789
@dataclass
11890
class GraphMetrics:
11991
"""Contains raw metrics from a single agent graph run."""
@@ -234,20 +206,6 @@ def to_dict(self) -> Dict[str, Any]:
234206
return result
235207

236208

237-
@dataclass
238-
class AgentResult:
239-
"""
240-
Result from a single-agent run.
241-
242-
.. deprecated::
243-
Use :class:`ManagedResult` (managed layer) or :class:`RunnerResult`
244-
(runner layer) instead.
245-
"""
246-
output: str
247-
raw: Any
248-
metrics: LDAIMetrics
249-
250-
251209
@dataclass
252210
class AgentGraphResult:
253211
"""Contains the result of an agent graph run."""

packages/sdk/server-ai/tests/test_runner_abcs.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
import pytest
22

3-
from ldai.providers import AgentGraphResult, AgentGraphRunner, AgentRunner, ToolRegistry
3+
from ldai.providers import AgentGraphResult, AgentGraphRunner, ToolRegistry
44
from ldai.providers.types import LDAIMetrics, RunnerResult
55

66

77
# --- Concrete test doubles ---
88

9-
class ConcreteAgentRunner:
10-
async def run(self, input):
11-
return RunnerResult(
12-
content=f"agent response to: {input}",
13-
metrics=LDAIMetrics(success=True),
14-
raw={"raw": input},
15-
)
16-
17-
189
class ConcreteAgentGraphRunner:
1910
async def run(self, input):
2011
return AgentGraphResult(
@@ -28,26 +19,6 @@ class MissingRunMethod:
2819
pass
2920

3021

31-
# --- AgentRunner ---
32-
33-
def test_agent_runner_structural_check_passes():
34-
assert isinstance(ConcreteAgentRunner(), AgentRunner)
35-
36-
37-
def test_agent_runner_structural_check_fails_when_run_missing():
38-
assert not isinstance(MissingRunMethod(), AgentRunner)
39-
40-
41-
@pytest.mark.asyncio
42-
async def test_agent_runner_run_returns_runner_result():
43-
runner = ConcreteAgentRunner()
44-
result = await runner.run("hello")
45-
assert isinstance(result, RunnerResult)
46-
assert result.content == "agent response to: hello"
47-
assert result.raw == {"raw": "hello"}
48-
assert result.metrics.success is True
49-
50-
5122
@pytest.mark.asyncio
5223
async def test_runner_result_fields():
5324
metrics = LDAIMetrics(success=True)
@@ -101,7 +72,6 @@ def test_tool_registry_is_dict_of_callables():
10172

10273
def test_top_level_exports():
10374
import ldai
104-
assert hasattr(ldai, 'AgentRunner')
10575
assert hasattr(ldai, 'AgentGraphRunner')
10676
assert hasattr(ldai, 'AgentGraphResult')
10777
assert hasattr(ldai, 'RunnerResult')

0 commit comments

Comments
 (0)