Issue 内容
Please read this first
- Have you read the docs? Yes, I have read the Agents SDK docs
- Have you searched for related issues? Yes, I searched but didn't find similar issues related to non-OpenAI model compatibility with
codex_tool.
Describe the bug
When using codex_tool with a non-OpenAI model (e.g., DeepSeek via OpenAI-compatible API), the Codex CLI successfully executes commands and retrieves information, but never emits an agent_message event. This causes codex_tool to return the default fallback message "Codex task completed with inputs." instead of the actual analysis results.
The outer agent (which called the codex tool) receives this uninformative response and doesn't know what Codex actually found. This leads to:
- The outer agent repeatedly calling
codex_tool trying to get useful information
- Infinite loops or wasted API calls
- Poor user experience as the final response is empty or meaningless
Root cause analysis:
In codex_tool.py, the _consume_events function expects to receive an ItemCompletedEvent with item.type == "agent_message" to capture the final response:
if is_agent_message_item(event.item):
final_response = event.item.text
When no agent_message event is received, it falls back to:
if not final_response:
final_response = _build_default_response(args) # Returns "Codex task completed with inputs."
This fallback message contains no useful information from the actual Codex execution.
Debug information
- Agents SDK version:
v0.7.0
- Python version: Python 3.12.9
- Model used: DeepSeek (via Baidu Qianfan API with OpenAI-compatible endpoint)
- Codex CLI version: (latest)
Repro steps
import os
from agents import Agent, Runner
from agents.extensions.experimental.codex import codex_tool, ThreadOptions
# Configure to use a non-OpenAI model via OpenAI-compatible API
os.environ["OPENAI_API_KEY"] = "your-api-key"
os.environ["OPENAI_BASE_URL"] = "https://your-compatible-api.com/v1"
# Create codex tool
thread_options = ThreadOptions(
model="deepseek-v3.2", # or any non-OpenAI model
)
tool = codex_tool(
sandbox_mode="workspace-write",
default_thread_options=thread_options,
)
# Create agent with codex tool
agent = Agent(
name="Test Agent",
instructions="You are a helpful assistant. Use the codex tool to analyze code.",
model="deepseek-v3.2-think",
tools=[tool],
)
# Run a simple query
os.chdir("/path/to/your/code/workspace")
result = Runner.run_sync(agent, "How many Java files are in this project?")
print(result.final_output) # Often empty or unhelpful
Issue 内容
Please read this first
codex_tool.Describe the bug
When using
codex_toolwith a non-OpenAI model (e.g., DeepSeek via OpenAI-compatible API), the Codex CLI successfully executes commands and retrieves information, but never emits anagent_messageevent. This causescodex_toolto return the default fallback message"Codex task completed with inputs."instead of the actual analysis results.The outer agent (which called the codex tool) receives this uninformative response and doesn't know what Codex actually found. This leads to:
codex_tooltrying to get useful informationRoot cause analysis:
In
codex_tool.py, the_consume_eventsfunction expects to receive anItemCompletedEventwithitem.type == "agent_message"to capture the final response:When no
agent_messageevent is received, it falls back to:This fallback message contains no useful information from the actual Codex execution.
Debug information
v0.7.0Repro steps