This invention relates to the technical field of
programming task
code generation methods based on multi-agent
collaboration and iterative reasoning. Specifically, it discloses a method for generating
programming task code based on multi-agent
collaboration and iterative reasoning, comprising: obtaining a task description with a primary-secondary
functional dependency structure; generating initial code by a generating agent based on a dependency-guided thought chain and performing
static structure verification; collecting runtime execution trajectories in an isolated sandbox through dynamic agents; having a
diagnostic agent attribute errors to the trajectories, distinguishing between inter-function
collaboration errors and intra-function logic errors, and generating structured repair guidance; and combining historical
perception feedback and a controlled reset mechanism to guide subsequent iterative repairs and avoid local optima. This invention solves the problems of ambiguous
error location, easy code degradation, and low repair efficiency in existing
code generation methods for multi-
functional dependency tasks, achieving accurate error attribution, preventing code
rollback, and improving generation success rate and repair convergence efficiency.