Intention Chain-of-Thought Prompting with Dynamic Routing for Code Generation

Shen Li, Li Huang, Shaoxiong Zhan, Weifeng Sun, Tao Yin, Zhongxin Liu, Meng Yan

TL;DR

RoutingGen is a new framework for code generation that prevents Large Language Models (LLMs) from "overthinking" simple tasks while providing a structured "Intention Chain-of-Thought" (ICoT) for complex ones. By dynamically routing queries based on difficulty, it achieves state-of-the-art performance while slashing token usage by an average of 46.37%.

What Problem Does This Paper Address?

Chain-of-Thought (CoT) prompting—asking a model to "think step-by-step"—has revolutionized LLM reasoning. However, the authors identify two critical flaws when applying CoT to code generation:

  1. The Overthinking Trap: Current methods apply structured reasoning uniformly. For simple tasks (e.g., "reverse a string"), forcing a model through a complex reasoning chain often leads to disorganized logic, unnecessary verbosity, and even reduced accuracy.
  2. Lack of Intention Abstraction: Existing code-centric CoT methods (like Program-of-Thought) focus on surface-level procedural steps. They often fail to explicitly model the high-level intention—the core algorithmic design and time complexity—leading to code that might be syntactically correct but functionally inefficient or misaligned with the global objective.

Inspired by the "cognitive economy" principle (engaging deliberate reasoning only when necessary), the researchers sought a way to make LLMs more adaptive and "intent-aware."

Methods

The authors introduce RoutingGen, a framework consisting of two main components:

1. Difficulty-Aware Dynamic Routing

Instead of treating every prompt the same, RoutingGen uses a classifier (in this study, Qwen3-8B) to categorize an incoming coding problem as either Simple or Complex.

  • Simple Path: The model generates code directly via few-shot prompting, bypassing expensive reasoning steps.
  • Complex Path: The model is routed to the ICoT strategy.

2. Intention Chain-of-Thought (ICoT)

For complex problems, the authors propose a two-stage reasoning process:

  • Stage 1 (ICoT Generation): The model generates a Specification (defining input-output constraints) and an Idea (capturing the core algorithmic logic and estimating time complexity). This abstracts the "intent" before a single line of code is written.
  • Stage 2 (Code Generation): The model generates the final code, conditioned on both the original prompt and the ICoT generated in Stage 1.

Datasets

The framework was evaluated across three models (Qwen2.5-Coder-3B, DeepSeek-Coder-6.7B, and DeepSeek-V3) using six diverse benchmarks:

  • HumanEval & MBPP-sanitized: The industry standards for Python code generation.
  • HumanEval-ET & MBPP-ET: Extended versions of the above that include ~100 edge-case tests per problem to check for robustness.
  • OpenEval: A collection of 178 challenging problems with manually written test cases.
  • McEval: A multilingual benchmark (the authors focused on the Python subset).

Key Insights and Ideas

  • System 1 vs. System 2 for AI: The paper mirrors human dual-process theory. Simple tasks use "System 1" (fast, intuitive), while complex tasks trigger "System 2" (deliberate, structured). This prevents the "disorganized logic" seen when models try to over-explain simple solutions.
  • Efficiency as an Explicit Goal: By including "time complexity" in the ICoT "Idea" stage, the model is forced to consider performance before implementation. This steers the model toward concise, optimal solutions rather than just "working" code.
  • The Cost-Benefit Sweet Spot: The authors found that for simple tasks, structured prompting actually hurts performance. RoutingGen acts as a filter that ensures the "heavy lifting" of CoT is only used when it provides a net positive to accuracy.

Key Results

  • State-of-the-Art Performance: ICoT consistently outperformed six existing prompting baselines (like Self-CoT and SCoT) on challenging benchmarks.
  • Massive Efficiency Gains: RoutingGen reduced total token usage by 46.37% on average across all settings. In some cases, like MBPP-sanitized with DeepSeek-Coder-6.7B, token usage dropped by nearly 60% while accuracy actually improved.
  • Robustness: The routing mechanism proved robust even when the difficulty classifier was swapped (e.g., comparing Qwen3-8B to GPT-4o). Both classifiers agreed on difficulty for the vast majority of tasks.
  • Ablation Success: Removing either the "Specification" or the "Idea" stage from ICoT led to significant drops in Pass@1 accuracy, proving that both high-level constraints and algorithmic planning are necessary for complex code.

Limitations and Future Work

  • Classifier Dependency: While the system is robust, it still relies on an initial classification step. If the classifier mislabels a complex task as simple, the model loses the benefit of ICoT.
  • Fixed Routing: The current routing is binary (Simple vs. Complex). Future work could explore more granular routing (e.g., routing to specific algorithmic templates like Dynamic Programming or Graph Theory).
  • Language Scope: While tested on Python, the authors suggest that extending the "Intention" abstraction to more diverse programming paradigms (like functional or low-level languages) remains an open area for exploration.

Summary updated

BibTeX
@inproceedings{li2026intention,
  author = {Shen Li and Li Huang and Shaoxiong Zhan and Weifeng Sun and Tao Yin and Zhongxin Liu and Meng Yan},
  title = {{Intention Chain-of-Thought Prompting with Dynamic Routing for Code Generation}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  doi = {10.1609/aaai.v40i1.37030},
}
Figure