[CI][MCP][Harmony] Heavy refactoring Harmony & MCP response tests and stabilizing with deterministic test infrastructure (#33949)
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
@@ -346,17 +346,17 @@ class ParsableContext(ConversationContext):
|
||||
self.parser.response_messages.extend(output)
|
||||
|
||||
def need_builtin_tool_call(self) -> bool:
|
||||
"""Return true if the last message is a MCP tool call"""
|
||||
"""Return true if the last message is a builtin tool call
|
||||
that the request has enabled."""
|
||||
last_message = self.parser.response_messages[-1]
|
||||
# TODO(qandrew): figure out which tools are MCP tools
|
||||
if last_message.type == "function_call": # noqa: SIM102
|
||||
if last_message.name in (
|
||||
"code_interpreter",
|
||||
"python",
|
||||
"web_search_preview",
|
||||
) or last_message.name.startswith("container"):
|
||||
return True
|
||||
|
||||
if last_message.type != "function_call":
|
||||
return False
|
||||
if last_message.name in ("code_interpreter", "python"):
|
||||
return "python" in self.available_tools
|
||||
if last_message.name == "web_search_preview":
|
||||
return "browser" in self.available_tools
|
||||
if last_message.name.startswith("container"):
|
||||
return "container" in self.available_tools
|
||||
return False
|
||||
|
||||
async def call_python_tool(
|
||||
@@ -665,11 +665,15 @@ class HarmonyContext(ConversationContext):
|
||||
def need_builtin_tool_call(self) -> bool:
|
||||
last_msg = self.messages[-1]
|
||||
recipient = last_msg.recipient
|
||||
return recipient is not None and (
|
||||
recipient.startswith("browser.")
|
||||
or recipient.startswith("python")
|
||||
or recipient.startswith("container.")
|
||||
)
|
||||
if recipient is None:
|
||||
return False
|
||||
if recipient.startswith("browser."):
|
||||
return "browser" in self.available_tools
|
||||
if recipient.startswith("python"):
|
||||
return "python" in self.available_tools
|
||||
if recipient.startswith("container."):
|
||||
return "container" in self.available_tools
|
||||
return False
|
||||
|
||||
async def call_tool(self) -> list[Message]:
|
||||
if not self.messages:
|
||||
|
||||
@@ -392,13 +392,27 @@ class OpenAIServingResponses(OpenAIServing):
|
||||
max_model_len = self.model_config.max_model_len
|
||||
generators: list[AsyncGenerator[ConversationContext, None]] = []
|
||||
|
||||
# Only include builtin tools that the request actually asked for.
|
||||
# Without this filter, tools registered on the server (e.g. via
|
||||
# --tool-server demo) would be available for execution even when
|
||||
# the request didn't enable them.
|
||||
requested_tool_types = extract_tool_types(request.tools)
|
||||
builtin_tool_list: list[str] = []
|
||||
if self.tool_server is not None:
|
||||
if self.tool_server.has_tool("browser"):
|
||||
if (
|
||||
self.tool_server.has_tool("browser")
|
||||
and "web_search_preview" in requested_tool_types
|
||||
):
|
||||
builtin_tool_list.append("browser")
|
||||
if self.tool_server.has_tool("python"):
|
||||
if (
|
||||
self.tool_server.has_tool("python")
|
||||
and "code_interpreter" in requested_tool_types
|
||||
):
|
||||
builtin_tool_list.append("python")
|
||||
if self.tool_server.has_tool("container"):
|
||||
if (
|
||||
self.tool_server.has_tool("container")
|
||||
and "container" in requested_tool_types
|
||||
):
|
||||
builtin_tool_list.append("container")
|
||||
|
||||
if self.tool_server is not None:
|
||||
@@ -1049,9 +1063,15 @@ class OpenAIServingResponses(OpenAIServing):
|
||||
# FIXME(woosuk): Currently, request params like reasoning and
|
||||
# instructions are ignored.
|
||||
prev_msgs = self.msg_store[prev_response.id]
|
||||
# Remove the previous chain-of-thoughts if there is a new "final"
|
||||
# message. Note that this also removes these messages from the
|
||||
# msg_store.
|
||||
|
||||
# FIXME(woosuk): The slice-delete-reappend cycle below is
|
||||
# currently a no-op --- it removes messages then puts them all
|
||||
# back unfiltered. It may be intentionally deferred (see FIXME
|
||||
# above) or redundant if the Harmony encoder already strips
|
||||
# analysis messages at render time. If analysis messages need
|
||||
# to be dropped here, add a channel != "analysis" filter when
|
||||
# re-appending, similar to auto_drop_analysis_messages in
|
||||
# harmony_utils.py.
|
||||
if len(prev_msgs) > 0:
|
||||
last_msg = prev_msgs[-1]
|
||||
assert isinstance(last_msg, OpenAIHarmonyMessage)
|
||||
@@ -1072,7 +1092,11 @@ class OpenAIServingResponses(OpenAIServing):
|
||||
# Append the new input.
|
||||
# Responses API supports simple text inputs without chat format.
|
||||
if isinstance(request.input, str):
|
||||
messages.append(get_user_message(request.input))
|
||||
# Skip empty string input when previous_input_messages supplies
|
||||
# the full conversation history --- an empty trailing user message
|
||||
# confuses the model into thinking nothing was sent.
|
||||
if request.input or not request.previous_input_messages:
|
||||
messages.append(get_user_message(request.input))
|
||||
else:
|
||||
if prev_response is not None:
|
||||
prev_outputs = copy(prev_response.output)
|
||||
|
||||
Reference in New Issue
Block a user