Skip to content

feat(transports/codex): pass reasoning.effort to xAI Responses API - #22055

Closed
Julientalbot wants to merge 1 commit into
NousResearch:mainfrom
Julientalbot:jt/xai-reasoning-effort-pass
Closed

feat(transports/codex): pass reasoning.effort to xAI Responses API#22055
Julientalbot wants to merge 1 commit into
NousResearch:mainfrom
Julientalbot:jt/xai-reasoning-effort-pass

Conversation

@Julientalbot

Copy link
Copy Markdown
Contributor

Problem

The xAI direct path (is_xai_responses=True) in agent/transports/codex.py only forwards include=["reasoning.encrypted_content"] and silently drops the resolved reasoning_effort. The sibling non-xAI Responses branch already passes kwargs["reasoning"] = {"effort": ..., "summary": "auto"}.

This means agent.reasoning_effort (and any reasoning_config.effort injected by callers) is silently ignored on the xAI direct route. Setting low, medium, or high in config has zero effect — xAI receives no reasoning field and uses its server-side default.

Why this matters

For agentic tool-calling on grok-4.x, xAI's docs explicitly recommend reasoning_effort: low (model-capabilities/text/reasoning). When Hermes can't transmit this, users running Telegram bots / CLIs report:

  • "intention without execution" patterns (model says "I'll check..." but emits no tool_call)
  • inability to control thinking depth between latency-sensitive and analysis-heavy tasks

A 100-call benchmark across efforts on a real-world Alfred-style session showed pass rate variance: none=58%, low=87%, medium=82%, high=86% — variance that's currently inaccessible from config on the xAI direct path.

Fix

One-line change: in the is_xai_responses branch, also pass kwargs["reasoning"] = {"effort": reasoning_effort}. We deliberately omit summary: "auto" (used by the OpenAI Responses branch) since xAI's Responses API documentation does not mention it — conservative posture pending confirmation.

 if reasoning_enabled and is_xai_responses:
     kwargs["include"] = ["reasoning.encrypted_content"]
+    kwargs["reasoning"] = {"effort": reasoning_effort}
 elif reasoning_enabled:
     ...

Tests

3 new tests in tests/agent/transports/test_codex_transport.py::TestCodexBuildKwargs:

  • test_xai_reasoning_effort_passed — asserts kw["reasoning"] == {"effort": "high"} and the encrypted-content include remains.
  • test_xai_reasoning_disabled_no_reasoning_key — asserts "reasoning" not in kw when reasoning_config={"enabled": False}.
  • test_xai_minimal_effort_clamped — parity with the existing non-xAI clamp test (minimal -> low).

pytest tests/agent/transports/test_codex_transport.py -v29 passed.

Live verification

Real call to https://api.x.ai/v1/responses with the patched payload + a single dummy echo tool:

response.id      = 11a97f68-e8c9-92ae-8f45-0ec5403d14f7
response.model   = grok-4.3
output[0].type   = reasoning
output[1].type   = function_call
reasoning_tokens = 153    ← effort=low effectively activated

Without the patch, the equivalent request produces no reasoning output item and reasoning_tokens=0.

Tangential note

While building the live test, I confirmed that xAI rejects requests with tool_choice set but tools=[] (HTTP 400 "A tool_choice was set on the request but no tools were specified") — exact symptom of #20606 (still open). Independent of this PR but worth flagging.

The is_xai_responses branch only sent include=[reasoning.encrypted_content]
without forwarding the resolved reasoning_effort. Other Responses providers
(OpenAI, GitHub) already get effort forwarded — this aligns the xAI path.

Without this, agent.reasoning_effort is silently dropped on the xAI direct
path, making Hermes unable to control reasoning depth on grok-4.x via
api.x.ai. Tests added to TestCodexBuildKwargs cover effort passthrough,
disabled state, and minimal-clamp parity with non-xAI.
@teknium1

teknium1 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #22807 — your commit was rebased onto current main with your authorship preserved in git log. Thanks for the live verification on grok-4.3 (reasoning_tokens=153 with effort=low confirmed the fix end-to-end) and the clean test coverage. #22807

@teknium1 teknium1 closed this May 9, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/xai xAI (Grok) labels May 9, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Superseded by #22807 (salvage merge of this PR by @teknium1). The fix is now on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/xai xAI (Grok) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants