mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-30 19:09:28 +00:00
fix(gemini): preserve bridged tool response name
This commit is contained in:
parent
9dcb44a219
commit
01cb38e8ec
2 changed files with 48 additions and 2 deletions
|
|
@ -321,9 +321,13 @@ def _translate_tool_result_to_gemini(
|
|||
) -> Dict[str, Any]:
|
||||
tool_name_by_call_id = tool_name_by_call_id or {}
|
||||
tool_call_id = str(message.get("tool_call_id") or "")
|
||||
# A tool result can carry the unwrapped internal tool name (for example,
|
||||
# an MCP tool invoked through the `tool_call` bridge). Gemini requires
|
||||
# functionResponse.name to echo the matching functionCall.name, so the
|
||||
# call-id mapping must take precedence over the internal result name.
|
||||
name = str(
|
||||
message.get("name")
|
||||
or tool_name_by_call_id.get(tool_call_id)
|
||||
tool_name_by_call_id.get(tool_call_id)
|
||||
or message.get("name")
|
||||
or tool_call_id
|
||||
or "tool"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -122,6 +122,48 @@ def test_build_native_request_uses_original_function_name_for_tool_result():
|
|||
assert tool_response["name"] == "get_weather"
|
||||
|
||||
|
||||
|
||||
def test_build_native_request_prefers_call_name_over_unwrapped_result_name():
|
||||
"""Gemini must receive the bridge call name, not the internal MCP name."""
|
||||
from agent.gemini_native_adapter import build_gemini_request
|
||||
|
||||
request = build_gemini_request(
|
||||
messages=[
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "call_1",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "tool_call",
|
||||
"arguments": (
|
||||
'{"name": "mcp__github__create_issue", '
|
||||
'"arguments": {"title": "Regression"}}'
|
||||
),
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"role": "tool",
|
||||
"name": "mcp__github__create_issue",
|
||||
"tool_name": "mcp__github__create_issue",
|
||||
"tool_call_id": "call_1",
|
||||
"content": '{"number": 123}',
|
||||
},
|
||||
],
|
||||
tools=[],
|
||||
tool_choice=None,
|
||||
)
|
||||
|
||||
function_call = request["contents"][0]["parts"][0]["functionCall"]
|
||||
function_response = request["contents"][1]["parts"][0]["functionResponse"]
|
||||
assert function_call["name"] == "tool_call"
|
||||
assert function_response["name"] == function_call["name"]
|
||||
|
||||
|
||||
def test_parallel_tool_results_merge_into_one_user_content():
|
||||
"""Gemini requires strict user/model alternation; two consecutive `user`
|
||||
contents are rejected with HTTP 400. Parallel tool calls produce two tool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue