Skip to content

Agent Zero AI framework

Fix Responses tool call completion

Alessandroa767824fb63e
diff --git a/helpers/litellm_transport.py b/helpers/litellm_transport.py
index f84a12285..6a1498b71 100644
--- a/helpers/litellm_transport.py
+++ b/helpers/litellm_transport.py
@@ -428,7 +428,13 @@ class LiteLLMTransport:
) -> LLMResult | None:
if parser.completed_response is None:
return None
- return self._llm_result_from_response(parser.completed_response, request)
+ response = _object_to_dict(parser.completed_response)
+ output = _as_list(response.get("output"))
+ if parser.function_calls and not any(
+ _get_value(item, "type") == "function_call" for item in output
+ ):
+ response["output"] = [*output, *parser.function_calls.values()]
+ return self._llm_result_from_response(response, request)
def _stream_result_from_chat_parser(
self, parser: "ChatCompletionsStreamParser"
diff --git a/helpers/litellm_transport.py.dox.md b/helpers/litellm_transport.py.dox.md
index 710765642..1a8e20795 100644
--- a/helpers/litellm_transport.py.dox.md
+++ b/helpers/litellm_transport.py.dox.md
@@ -33,6 +33,7 @@
- Fall back to Chat Completions when a Responses endpoint fails before output with an endpoint-specific server error, proxy path-unavailable error, or LiteLLM proxy-extra import error.
- Fall back to Chat Completions when LiteLLM's Responses mock streaming path tries to JSON-decode a real SSE stream before any output.
- Preserve Chat Completions tool calls from both non-streaming responses and streaming deltas as canonical `LLMResult` function-call items.
+- Preserve Responses function calls collected from stream events when a terminal completed event omits them.
- Preserve provider-state metadata when Responses API calls succeed, and fall back to local replay when provider state is unsupported.
- Keep prompt-cache markers only for providers that accept them.
diff --git a/helpers/responses_tools.py b/helpers/responses_tools.py
index 93778d652..8bfffedca 100644
--- a/helpers/responses_tools.py
+++ b/helpers/responses_tools.py
@@ -39,20 +39,31 @@ def build_responses_function_tools(agent: Any) -> tuple[list[dict[str, Any]], di
continue
native_name = _native_tool_name(tool_name)
name_map[native_name] = tool_name
- tools.append(
+ parameters = (
{
- "type": "function",
- "name": native_name,
- "description": _truncate(
- tool_policy.tool_prompt_description(
- prompt,
- tool_name,
- fallback=tool_name,
- )
- ),
- "parameters": _schema_from_prompt(prompt),
+ "type": "object",
+ "properties": {"text": {"type": "string"}},
+ "required": ["text"],
+ "additionalProperties": False,
}
+ if tool_name == "response"
+ else _schema_from_prompt(prompt)
)
+ tool = {
+ "type": "function",
+ "name": native_name,
+ "description": _truncate(
+ tool_policy.tool_prompt_description(
+ prompt,
+ tool_name,
+ fallback=tool_name,
+ )
+ ),
+ "parameters": parameters,
+ }
+ if tool_name == "response":
+ tool["strict"] = True
+ tools.append(tool)
for tool_name, tool in _mcp_tools(agent):
if not tool_policy.resolve_tool(
diff --git a/helpers/responses_tools.py.dox.md b/helpers/responses_tools.py.dox.md
index f534eda5e..58a493b11 100644
--- a/helpers/responses_tools.py.dox.md
+++ b/helpers/responses_tools.py.dox.md
@@ -17,6 +17,7 @@
owns the Responses-specific prompt-name compatibility rules.
- Local prompt-derived function names use existing bullet declarations that pair a backticked name with `arg` or `args` for multi-tool prompt files, otherwise prefer explicit `"tool_name"` examples, then the first prompt heading, and finally the prompt filename.
- Apply registered tool-prompt render kwargs before deriving native metadata so descriptions never expose unresolved prompt templates.
+- Always expose the native `response` tool as strict with one required `text` string, independent of profile prompt wording.
- Use an explicitly embedded JSON input schema when present. Infer only an unambiguous single backticked argument on an otherwise empty `args:` line; all other local tools receive an honest permissive object schema instead of prose-guessed types.
- Native local-tool descriptions reuse the tool catalog's compact prompt
description; Responses retains native-name mapping, schema derivation, and
diff --git a/tests/test_responses_architecture.py b/tests/test_responses_architecture.py
index 1a195cb62..f344e9ebf 100644
--- a/tests/test_responses_architecture.py
+++ b/tests/test_responses_architecture.py
@@ -249,7 +249,9 @@ async def test_transport_downgrades_unsupported_builtin_tools(monkeypatch):
@pytest.mark.asyncio
-async def test_unified_turn_captures_response_id_without_stop_request(monkeypatch):
+async def test_unified_turn_keeps_streamed_call_when_completion_omits_output(
+ monkeypatch,
+):
stream = _AsyncEventStream(
[
{
@@ -274,15 +276,7 @@ async def test_unified_turn_captures_response_id_without_stop_request(monkeypatc
"type": "response.completed",
"response": {
"id": "resp_1",
- "output": [
- {
- "type": "function_call",
- "id": "fc_1",
- "call_id": "call_1",
- "name": "lookup",
- "arguments": '{"q":"a0"}',
- }
- ],
+ "output": [],
},
},
]
@@ -315,6 +309,7 @@ async def test_unified_turn_captures_response_id_without_stop_request(monkeypatc
assert stream.closed is False
assert result.response_id == "resp_1"
assert result.function_calls[0].call_id == "call_1"
+ assert result.function_calls[0].arguments == {"q": "a0"}
@pytest.mark.asyncio
diff --git a/tests/test_responses_tools.py b/tests/test_responses_tools.py
index aaacaec6c..e1790b8da 100644
--- a/tests/test_responses_tools.py
+++ b/tests/test_responses_tools.py
@@ -168,20 +168,40 @@ def test_responses_function_tools_add_empty_properties_to_mcp_schemas(
]
-def test_response_tool_native_contract_omits_wrapper_and_exposes_text():
- prompt = (PROJECT_ROOT / "prompts" / "agent.system.tool.response.md").read_text(
- encoding="utf-8"
- )
+def test_response_tool_native_contract_is_strict_and_requires_text(monkeypatch):
+ prompt_root = PROJECT_ROOT / "agents" / "agent0" / "prompts"
+ prompt = (prompt_root / "agent.system.tool.response.md").read_text(encoding="utf-8")
description = tool_policy.tool_prompt_description(
prompt,
"response",
fallback="response",
)
- schema = responses_tools._schema_from_prompt(prompt)
+ monkeypatch.setattr(
+ responses_tools.subagents,
+ "get_paths",
+ lambda *args, **kwargs: [str(prompt_root)],
+ )
+ monkeypatch.setattr(
+ responses_tools,
+ "_include_local_tool_prompt",
+ lambda agent, tool_name: True,
+ )
+ monkeypatch.setattr(responses_tools, "_vision_tool_prompt", lambda agent: "")
+ monkeypatch.setattr(responses_tools, "_mcp_tools", lambda agent: [])
+ tools, _name_map = responses_tools.build_responses_function_tools(
+ FakeAgent(prompt_root)
+ )
+ response_tool = next(tool for tool in tools if tool["name"] == "response")
assert description == "final answer to user"
- assert schema["properties"] == {"text": {"type": "string"}}
+ assert response_tool["parameters"] == {
+ "type": "object",
+ "properties": {"text": {"type": "string"}},
+ "required": ["text"],
+ "additionalProperties": False,
+ }
+ assert response_tool["strict"] is True
def test_complex_prompt_args_are_not_guessed_as_string_schemas():