22from typing import List
33
44from ldai import log
5- from ldai .models import AICompletionConfig , LDMessage
5+ from ldai .models import AICompletionConfig
66from ldai .providers .runner import Runner
77from ldai .providers .types import JudgeResult , ManagedResult , RunnerResult
88from ldai .tracker import LDAIConfigTracker
@@ -12,9 +12,10 @@ class ManagedModel:
1212 """
1313 LaunchDarkly managed wrapper for AI model invocations.
1414
15- Holds a Runner. Handles conversation management, judge evaluation
16- dispatch, and tracking automatically via ``create_tracker()``.
17- Obtain an instance via ``LDAIClient.create_model()``.
15+ Holds a Runner. Handles judge evaluation dispatch and tracking
16+ automatically via ``create_tracker()``. Conversation history is
17+ managed by the runner. Obtain an instance via
18+ ``LDAIClient.create_model()``.
1819 """
1920
2021 def __init__ (
@@ -24,37 +25,26 @@ def __init__(
2425 ):
2526 self ._ai_config = ai_config
2627 self ._model_runner = model_runner
27- self ._messages : List [LDMessage ] = []
2828
2929 async def run (self , prompt : str ) -> ManagedResult :
3030 """
3131 Run the model with a prompt string.
3232
33- Appends the prompt to the conversation history, prepends any
34- system messages from the config, delegates to the runner, and
35- appends the response to the history.
33+ Delegates to the runner, then dispatches judge evaluations and
34+ records tracking metrics.
3635
3736 :param prompt: The user prompt to send to the model
3837 :return: ManagedResult containing the model's response, metric summary,
3938 and an optional evaluations task
4039 """
4140 tracker = self ._ai_config .create_tracker ()
4241
43- user_message = LDMessage (role = 'user' , content = prompt )
44- self ._messages .append (user_message )
45-
4642 result : RunnerResult = await tracker .track_metrics_of_async (
4743 lambda r : r .metrics ,
4844 lambda : self ._model_runner .run (prompt ),
4945 )
5046
51- assistant_message = LDMessage (role = 'assistant' , content = result .content )
52-
53- input_text = '\r \n ' .join (m .content for m in self ._messages ) if self ._messages else ''
54-
55- evaluations_task = self ._track_judge_results (tracker , input_text , result .content )
56-
57- self ._messages .append (assistant_message )
47+ evaluations_task = self ._track_judge_results (tracker , prompt , result .content )
5848
5949 return ManagedResult (
6050 content = result .content ,
@@ -88,25 +78,6 @@ async def _run_and_track(eval_task: asyncio.Task) -> List[JudgeResult]:
8878
8979 return asyncio .create_task (_run_and_track (evaluator_task ))
9080
91- def get_messages (self , include_config_messages : bool = False ) -> List [LDMessage ]:
92- """
93- Get all messages in the conversation history.
94-
95- :param include_config_messages: When True, prepends config messages.
96- :return: List of conversation messages.
97- """
98- if include_config_messages :
99- return (self ._ai_config .messages or []) + self ._messages
100- return list (self ._messages )
101-
102- def append_messages (self , messages : List [LDMessage ]) -> None :
103- """
104- Append messages to the conversation history without invoking the model.
105-
106- :param messages: Messages to append.
107- """
108- self ._messages .extend (messages )
109-
11081 def get_model_runner (self ) -> Runner :
11182 """
11283 Return the underlying runner for advanced use.
0 commit comments