Towards Fully Automated Medical Imaging Code Generation via Validation-based Context Engineering
Authors: Zixiao Zhao, Jing Sun, Zhe Hou, Cheng-Hao Cai, Qian Liu, Mengze Li, Zijian Zhang, Jin Song Dong
Organizations: University of Auckland Auckland, New Zealand · Griffith University Brisbane, Australia · Suzhou Industrial Park Monash Research Institute of Science and Technology Suzhou, China · Beijing Institute of Technology Beijing, China · National University of Singapore Singapore, Singapore
Large language models (LLMs) have demonstrated considerable promise in program generation for small-scale and conventional application development; however, they remain limited when applied to complex, domain-specific tasks such as medical image processing. General-purpose models lack explicit domain knowledge and robust validation mechanisms to ensure correctness, often requiring substantial human intervention to produce reliable processing pipelines. To address these limitations, we propose AutoMedImg, a multi-agent framework for fully automated medical image processing code generation. AutoMedImg orchestrates specialised agents across two phases: a Planning Phase that performs dataset analysis and architecture design with semantic and formal verification, and a Coding Phase that generates modules in parallel with static checking, execution testing, and assembly validation. This multi-stage validation mitigates error propagation throughout generation, while comprehensive auto-context engineering combining domain-specific knowledge bases, shared memory, and validation feedback automates context construction without manual prompting. A cross-project adaptive pipeline synthesis mechanism further accumulates validated pipelines and retrieves proven components for new tasks based on project similarity, enhancing generation efficiency through cross-project learning. Extensive evaluation across six diverse and well-established medical imaging datasets with five backbone LLMs demonstrates that AutoMedImg achieves zero human intervention, with Dice scores of up to 0.90 for segmentation tasks and 99% accuracy for classification.
Figures & tables
Figure 1. AutoMedImg’s two-phase workflow: Planning and Coding vace workflow
Figure 4. Performance of Code Generation Tools and Base LLMs on Medical Image Processing Tasks Performance of Code Generation Tools and Base LLMs on Medical Image Processing Tasks
FLARE22
ACDC
BTCV
FLARE21
Promise12
OrganMNIST
Method
HI↓
Dice↑
HI↓
Dice↑
HI↓
Dice↑
HI↓
Dice↑
HI↓
Dice↑
HI↓
Acc↑
Multi-agent frameworks
CAMEL with GPT5.2 ( Li et al., 2023 )
6
0.6523
7
0.7234
9
0.6312
6
0.7018
6
0.8456
5
0.8923
MetaGPT X ( Hong et al., 2023 )
4
0.7132
3
0.7750
3
0.6845
4
0.7534
3
0.8821
3
0.9125
MaCTG ( Zhao et al., 2024 )
3
0.5104
4
0.6273
2
0.5205
3
0.8414
2
0.8719
1
0.8820
AutoML frameworks
Table 1. Comparison of AutoMedImg Against Multi-agent and AutoML Frameworks on Medical Image Processing Tasks
Method
Preprocessing
Augmentation
Model
GPU
Time
Multi-agent frameworks
CAMEL-GPT-5.2
Res., Norm.
Rot., Flip
UNet3D
8.9
146
MetaGPT X
Ori., Res., Norm.
Patch, Rot., Flip, Int.
UNet3D+RN
6.0
257
MaCTG
Ori., Res., Norm.
Rot., Noise, Flip, Int., Smooth
UNet3D
25.5
203
AutoML frameworks
AutoML-Agent
Ori., Res., Norm.
Patch
UNet3D
14.4
106
Table 2. Detailed Method Comparison on BTCV Dataset (Supervised 3D Segmentation)
Figure 5. Ablation Study: Average Impact of Component Removal on AutoMedImg with Claude-4.5-Opus
Method
Complete Pipeline
Task Specific Design
Multi-task Support
Cross-project Reference
Multi-stage Validation
Production-ready Implementation
Fully Automated
NAS ( Wang et al., 2024 )
✗ (NN only)
✗ (Depend on search space)
✓
✗
✗
✗
✗ (Predefined search space needed)
nnU-Net ( Isensee et al., 2021 )
✓
✓
✗ (Seg. only)
✗
✗
✓
✗ (Manual setup needed)
MedSAM ( Ma et al., 2024a )
✗ (Inference only)
✗ (Fixed pre-trained model)
✗ (Seg. only)
✗
✗
✓
✗ (Interactive inference)
AutoMedImg
✓
✓
✓
✓
✓
✓
✓
Table 3. Comparison of AutoMedImg with Automated Medical Imaging Methods