Abstract
Real-world tasks require decisions at varying granularities, and humans excelat this by leveraging a unified cognitive representation where planning isfundamentally understood as a high-level form of action. However, current LargeLanguage Model (LLM)-based agents lack this crucial capability to operatefluidly across decision granularities. This limitation stems from existingparadigms that enforce a rigid separation between high-level planning andlow-level action, which impairs dynamic adaptability and limits generalization.We propose ReCode (Recursive Code Generation), a novel paradigm that addressesthis limitation by unifying planning and action within a single coderepresentation. In this representation, ReCode treats high-level plans asabstract placeholder functions, which the agent then recursively decomposesinto finer-grained sub-functions until reaching primitive actions. Thisrecursive approach dissolves the rigid boundary between plan and action,enabling the agent to dynamically control its decision granularity.Furthermore, the recursive structure inherently generates rich,multi-granularity training data, enabling models to learn hierarchicaldecision-making processes. Extensive experiments show ReCode significantlysurpasses advanced baselines in inference performance and demonstratesexceptional data efficiency in training, validating our core insight thatunifying planning and action through recursive code generation is a powerfuland effective approach to achieving universal granularity control. The code isavailable at https://github.com/FoundationAgents/ReCode.