Agent Zero AI framework
Scope strict response schema to Codex
Alessandrofdf64a7f29f8
diff --git a/helpers/responses_tools.py b/helpers/responses_tools.pyindex 8bfffedca..93778d652 100644--- a/helpers/responses_tools.py+++ b/helpers/responses_tools.py@@ -39,31 +39,20 @@ def build_responses_function_tools(agent: Any) -> tuple[list[dict[str, Any]], dicontinuenative_name = _native_tool_name(tool_name)name_map[native_name] = tool_name- parameters = (+ tools.append({- "type": "object",- "properties": {"text": {"type": "string"}},- "required": ["text"],- "additionalProperties": False,+ "type": "function",+ "name": native_name,+ "description": _truncate(+ tool_policy.tool_prompt_description(+ prompt,+ tool_name,+ fallback=tool_name,+ )+ ),+ "parameters": _schema_from_prompt(prompt),}- 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.mdindex 58a493b11..7c2631867 100644--- a/helpers/responses_tools.py.dox.md+++ b/helpers/responses_tools.py.dox.md@@ -17,7 +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.+- Keep emitted schemas provider-neutral; provider-specific strictness belongs at the provider request boundary.- 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 promptdescription; Responses retains native-name mapping, schema derivation, anddiff --git a/plugins/_oauth/AGENTS.md b/plugins/_oauth/AGENTS.mdindex 8e5f32e07..cdb3f9d3e 100644--- a/plugins/_oauth/AGENTS.md+++ b/plugins/_oauth/AGENTS.md@@ -46,6 +46,7 @@- Codex Responses proxy requests must include Codex client metadata and compatibility headers such as `client_metadata`, `x-codex-installation-id`, `originator`, `session-id`, and `thread-id`, and must forward `input` as a list for upstream Codex compatibility.- Codex Responses proxy requests must translate the legacy top-level `reasoning_effort` field to `reasoning.effort`; an explicit native `reasoning` field takes precedence.- Codex Responses proxy defaults for reasoning effort, reasoning summary, and text verbosity come from the `codex` plugin config; explicit native request values take precedence.+- Codex request shaping tightens an already-advertised native `response` tool to a strict required `text` schema; it must not add tools omitted by the framework tool policy.- OAuth providers without upstream Responses support must set `a0_api_mode: chat`; native Responses providers rely on the default, since a local proxy route alone does not prove upstream support.## Work Guidancediff --git a/plugins/_oauth/helpers/codex.py b/plugins/_oauth/helpers/codex.pyindex 3018dbe89..9559f8f90 100644--- a/plugins/_oauth/helpers/codex.py+++ b/plugins/_oauth/helpers/codex.py@@ -670,6 +670,25 @@ def fetch_models() -> list[str]:def prepare_responses_body(body: dict[str, Any], *, force_stream: bool) -> dict[str, Any]:normalized = dict(body)settings = codex_config()+ tools = normalized.get("tools")+ if isinstance(tools, list):+ normalized["tools"] = [+ {+ **tool,+ "strict": True,+ "parameters": {+ "type": "object",+ "properties": {"text": {"type": "string"}},+ "required": ["text"],+ "additionalProperties": False,+ },+ }+ if isinstance(tool, dict)+ and tool.get("type") == "function"+ and tool.get("name") == "response"+ else tool+ for tool in tools+ ]reasoning_effort = normalized.pop("reasoning_effort", None)reasoning = normalized.get("reasoning")if isinstance(reasoning, dict):diff --git a/tests/test_oauth_codex.py b/tests/test_oauth_codex.pyindex 02592f7f9..9df1576be 100644--- a/tests/test_oauth_codex.py+++ b/tests/test_oauth_codex.py@@ -208,6 +208,44 @@ def test_prepare_responses_body_adds_codex_client_metadata(monkeypatch):assert body["include"] == ["output_text", "reasoning.encrypted_content"]+def test_prepare_responses_body_tightens_existing_response_tool_only(monkeypatch):+ monkeypatch.setattr(codex, "build_client_metadata", lambda: {})+ response_tool = {+ "type": "function",+ "name": "response",+ "description": "final answer",+ "parameters": {"type": "object", "additionalProperties": True},+ }+ other_tool = {+ "type": "function",+ "name": "search",+ "parameters": {"type": "object", "additionalProperties": True},+ }++ body = codex.prepare_responses_body(+ {"input": [], "tools": [response_tool, other_tool]},+ force_stream=True,+ )++ assert body["tools"] == [+ {+ **response_tool,+ "strict": True,+ "parameters": {+ "type": "object",+ "properties": {"text": {"type": "string"}},+ "required": ["text"],+ "additionalProperties": False,+ },+ },+ other_tool,+ ]+ assert codex.prepare_responses_body(+ {"input": [], "tools": [other_tool]},+ force_stream=True,+ )["tools"] == [other_tool]++@pytest.mark.parametrize(("request_reasoning", "expected"),[diff --git a/tests/test_responses_tools.py b/tests/test_responses_tools.pyindex e1790b8da..154f5b060 100644--- a/tests/test_responses_tools.py+++ b/tests/test_responses_tools.py@@ -168,7 +168,7 @@ def test_responses_function_tools_add_empty_properties_to_mcp_schemas(]-def test_response_tool_native_contract_is_strict_and_requires_text(monkeypatch):+def test_response_tool_native_contract_stays_provider_neutral(monkeypatch):prompt_root = PROJECT_ROOT / "agents" / "agent0" / "prompts"prompt = (prompt_root / "agent.system.tool.response.md").read_text(encoding="utf-8")@@ -195,13 +195,8 @@ def test_response_tool_native_contract_is_strict_and_requires_text(monkeypatch):response_tool = next(tool for tool in tools if tool["name"] == "response")assert description == "final answer to user"- assert response_tool["parameters"] == {- "type": "object",- "properties": {"text": {"type": "string"}},- "required": ["text"],- "additionalProperties": False,- }- assert response_tool["strict"] is True+ assert response_tool["parameters"] == responses_tools._schema_from_prompt(prompt)+ assert "strict" not in response_tooldef test_complex_prompt_args_are_not_guessed_as_string_schemas():