SEMAG Picks Its Own AI Model and Hits 52.6% on Coding
A new multi-agent framework decomposes coding tasks into planning, coding, debugging, and debate stages, then auto-selects the best backbone LLM.
ProTakeaways
- SEMAG hits 52.6% Pass@1 on CodeContests after auto-selecting Claude-3.7-Sonnet as backbone.
- Four-level hierarchy scales from direct generation to multi-agent debate based on task difficulty.
- Adaptive level transitions use normalized edit distance on execution traces to detect debugging stalls.
- Self-evolution agents crawl the web to find and vote on the best backbone LLM automatically.
- Cuts token usage 15-19% on easy tasks while improving accuracy over LPW baseline.
- Full prompts for all 13 agents included in appendix; no public code release yet.
A team from Shenzhen University and Carleton University has released SEMAG, a multi-agent code generation framework that does two things most prior systems don't: it scales its reasoning depth to the difficulty of the task, and it can go shop for its own backbone model on the internet. On the hardest public coding benchmark, CodeContests, it reaches 52.6% Pass@1 after auto-selecting Claude-3.7-Sonnet, up from 38.0% with a fixed GPT-4o backbone.
Why fixed workflows fall over
Most agentic coding systems, from Self-Debugging to LDB to LPW, run the same pipeline regardless of whether they are being asked to reverse a string or solve an ICPC problem. Current methods rely on manual model selection and fixed workflows, which limit their ability to adapt to changing task complexities. The authors identify three concrete failure modes in existing systems: fixed reasoning depth wastes tokens on easy tasks and undershoots on hard ones, a single debugging pass tends to get stuck in local minima, and everything is hard-coded to one backbone model that has to be swapped by hand when something better comes out.
A four-level hierarchy that grows with the problem
SEMAG's core idea is to escalate compute only when the task demands it. It runs through progressively more expensive levels until tests pass:
- Direct generation. One shot at the code with minimal prompting.
- Plan and verify. A Planning Agent produces a structured plan, and a Plan Verifying Agent simulates it step by step against the I/O examples, refining until it verifies.
- Trace-guided debugging. On failure, an Embedding Trace agent inserts print statements to capture runtime variable states, an Explainer describes the code, and a Suggestor synthesizes targeted fixes for a Debugger.
- Multi-agent debate. If debugging stalls, several Debater agents propose alternative algorithms and a Discriminator picks a winner via weighted consensus.
Transitions between levels are governed by an adaptive threshold that compares consecutive execution traces using normalized edit distance. If two debug iterations produce nearly identical traces, the system concludes it's stuck and escalates rather than burning more iterations.
Agents that pick their own model
The self-evolution component is the most unusual piece. Instead of hard-coding a backbone, SEMAG spawns parallel Model Selector agents that generate search queries, crawl the web for recent LLM release notes and benchmark posts, summarize what they find, and vote on candidate models. SEMAG adapts a multi-agent code-generation workflow by coordinating planning, coding, debugging, and discussion according to task difficulty, while also allowing model selection to evolve with the available coding backbones.

An ablation on crawl depth shows the tradeoff clearly: pulling 10 links only identifies the current SOTA (Claude-3.7-Sonnet) 40% of the time, while 20 links hits 80% at roughly 46k tokens and 6 minutes of latency per selection. Going beyond 20 pages inflates cost 30 to 55% for no accuracy gain.
The numbers
SEMAG was evaluated on seven benchmarks: HumanEval, MBPP, their ET (edge-test) variants, plus the competition-level APPS, LiveCodeBench, and CodeContests. Using GPT-4o with a fixed backbone, it beats the prior best system LPW by 1.8 to 6.0 points on foundational benchmarks and 3.3 to 5.7 points on competition benchmarks.
| Benchmark | LPW (GPT-4o) | SEMAG (GPT-4o) | SEMAG + auto-select |
|---|---|---|---|
| HumanEval | 98.2% | 98.8% | - |
| MBPP | 84.8% | 87.6% | - |
| LiveCode | 59.3% | 65.0% | - |
| APPS | 62.6% | 67.6% | - |
| CodeContests | 34.7% | 38.0% | 52.6% (Claude-3.7) |
The hierarchical routing also cuts cost: SEMAG uses 19.3% fewer tokens than LPW on HumanEval and 15.5% fewer on MBPP because most simple problems exit at Level 1. On HumanEval with GPT-4o, 148 of 164 problems never leave Level 1. Ablations confirm that plan verification, refinement suggestion, and the discussion-decision module are all necessary; removing any single component drops Pass@1 by 8 to 15 points.
Where it breaks down
The framework isn't uniformly better. On the APPS Competition tier, SEMAG scores 32.6% versus LPW's 34.8%, which the authors attribute to hierarchical prompting sometimes passing visible tests while failing hidden ones. The self-evolution module also depends on public search results, so biased or thin coverage of a new model can lead to suboptimal picks. And the iterative refinement adds latency, making SEMAG a poor fit for interactive IDE-style completion; it's built for problems where correctness matters more than milliseconds.
What's actually new here
Agent frameworks like SEW and EvoMAC have explored evolving workflows and prompts, but SEMAG is one of the first to fold the choice of backbone model itself into the agent loop. That matters because coding benchmarks are increasingly bottlenecked by model capability, not orchestration cleverness, and a framework that can absorb the next SOTA model automatically has a much longer shelf life. The paper does not appear to have released code publicly yet, though the appendix includes full prompts for all thirteen agents, which is enough to reproduce the system if you're willing to wire it up yourself.