Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/sdk/server-ai/src/ldai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
AgentGraphResult,
AgentGraphRunner,
AgentGraphRunnerResult,
AgentResult,
AgentRunner,
GraphMetrics,
GraphMetricSummary,
Expand All @@ -53,7 +52,6 @@
'Evaluator',
'AgentRunner',
'AgentGraphRunner',
'AgentResult',
'AgentGraphResult',
'AgentGraphRunnerResult',
'GraphMetrics',
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/server-ai/src/ldai/managed_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ldai import log
from ldai.models import AICompletionConfig, LDMessage
from ldai.providers.runner import Runner
from ldai.providers.types import JudgeResult, ManagedResult
from ldai.providers.types import JudgeResult, ManagedResult, RunnerResult
from ldai.tracker import LDAIConfigTracker


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

result = await tracker.track_metrics_of_async(
result: RunnerResult = await tracker.track_metrics_of_async(
lambda r: r.metrics,
lambda: self._model_runner.run(all_messages),
)
Expand Down
6 changes: 0 additions & 6 deletions packages/sdk/server-ai/src/ldai/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
from ldai.providers.types import (
AgentGraphResult,
AgentGraphRunnerResult,
AgentResult,
GraphMetrics,
GraphMetricSummary,
JudgeResult,
LDAIMetrics,
ManagedGraphResult,
ManagedResult,
ModelResponse,
RunnerResult,
StructuredResponse,
ToolRegistry,
)

Expand All @@ -25,19 +22,16 @@
'AgentGraphResult',
'AgentGraphRunner',
'AgentGraphRunnerResult',
'AgentResult',
'AgentRunner',
'GraphMetrics',
'GraphMetricSummary',
'JudgeResult',
'LDAIMetrics',
'ManagedGraphResult',
'ManagedResult',
'ModelResponse',
'ModelRunner',
'Runner',
'RunnerFactory',
'RunnerResult',
'StructuredResponse',
'ToolRegistry',
]
6 changes: 3 additions & 3 deletions packages/sdk/server-ai/src/ldai/providers/agent_runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Protocol, runtime_checkable

from ldai.providers.types import AgentResult
from ldai.providers.types import RunnerResult


@runtime_checkable
Expand All @@ -18,11 +18,11 @@ class AgentRunner(Protocol):
the caller just passes input.
"""

async def run(self, input: Any) -> AgentResult:
async def run(self, input: Any) -> RunnerResult:
"""
Run the agent with the given input.

:param input: The input to the agent (string prompt or structured input)
:return: AgentResult containing the output, raw response, and metrics
:return: RunnerResult containing the agent's content, metrics, and optional raw/parsed fields
"""
...
50 changes: 2 additions & 48 deletions packages/sdk/server-ai/src/ldai/providers/ai_provider.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from abc import ABC
from typing import Any, Dict, List, Optional
from typing import Any, Optional

from ldai import log
from ldai.models import LDMessage
from ldai.providers.types import ModelResponse, StructuredResponse, ToolRegistry
from ldai.providers.types import ToolRegistry


class AIProvider(ABC):
Expand All @@ -16,51 +15,6 @@ class AIProvider(ABC):
create_model(), create_agent(), and create_agent_graph().
"""

async def invoke_model(self, messages: List[LDMessage]) -> ModelResponse:
"""
Invoke the chat model with an array of messages.

Default implementation takes no action and returns a placeholder response.
Provider implementations should override this method.

:param messages: Array of LDMessage objects representing the conversation
:return: ModelResponse containing the model's response
"""
log.warning('invoke_model not implemented by this provider')

from ldai.models import LDMessage
from ldai.providers.types import LDAIMetrics

return ModelResponse(
message=LDMessage(role='assistant', content=''),
metrics=LDAIMetrics(success=False, usage=None),
)

async def invoke_structured_model(
self,
messages: List[LDMessage],
response_structure: Dict[str, Any],
) -> StructuredResponse:
"""
Invoke the chat model with structured output support.

Default implementation takes no action and returns a placeholder response.
Provider implementations should override this method.

:param messages: Array of LDMessage objects representing the conversation
:param response_structure: Dictionary of output configurations keyed by output name
:return: StructuredResponse containing the structured data
"""
log.warning('invoke_structured_model not implemented by this provider')

from ldai.providers.types import LDAIMetrics

return StructuredResponse(
data={},
raw_response='',
metrics=LDAIMetrics(success=False, usage=None),
)

def create_model(self, config: Any) -> Optional[Any]:
"""
Create a configured model executor for the given AI config.
Expand Down
22 changes: 4 additions & 18 deletions packages/sdk/server-ai/src/ldai/providers/model_runner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Dict, List, Protocol, runtime_checkable
from typing import List, Protocol, runtime_checkable

from ldai.models import LDMessage
from ldai.providers.types import ModelResponse, StructuredResponse
from ldai.providers.types import RunnerResult


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

async def invoke_model(self, messages: List[LDMessage]) -> ModelResponse:
async def invoke_model(self, messages: List[LDMessage]) -> RunnerResult:
"""
Invoke the model with an array of messages.

:param messages: Array of LDMessage objects representing the conversation
:return: ModelResponse containing the model's response and metrics
"""
...
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModelRunner protocol is dead code after migration

Low Severity

The ModelRunner protocol defines invoke_model but nothing in the codebase calls this method or type-checks against this protocol. Both OpenAIModelRunner and LangChainModelRunner implement Runner (with its run method), not ModelRunner. The managed layer exclusively uses Runner. Implementing ModelRunner alone would not satisfy the Runner protocol the SDK requires, making this export misleading and effectively dead code that outlived its purpose during the migration.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 87007b9. Configure here.


async def invoke_structured_model(
self,
messages: List[LDMessage],
response_structure: Dict[str, Any],
) -> StructuredResponse:
"""
Invoke the model with structured output support.

:param messages: Array of LDMessage objects representing the conversation
:param response_structure: Dictionary defining the JSON schema for output structure
:return: StructuredResponse containing the structured data
:return: RunnerResult containing the model's response and metrics
"""
...
42 changes: 0 additions & 42 deletions packages/sdk/server-ai/src/ldai/providers/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, Optional

from ldai.models import LDMessage
from ldai.tracker import LDAIMetricSummary, TokenUsage

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


@dataclass
class ModelResponse:
"""
Response from a model invocation.

.. deprecated::
Use :class:`RunnerResult` (from a runner) and :class:`ManagedResult`
(from the managed layer) instead.
"""
message: LDMessage
metrics: LDAIMetrics
evaluations: Optional[asyncio.Task[List[JudgeResult]]] = None


@dataclass
class StructuredResponse:
"""
Structured response from AI models.

.. deprecated::
Structured output is now represented by :attr:`RunnerResult.parsed`.
"""
data: Dict[str, Any]
raw_response: str
metrics: LDAIMetrics


@dataclass
class GraphMetrics:
"""Contains raw metrics from a single agent graph run."""
Expand Down Expand Up @@ -234,20 +206,6 @@ def to_dict(self) -> Dict[str, Any]:
return result


@dataclass
class AgentResult:
"""
Result from a single-agent run.

.. deprecated::
Use :class:`ManagedResult` (managed layer) or :class:`RunnerResult`
(runner layer) instead.
"""
output: str
raw: Any
metrics: LDAIMetrics


@dataclass
class AgentGraphResult:
"""Contains the result of an agent graph run."""
Expand Down
Loading