Abstract
While generative AI has made significant strides in photorealistic image synthesis, creating structured, logically coherent visuals like flowcharts and architecture diagrams remains a persistent challenge. Standard text-to-image models often produce "visual soup"—nonsensical shapes and gibberish text—while text-to-code models struggle with complex hierarchical layouts. This paper introduces DiagramAgent, a multi-agent framework that treats diagramming as a software engineering task. By utilizing specialized agents for planning, coding, and quality assurance, DiagramAgent generates precise, editable, and logically sound diagrams. To evaluate this approach, the authors present DiagramGenBenchmark, a comprehensive dataset for text-to-diagram generation and editing. Experimental results demonstrate that DiagramAgent significantly outperforms general-purpose models like GPT-4o, achieving superior logical precision and post-generation modifiability.
Introduction: The Challenge of Structured Visuals
Modern AI models like DALL-E 3 or Midjourney excel at artistic imagery but fail when tasked with structured visuals. A request for a technical flowchart often results in a visually plausible but logically incoherent mess. Conversely, text-to-code models can generate simple charts but falter when faced with the intricate spatial relationships and aesthetic requirements of technical diagrams. Furthermore, static images generated by these models are nearly impossible to edit without full regeneration.
This research addresses the dual challenge of logical precision and post-generation modifiability by shifting the paradigm from pixel generation to code-based structural definition.
The DiagramAgent Framework
DiagramAgent is an agentic framework that conceptualizes diagramming as a software development lifecycle. It employs four specialized agents to ensure accuracy and editability:
- Plan Agent: Interprets user prompts and performs "Query Expansion" to clarify vague instructions, ensuring all necessary nodes and labels are identified.
- Code Agent: Translates the plan into vector-based code using languages like LaTeX/TikZ or DOT (Graphviz).
- Check Agent: Acts as a quality assurance tester by attempting to compile the code, debugging errors, and using a vision-language model (GPT-4o) to verify the visual output against the original request.
- Diagram-to-Code Agent: Enables editing by reverse-engineering existing diagram images back into code, allowing for surgical modifications without losing the original structure.
Benchmarking with DiagramGenBenchmark
To rigorously evaluate performance, the authors introduced DiagramGenBenchmark, the first comprehensive dataset of its kind. It spans eight categories, including flowcharts, mind maps, and architecture diagrams, comprising nearly 7,000 samples for generation and 1,600 for editing. Data was meticulously cleaned and aggregated from sources like GitHub, Overleaf, and HuggingFace.
Key Results and Insights
DiagramAgent demonstrates state-of-the-art performance across multiple metrics:
- Generation Accuracy: It achieved a Pass@1 score of 58.15, outperforming GPT-4o (49.81).
- Editing Precision: In the editing task, the framework reached a near-perfect 98.00 Pass@1 score, proving the efficacy of the code-based modification approach.
- Structural Coherence: A CodeBLEU score of 86.83 indicates that the generated code closely mirrors the logical structure of ground-truth diagrams.
A critical finding of the study is the "Compiler-in-the-Loop" effect: by including a Check Agent that debugs compilation errors, the system significantly reduces hallucinations. Furthermore, the results show that a specialized 7B parameter model (like Qwen2-7B) within this agentic framework can outperform much larger general-purpose models.
Conclusion and Future Work
DiagramAgent represents a significant step forward in automated technical visualization. By bridging the gap between natural language and structured code, it provides a robust solution for generating and editing complex diagrams. While challenges remain in handling extremely dense spatial layouts and 3D architectures, the framework's ability to maintain logical integrity through code-based editing sets a new standard for the field. Future work will focus on improving spatial placement and enabling the system to digitize hand-drawn sketches into professional diagrams.
Summary updated