-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
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_tooltrying 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.textWhen 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