Skip to content

feat(claude_code_agent): make thinking folding configurable - #5955

Merged
wedu-nvidia merged 1 commit into
NVIDIA-NeMo:mainfrom
wedu-nvidia:claude-code-fold-thinking-config
Nov 11, 2026
Merged

wedu-nvidia merged 1 commit into
NVIDIA-NeMo:mainfrom
wedu-nvidia:claude-code-fold-thinking-config

Conversation

@wedu-nvidia

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds an optional fold_thinking field to ClaudeCodeAgentConfig.

Without training-token capture, parse_stream_json folds each assistant message's thinking into the message text as <think>...</think>, and there is no config option to turn that off. When a judge grades the final message, it then reads the whole reasoning instead of the answer.

On a Kimi-K3.1 HLE run (1,000 text questions, sdg-pipelines in-harness recipe), 989/997 Claude Code final messages contained <think>. Their median length was ~22K characters, against ~650 for the Pi, Codex, Hermes and OpenClaw harnesses on the same questions. About 50 rollouts per Claude variant came back with no judge verdict. The raw backend responses were clean (reasoning and content separate), so the folding is the only source of the difference.

  • fold_thinking: null (default): unchanged. Thinking is folded unless training-token capture is on.
  • fold_thinking: false: returns the capture-style transcript without capture. Thinking comes back as separate reasoning items, so the final message holds only the answer.
  • fold_thinking: true together with capture raises ValueError, since capture needs unfolded output.

No issue is linked: this is a small opt-in config field with no change to the default behavior.

Validation

  • pytest responses_api_agents/claude_code_agent/tests from the repo root (uv 0.13.7, Python 3.13): 203 passed. There are 2 new tests: a parametrized test of the config/capture matrix, and a test that true is rejected under capture.
  • pre-commit run --files on the three changed files: all hooks pass.

Rollouts

The same patch on top of Gym 7d4bcf98, with Kimi-K3.1 (max effort) in AWS OpenSandbox, 30 HLE questions per variant, fold_thinking: false:

Variant Final messages containing <think> Median final-message chars Rollouts with reasoning items
claude-code bare 0/30 (was 989/997 on the full 1,000-question run) 644 (was 23,730) 30/30
claude-code standard 0/30 (was 986/991 on the full 1,000-question run) 548 (was 21,250) 30/30

Regraded with DeepSeek-V4.1-Flash, the standard variant had 0 unjudged out of 30.

Compatibility and benchmark impact

None by default. The new field is optional and null keeps today's behavior. Configs that set fold_thinking: false get answer-only final messages, which changes what an answer-grading judge sees. The transcript is the same one capture already produces, so subagent frames are excluded and pending tool calls stay incomplete.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification. (responses_api_agents/claude_code_agent/README.md)
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass). (Run on the changed files.)
  • New source files include the required Apache-2.0 SPDX header. (No new files.)
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

Without training-token capture, parse_stream_json folds each assistant
message's thinking into its text as <think>...</think>. A judge that grades
the final message then reads the full reasoning (median ~22K chars on a
K3.1 HLE run vs ~650 for other harnesses) and often returns no verdict.

Add an optional fold_thinking config field. None keeps the current default
(folded unless capture is on); false returns the capture-style transcript
without capture (thinking as separate reasoning items); true is rejected
under capture.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Wei Du <[email protected]>
@wedu-nvidia
wedu-nvidia force-pushed the claude-code-fold-thinking-config branch from 13af6f4 to d5f76c6 Compare November 10, 2026 18:37
@wedu-nvidia
wedu-nvidia marked this pull request as ready for review November 10, 2026 18:37

@yaoyu-33 yaoyu-33 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed d5f76c6. No actionable issues found. The default behavior is preserved, and the explicit false setting consistently selects the existing unfolded transcript across local success, local timeout, and sandbox paths.

Validation: all 203 Claude Code agent tests passed, plus four focused fixture-based integration probes for explicit false without capture through local/sandbox success and timeout. Model rollout evidence is author-reported and was not independently rerun. Full repository CI remains gated on runner authorization.

@yaoyu-33 yaoyu-33 added the ready-to-merge PR is approved, current, and waiting for final CI or merge label Nov 10, 2026
@ananthsub

Copy link
Copy Markdown
Contributor

/ok to test d5f76c6

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/42948523025

Merged via the queue into NVIDIA-NeMo:main with commit 36f5500 Nov 11, 2026
68 checks passed
@wedu-nvidia
wedu-nvidia deleted the claude-code-fold-thinking-config branch November 11, 2026 03:01
gwarmstrong added a commit to gwarmstrong/Gym that referenced this pull request Nov 12, 2026
Main's OpenAI 2.45 schemas (NVIDIA-NeMo#5464) give Responses usage a cache_write_tokens
count. The Anthropic-to-Responses conversion keeps it beside this branch's
total input (uncached + cache writes + cache reads), and the reverse
conversion now reports it as cache_creation_input_tokens and leaves it out of
input_tokens, as it already did for cache reads. Main's configurable thinking
folding (NVIDIA-NeMo#5955) is kept at each parse_stream_json call with this branch's
transcript records.

Signed-off-by: gwarmstrong <[email protected]>

This branch was previously deployed

1 inactive deployment
public — d5f76c61 Deployed Nov 11, 2026 by copy-pr-bot[bot] via release / finalize / notify #11691
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge PR is approved, current, and waiting for final CI or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants