Agent Zero AI framework
Build native tools only for Responses turns
Alessandroade204c7e3f2
diff --git a/AGENTS.md b/AGENTS.mdindex 747eaa2ab..9e075e34b 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -17,6 +17,7 @@- `agent.py` owns `Agent`, `AgentContext`, and loop data.- `Agent.hist_add_ai_response` owns Responses-API state advancement: it calls `_remember_llm_result_state` internally. Model turns pass an `LLMResult`; omitted results and legacy positional string IDs use the non-LLM sentinel. Callers must not invoke `_remember_llm_result_state` manually.- Prepared local Responses input may project intact native history through `helpers/responses_history.py`; retain original Chat/fallback messages, current protocol/extras, summaries and masking. Durable capability metadata stores only a stable-prefix digest for eligibility.+- `Agent.call_chat_model_turn` builds native function tools only when the chat model's `a0_api_mode` selects Responses; Chat Completions turns pass an empty tool list and name map, since that transport drops them.- Native function calls use canonical call content for history and repeat comparison, even when accompanied by commentary. The canonical content passes through the normal history template/masking hook; provider output metadata remains intact.- `initialize.py` owns framework initialization.- `models.py` owns model-provider configuration and LiteLLM integration. `get_api_key_raw()` reads the stored key or key list for settings/editing; `get_api_key()` selects a runtime key and runs provider extension hooks.diff --git a/agent.py b/agent.pyindex 2e558bd15..3c262300c 100644--- a/agent.py+++ b/agent.py@@ -40,7 +40,7 @@ from helpers.llm_result import (metadata_from_llm_result,result_from_metadata,)-from helpers.litellm_transport import ResponsesTransport+from helpers.litellm_transport import ResponsesTransport, TransportModefrom helpers.responses_tools import build_responses_function_tools, original_tool_name_RESPONSE_STREAM_UPDATE_CHARS = 128@@ -940,7 +940,13 @@ class Agent:model_kwargs = getattr(model, "kwargs", {}) if model else {}if isinstance(model_kwargs, dict) and model_kwargs.get("responses_delete_on_chat_delete") is False:self.set_data("responses_delete_on_chat_delete", False)- response_tools, name_map = build_responses_function_tools(self)+ # native function tools are only sent through the Responses API+ api_mode = model_kwargs.get("a0_api_mode") if isinstance(model_kwargs, dict) else None+ response_tools, name_map = (+ build_responses_function_tools(self)+ if TransportMode.from_value(api_mode) is TransportMode.RESPONSES+ else ([], {})+ )self.set_data(Agent.DATA_NAME_RESPONSES_TOOL_NAME_MAP, name_map)call_data = {diff --git a/tests/test_responses_architecture.py b/tests/test_responses_architecture.pyindex 0f2644f10..f2377159c 100644--- a/tests/test_responses_architecture.py+++ b/tests/test_responses_architecture.py@@ -776,6 +776,45 @@ def test_collect_response_ids_from_agent_state_and_history_metadata():][email protected]("api_mode, builds_tools", [("chat", False), ("responses", True)])+async def test_agent_builds_native_tools_only_for_responses_turns(+ monkeypatch, api_mode, builds_tools+):+ import agent as agent_module++ tools = [{"type": "function", "name": "lookup", "parameters": {"type": "object"}}]+ calls = []+ monkeypatch.setattr(+ agent_module,+ "build_responses_function_tools",+ lambda agent: calls.append(agent) or (tools, {"lookup": "lookup"}),+ )++ async def no_extensions(*args, **kwargs):+ return None++ monkeypatch.setattr(extension, "call_extensions_async", no_extensions)+ turn_kwargs = {}++ class Model:+ kwargs = {"a0_api_mode": api_mode}++ async def unified_turn(self, **kwargs):+ turn_kwargs.update(kwargs)+ return LLMResult.from_chat(response="ok")++ agent = object.__new__(Agent)+ agent.data = {}+ agent.loop_data = LoopData()+ agent.get_chat_model = lambda: Model()++ await Agent.call_chat_model_turn(agent, messages=[HumanMessage(content="hi")])++ assert bool(calls) is builds_tools+ assert turn_kwargs["a0_responses_function_tools"] == (tools if builds_tools else [])++@pytest.mark.asyncioasync def test_agent_executes_native_responses_function_call_and_records_output():class DummyContext: