🤖 AI Summary
This work identifies an “in-context compositional hardness” in large language models (LLMs) when solving multi-step combinatorial coding tasks within a single context: solution-generation complexity grows exponentially with output length, causing a sharp decline in first-attempt correctness for long code sequences. We formally define and theoretically prove this exponential gap. To quantify the phenomenon, we propose a metric grounded in probabilistic modeling and theoretical complexity analysis. Through systematic experiments—including LLM sampling, chain-of-thought reasoning, and multi-agent task decomposition—we demonstrate that distributed multi-agent solving reduces generation complexity by one to two orders of magnitude, significantly improving accuracy and robustness in long-code generation. Our core contributions are (1) establishing the first quantifiable theoretical framework for compositional difficulty in LLM code generation, and (2) empirically validating that multi-agent architectures fundamentally alleviate the inherent bottlenecks of monolithic LLMs in combinatorial programming tasks.
📝 Abstract
A common practice in large language model (LLM) usage for complex analytical tasks such as code generation, is to sample a solution for the entire task within the model's context window. Previous works have shown that subtask decomposition within the model's context (chain of thought), is beneficial for solving such tasks. In this work, we point a limitation of LLMs' ability to perform several sub-tasks within the same context window - an in-context hardness of composition, pointing to an advantage for distributing a decomposed problem in a multi-agent system of LLMs. The hardness of composition is quantified by a generation complexity metric, i.e., the number of LLM generations required to sample at least one correct solution. We find a gap between the generation complexity of solving a compositional problem within the same context relative to distributing it among multiple agents, that increases exponentially with the solution's length. We prove our results theoretically and demonstrate them empirically.