Skip to content

Steering Large Language Models between Code Execution and Textual Reasoning

🕒 Published (v1): 2025-01-01 · Source: ICLR · Venue: ICLR 2025 · link

Ask a follow-up

Open an assistant pre-loaded with this paper's context.

💬 Ask ChatGPT✦ Ask Claude

TL;DR

This paper investigates how LLMs decide between code generation/execution and textual reasoning across 14 tasks and 6 models, finding that no single existing method optimally steers this choice. The authors identify an inverse scaling phenomenon (smaller models sometimes outperform larger ones due to more conservative code usage) and propose three steering methods, of which a multi-agent code+text ensemble achieves the highest average normalized score.

Problem

Current LLMs—including those with built-in Code Interpreters (CI)—lack reliable mechanisms to decide when to solve a task via code vs. natural-language reasoning. Medium-difficulty tasks expose a systematic failure: models are overconfident in textual reasoning and skip code even when coding would guarantee correctness. No prior method generalizes across task types, model families, and complexity levels.

Method

The authors benchmark 7 existing steering strategies (pure-text prompt, pure-code prompt, All Code + CoT, AutoGen concatenated/system-prompt variants, and GPT CI) against 14 tasks spanning math, logic, robot planning, and symbolic calculation. They then propose three new methods:

  1. Code Interpreter+: augments GPT CI with an additional coding-encouragement prompt.
  2. Code + Text + Sum.: a three-agent pipeline—one agent answers in All-Text mode, one in All-Code mode, and a third summarizer agent merges both outputs into a final answer.
  3. Self-estimate Score: the model first self-rates its confidence in solving via code vs. text, then executes the higher-scoring modality.

Multi-turn refinement is also evaluated: after code execution the result is fed back to the LLM for self-reflection up to a maximum iteration count, terminating on a "Terminate" signal.

Key Contributions

  • Comprehensive empirical audit of 7 existing code/text steering methods across 6 LLMs and 14 tasks.
  • Discovery that forcing LLMs to always use code can be worse than pure text because LLMs generate "text-like code" (no actual execution benefit) or code that fails on multi-component planning tasks.
  • Identification of an inverse scaling behavior: GPT-3.5 and GPT-4o-mini with CI outperform GPT-4o with CI on computation-heavy tasks because smaller models are more conservative and use code earlier.
  • Three proposed steering methods; Code+Text+Sum. achieves the best Average Normalized Score and rank across all 6 models.
  • Detailed token-length and runtime cost analysis for all 10 methods.
  • CodeSteer dataset and codebase released publicly.

Results

  • Average Normalized Score (across 14 tasks, 6 models — higher is better):
  • Code + Text + Sum. (proposed): 79.5 avg, rank 2.50 (best overall)
  • All Code (baseline): 77.2, rank 3.33
  • Code Interpreter (baseline): 76.3, rank 6.33
  • All Text (baseline): 73.9, rank 5.50
  • Self-estimate Score (proposed): 69.4, rank 6.50
  • On GPT-4o: Code+Text+Sum. achieves 88.1 vs. best baseline of 84.5 (AutoGen Conca.).
  • On GPT-4o-mini: Code+Text+Sum. achieves 85.0 vs. best baseline of 80.8 (CI).
  • On O1-preview: pure All Code reaches 93.3; Code+Text+Sum. gives 90.2 (O1 already excels at code so ensemble adds little).
  • Inverse scaling: GPT-3.5 and GPT-4o-mini with CI achieve 100% on Number Multiplying across all complexities; GPT-4o fails on medium complexity.
  • Multi-turn refinement converges at turn 2; improves code-heavy methods for GPT-4o/4o-mini but degrades text-heavy and all methods for GPT-3.5.

Limitations

  • Proposed methods (CI+, Code+Text+Sum.) depend on CI availability—Claude-sonnet and Mixtral-8x7b cannot use them, reducing their generality.
  • Code+Text+Sum. and multi-turn refinement substantially increase token costs and runtime; no lightweight solution is proposed for cost-sensitive settings.
  • Self-estimate Score underperforms on average, particularly for weaker models (Mixtral-8x7b: 49.0).
  • All tasks are Python-solvable by design; findings may not generalize to tasks where coding is fundamentally insufficient.
  • Multi-turn refinement degrades performance for GPT-3.5, indicating a capability floor below which self-reflection is harmful.
  • The summarizer agent in Code+Text+Sum. inherits the same LLM's weaknesses, limiting gains when the base model lacks reasoning discrimination.

Relevance to Harnesses / Meta-Harnesses

The Code + Text + Sum. method is itself a three-node meta-harness: two specialized worker agents (code solver, text solver) feed a synthesizer agent, a canonical orchestration pattern directly relevant to harness design. The multi-turn refinement loop—where code execution output is piped back as feedback—exemplifies a harness feedback loop and demonstrates that such loops must be gated on model capability or they degrade performance. The paper's taxonomy of steering strategies (prompt injection, system-prompt wrapping, CI delegation, multi-agent assembly) maps directly onto design choices one must make when building a meta-harness that dynamically routes subtasks to code or language backends. The inverse scaling result is a practical warning for harness builders: routing decisions based on model tier can backfire if larger models are systematically overconfident.