PolyU-VCLab/CodeasAgent
About
Code-as-Agent: A Meta-Agent Automatically Evolving T2I Agents as Executable Programs
Design & MediaMeasured star growth
- in 24h
- Collecting history
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original
Code-as-Agent: A Meta-Agent Automatically Evolving T2I Agents as Executable Programs
Zhengqiang Zhang1,2 | Qiaosi Yi1,2 | Lingchen Sun1,2 | Xiangtao Kong1,2 | Rongyuan Wu1,2 | Lei Zhang1,2,+
1 The Hong Kong Polytechnic University · 2 OPPO Research Institute · + Corresponding author

Figure 1. (a) Existing T2I agents are hand-crafted tool chains: humans pick the tools and their interconnections. (b) Code-as-Agent evolves the agent program itself — a meta-agent diagnoses, revises and evaluates code — and the evolved program is frozen at deployment.
TL;DR — Start from a three-line seed that only calls the image generator; a meta-agent rewrites it into a full T2I agent. The frozen program reaches the best average rank (2.00) among 12 methods across five benchmarks.
💡 Key Idea: T2I agents should be programs, not pipelines
Text-to-image agents are currently hand-built pipelines: an expert picks the tools (prompt rewriter, VLM verifier, image editor, retrieval module) and decides how they are wired. Every new capability needs a new manual design, and the resulting workflow can only express what its designer anticipated.
Code-as-Agent removes the pipeline builder. We represent the entire agent as one executable Python program with a fixed interface:
def T2IAgent(prompt: str) -> Image:
...
return img
📐 Method

Figure 2. The meta-agent evolution loop.
- Diagnosis — the current program generates images for the validation set; a VLM audits each image against a fixed 9-rule checklist (objects, counts, attributes, spatial relations, actions, part-whole relations, negation, text, visual defects) and the failures are aggregated into a report.
- Revision — one problem at a time: the meta-agent retrieves positive and negative precedents from an evolution memory and applies a single local code edit (insert / delete / replace).
- Evaluation — two gates, both must pass: targeted verification (is the reported defect fixed?) and a 2×2 paired comparison against the incumbent program, accepted iff
w > l + δ(δ = 5).
📊 Results
One evolved agent per generator (Qwen-Image-2.1, Gemini-3.1-Flash-Image), with GPT-5.6-Sol as the LLM/VLM backend, evaluated on five benchmarks.
Table 1 — Scores (higher is better; 🔴 best · 🔵 second · 🟢 third)
| Method | GenAI-Bench ↑ | TIFA ↑ | CompBench ↑ | GenEval++ ↑ | Q-Image-Bench ↑ |
|---|---|---|---|---|---|
| Direct (Qwen) | 0.7617 | 0.8373 | 0.4452 | 34.64 | 53.03 |
| Direct (Gemini) | 🔵 0.8696 | 🔵 0.8850 | 0.5443 | 78.57 | 🔵 59.91 |
| VisualPrompter | 0.7750 | 0.8614 | 0.5205 | 42.86 | 30.35 |
| T2I-Copilot | 0.8128 | 0.8681 | 0.5238 | 65.36 | 45.19 |
| Gen-Searcher | 0.7871 | 0.8567 | 0.4463 | 67.50 | 56.09 |
| OctoT2I | 0.7929 | 0.8768 | 🔵 0.5725 | 52.14 | 42.65 |
| GEMS | 0.8243 | 0.8720 | 0.5571 | 🟢 86.50 | 53.13 |
| Qwen-PE | 0.8551 | 0.8759 | 0.5519 | 72.50 | 🟢 57.84 |
| GenClaw | 🔴 0.8746 | 0.8779 | 0.5549 | 🔴 92.86 | 57.47 |
| GEPA* | 0.8103 | 0.8690 | 🔴 0.5849 | 66.43 | 43.14 |
| Ours (Qwen) | 0.8580 | 🟢 0.8803 | 0.5525 | 75.71 | 54.81 |
| Ours (Gemini) | 🟢 0.8646 | 🔴 0.8863 | 🟢 0.5576 | 🔵 87.14 | 🔴 60.03 |
Table 2 — Ranks (lower is better; same marks; bold = best per column; CompBench = T2I-CompBench, Q-Image-Bench = Qwen-Image-Bench)
| Method | GenAI-Bench ↓ | TIFA ↓ | CompBench ↓ | GenEval++ ↓ | Q-Image-Bench ↓ | Avg. Rank ↓ |
|---|---|---|---|---|---|---|
| Direct (Qwen) | 12 | 12 | 12 | 12 | 8 | 11.20 |
| Direct (Gemini) | 🔵 2 | 🔵 2 | 8 | 4 | 🔵 2 | 🟢 3.60 |
| VisualPrompter | 11 | 10 | 10 | 11 | 12 | 10.80 |
| T2I-Copilot | 7 | 9 | 9 | 9 | 9 | 8.60 |
| Gen-Searcher | 10 | 11 | 11 | 7 | 5 | 8.80 |
| OctoT2I | 9 | 5 | 🔵 2 | 10 | 11 | 7.40 |
| GEMS | 6 | 7 | 4 | 🟢 3 | 7 | 5.40 |
| Qwen-PE | 5 | 6 | 7 | 6 | 🟢 3 | 5.40 |
| GenClaw | 🔴 1 | 4 | 5 | 🔴 1 | 4 | 🔵 3.00 |
| GEPA* | 8 | 8 | 🔴 1 | 8 | 10 | 7.00 |
| Ours (Qwen) | 4 | 🟢 3 | 6 | 5 | 6 | 4.80 |
| Ours (Gemini) | 🟢 3 | 🔴 1 | 🟢 3 | 🔵 2 | 🔴 1 | 🔴 2.00 |
*GEPA is a general-purpose evolutionary agent framework, applied here to refine text-to-image prompts. Average rank is taken over the per-benchmark ranks of all 12 methods.
Ours (Gemini) has the best average rank (2.00) and is the only method to reach the top 3 on all five benchmarks, whereas every hand-crafted agent wins at most two columns and falls back to 4th–5th elsewhere. With the generator held fixed, evolution improves Qwen-Image-2.1 on all five benchmarks (average rank 11.20 → 4.80), the largest gain being GenEval++ 34.64 → 75.71.

Figure 3. Images generated by the evolved Gemini agent.
📝 Citation
Paper: arXiv:2612.03558 — https://arxiv.org/abs/2612.03558
@article{code_as_agent_2026,
title = {Code-as-Agent: A Meta-Agent Automatically Evolving T2I Agents as Executable Programs},
author = {Zhang, Zhengqiang and Yi, Qiaosi and Sun, Lingchen and
Kong, Xiangtao and Wu, Rongyuan and Zhang, Lei},
journal = {arXiv preprint arXiv:2612.03558},
year = {2026}
}
⚖️ License
Released under the Apache License 2.0 — the LICENSE file is added together with the code. Benchmarks and generators used in this work keep their own licenses; please follow them when reproducing the numbers above.
Explore related projects
Loading…