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 · DOI

Chain-of-Thought (CoT) prompting has become the gold standard for coaxing better reasoning out of Large Language Models (LLMs). However, in the world of code generation, more reasoning isn't always better. Sometimes, it leads to "overthinking" simple tasks or missing the high-level algorithmic goal on complex ones.

A new framework titled RoutingGen introduces a dynamic approach that knows when to think deep and when to just write the code. By pairing a difficulty-aware router with a novel "Intention" reasoning strategy, RoutingGen achieves state-of-the-art performance while cutting token costs nearly in half.

The Problem: Overthinking and Logic-Blindness

Existing code-centric prompting methods (like SCoT or Self-Planning) suffer from two main pathologies:

  1. The Overthinking Trap: When a powerful model is asked to "think step-by-step" for a trivial task (e.g., checking if a number is divisible by 11), it often generates unnecessarily complex logic that increases the chance of a bug. This is a waste of both compute and accuracy.
  2. Lack of Intention Abstraction: Standard CoT often focuses on the structure of the code (loops, variables, syntax) rather than the algorithmic intent. Models might produce syntactically perfect code that misses the global objective or ignores time complexity requirements.
Comparison of standard CoT vs. RoutingGen highlighting overthinking and lack of intention abstraction.

RoutingGen argues that LLMs should follow the human principle of cognitive economy: use "System 1" (intuitive, fast) for easy tasks and "System 2" (deliberate, structured) only when the problem is complex.

Methodology: Difficulty-Aware Dynamic Routing

RoutingGen consists of two main components designed to balance efficiency and reasoning depth.

The RoutingGen architecture: from question input to difficulty-aware dynamic routing and ICoT-guided generation.

1. Difficulty-Aware Dynamic Routing

Before generating any code, a classifier (such as Qwen3-8B) analyzes the prompt and labels it as Simple or Complex.

  • Simple tasks are sent to a Direct Generation path (few-shot prompting). This prevents the model from wandering into "hallucinated" complex logic for easy problems.
  • Complex tasks are sent to the ICoT-Guided path.

2. Intention Chain-of-Thought (ICoT)

For complex problems, the model generates an Intention consisting of:

  • Specification: A concise definition of input-output constraints.
  • Idea: A high-level abstraction of the core algorithmic logic and an explicit estimate of time complexity (e.g., $O(n \log n)$).

This "Intention" acts as a blueprint, forcing the model to commit to a logic strategy and efficiency target before it ever touches a line of syntax.

Experimental Results

The researchers evaluated RoutingGen across three models (Qwen2.5-Coder, DeepSeek-Coder, and DeepSeek-V3) using six major benchmarks, including HumanEval, MBPP, and LiveCodeBench.

  • State-of-the-Art Performance: RoutingGen achieved the highest Pass@1 scores in most settings. For example, using DeepSeek-V3, it reached 91.83% on HumanEval and 65.20% on McEval.
  • Massive Token Savings: On average, RoutingGen reduced total token usage by 46.37% compared to uniform structured prompting. On the MBPP-sanitized benchmark, the reduction was as high as 59.22%.
  • Big-O as a Guardrail: By requiring the model to state the time complexity in the "Idea" phase, the ICoT strategy steers the model away from "brute-force" solutions that might pass basic tests but fail on scale or efficiency.

Conclusion

RoutingGen demonstrates that "thinking harder" is not a universal solution for code generation. By intelligently routing tasks based on difficulty and focusing on algorithmic intent for complex problems, the framework achieves a superior balance of accuracy and computational efficiency. Future work aims to extend this to repository-level code generation and adaptive routing mechanisms.

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