π OpenHands: AI-Driven Development
Revert "Add support for passing list of `Message` into LLM `completion`" (#10653)
mamoodi9630b536cda7
diff --git a/openhands/agenthub/browsing_agent/browsing_agent.py b/openhands/agenthub/browsing_agent/browsing_agent.pyindex cd1decd261..bf2c0960a0 100644--- a/openhands/agenthub/browsing_agent/browsing_agent.py+++ b/openhands/agenthub/browsing_agent/browsing_agent.py@@ -217,7 +217,7 @@ class BrowsingAgent(Agent):messages.append(Message(role='user', content=[TextContent(text=prompt)]))response = self.llm.completion(- messages=messages,+ messages=self.llm.format_messages_for_llm(messages),stop=[')```', ')\n```'],)return self.response_parser.parse(response)diff --git a/openhands/agenthub/codeact_agent/codeact_agent.py b/openhands/agenthub/codeact_agent/codeact_agent.pyindex 1f4686c0f0..402d4ba1d1 100644--- a/openhands/agenthub/codeact_agent/codeact_agent.py+++ b/openhands/agenthub/codeact_agent/codeact_agent.py@@ -204,7 +204,7 @@ class CodeActAgent(Agent):initial_user_message = self._get_initial_user_message(state.history)messages = self._get_messages(condensed_history, initial_user_message)params: dict = {- 'messages': messages,+ 'messages': self.llm.format_messages_for_llm(messages),}params['tools'] = check_tools(self.tools, self.llm.config)params['extra_body'] = {diff --git a/openhands/agenthub/visualbrowsing_agent/visualbrowsing_agent.py b/openhands/agenthub/visualbrowsing_agent/visualbrowsing_agent.pyindex 0603da38f9..322629d3a3 100644--- a/openhands/agenthub/visualbrowsing_agent/visualbrowsing_agent.py+++ b/openhands/agenthub/visualbrowsing_agent/visualbrowsing_agent.py@@ -301,8 +301,10 @@ You are an agent trying to solve a web task based on the content of the page andmessages.append(Message(role='system', content=[TextContent(text=system_msg)]))messages.append(Message(role='user', content=human_prompt))+ flat_messages = self.llm.format_messages_for_llm(messages)+response = self.llm.completion(- messages=messages,+ messages=flat_messages,temperature=0.0,stop=[')```', ')\n```'],)diff --git a/openhands/llm/llm.py b/openhands/llm/llm.pyindex 2ed942df15..d3926848cc 100644--- a/openhands/llm/llm.py+++ b/openhands/llm/llm.py@@ -3,7 +3,7 @@ import osimport timeimport warningsfrom functools import partial-from typing import Any, Callable, cast+from typing import Any, Callableimport httpx@@ -220,9 +220,7 @@ class LLM(RetryMixin, DebugMixin):"""Wrapper for the litellm completion function. Logs the input and output of the completion function."""from openhands.io import json- messages_kwarg: (- dict[str, Any] | Message | list[dict[str, Any]] | list[Message]- ) = []+ messages_kwarg: list[dict[str, Any]] | dict[str, Any] = []mock_function_calling = not self.is_function_calling_active()# some callers might send the model and messages directly@@ -241,17 +239,9 @@ class LLM(RetryMixin, DebugMixin):messages_kwarg = kwargs['messages']# ensure we work with a list of messages- messages_list = (+ messages: list[dict[str, Any]] = (messages_kwarg if isinstance(messages_kwarg, list) else [messages_kwarg])- # Format Message objects to dict format if needed- messages: list[dict] = []- if messages_list and isinstance(messages_list[0], Message):- messages = self.format_messages_for_llm(- cast(list[Message], messages_list)- )- else:- messages = cast(list[dict[str, Any]], messages_list)# handle conversion of to non-function calling messages if neededoriginal_fncall_messages = copy.deepcopy(messages)