# dwzhu-pku/paperbanana architecture

> Architecture diagram of the GitHub repository dwzhu-pku/paperbanana, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dwzhu-pku/paperbanana
- Repository: https://github.com/dwzhu-pku/paperbanana

## Overview

1. **What this repo is**
   PaperBanana is an academic illustration generation system for two task families: **diagrams** and **plots**. Its core architecture is a **multi-agent pipeline** that turns paper text and captions into generated figures, optionally using reference examples from a benchmark dataset.

2. **Main entrypoints**
   The repository has three primary execution paths:
   - **`main.py`**: command-line batch execution and evaluation
   - **`app.py`**: a Gradio-based interactive app
   - **`demo.py`**: a Streamlit demo for candidate generation and image refinement  
   Additional Streamlit tools live under **`visualize/`** for inspecting pipeline evolution and evaluation results.

3. **Core orchestration layer**
   The real system behavior is in **`agents/`**, which encodes the pipeline as modular roles:
   - **Retriever Agent**: selects relevant reference figures
   - **Planner Agent**: expands source text into a structured figure plan
   - **Stylist Agent**: rewrites the plan to match publication-style conventions
   - **Visualizer Agent**: calls image generation models to render candidates
   - **Critic Agent**: evaluates outputs and drives iterative refinement
   - **Vanilla Agent**: direct generation baseline
   - **Polish Agent**: post-processing/refinement path

4. **Pipeline structure and control flow**
   The architecture is centered on a **reference-driven generation loop**:
   - Input: method text, caption, task type, and optional retrieval examples
   - Optional retrieval: choose similar references from the benchmark
   - Planning: convert content into a figure-specification
   - Styling: adapt the spec to academic design norms
   - Visual synthesis: generate one or more candidate images
   - Critique/refinement: compare candidate against goals and iterate  
   The README exposes several modes, from **vanilla** to **full pipeline** with critic rounds, which suggests the pipeline is designed as composable stages rather than a monolith.

5. **Data and knowledge sources**
   The system depends on a benchmark dataset stored under **`data/PaperBananaBench/`** when available. This dataset provides:
   - task instances for diagram and plot generation
   - reference images and metadata for retrieval
   - evaluation targets / held-out splits  
   The repo is designed to degrade gracefully without the dataset by skipping the few-shot retrieval path.

6. **Configuration and model routing**
   Configuration is externalized in **`configs/model_config.yaml`** created from the template. This file controls:
   - the main multimodal model used for reasoning/planning
   - the image generation model
   - API keys for providers such as **Google Gemini** or **OpenRouter**  
   This makes model selection a first-class architectural boundary: reasoning and image synthesis can be swapped independently.

7. **Prompting and style guidance**
   The **`prompts/`** and **`style_guides/`** directories hold the reusable textual assets that shape agent behavior:
   - task-specific evaluation prompts for diagrams and plots
   - automatically synthesized style guides
   - category/style reference materials  
   These are not code paths but are part of the control surface of the system, especially for the Stylist and Critic stages.

8. **Utility layer**
   Shared functionality is concentrated in **`utils/`**:
   - configuration loading
   - generation helpers and async/concurrency support
   - image manipulation and export
   - dataset/paper visualization preprocessing
   - evaluation toolkits  
   This layer acts as the glue between agent logic, model APIs, file outputs, and evaluation.

9. **Evaluation and analysis**
   The repo includes a built-in evaluation workflow, mainly for benchmarked diagram/plot outputs. Evidence of this appears in:
   - **`utils/eval_toolkits.py`**
   - **`prompts/*_eval_prompts.py`**
   - **`visualize/show_referenced_eval.py`**  
   The architecture therefore includes a closed loop: generate figures, score them against references/targets, and inspect results visually.

10. **Artifacts and outputs**
    Generated images, intermediate candidates, timelines, and batch exports appear to be stored under **`results/`** at runtime. The demo mode emphasizes producing multiple candidates and preserving evolution artifacts, which suggests the pipeline is not only generative but also **traceable** for inspection.

11. **User interface boundary**
    The repo separates the model pipeline from user interaction:
    - **Gradio app** for direct generation and API-key-driven usage
    - **Streamlit demo** for candidate grids, refinement, and downloads
    - **Visualization apps** for post hoc analysis  
    This UI layer sits on top of the same agent pipeline and does not own generation logic.

12. **Deployment and packaging**
    The repo is packaged for local Python execution with **`requirements.txt`**, a **`Dockerfile`**, shell scripts in **`scripts/`**, and static frontend assets in **`static/`** and **`assets/`**. It is also published as a **ClawHub skill** (`skill/`), which indicates an additional integration boundary for agent platforms.

13. **Overall architectural picture**
    The system is best understood as:  
    **input text + optional retrieved references → multi-agent text planning and styling → image synthesis → critique/refinement → downloadable figure outputs**, with separate presentation layers for interactive use and separate evaluation/visualization tools for benchmarking and debugging.

Main entry points: [`agents/visualizer_agent.py`](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/visualizer_agent.py) (Visualizer), [`agents/critic_agent.py`](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/critic_agent.py) (Critic), [`main.py`](https://github.com/dwzhu-pku/paperbanana/blob/main/main.py) (main.py), [`agents/base_agent.py`](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/base_agent.py) (Base Agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entrypoints["Entrypoints"]
  node_main["main.py<br/>batch runner<br/>[main.py]"]
  node_app["app.py<br/>gradio app<br/>[app.py]"]
  node_demo["demo.py<br/>streamlit demo<br/>[demo.py]"]
end

subgraph group_pipeline["Pipeline Core"]
  node_retriever["Retriever<br/>reference search<br/>[retriever_agent.py]"]
  node_planner["Planner<br/>spec planning<br/>[planner_agent.py]"]
  node_stylist["Stylist<br/>style rewrite<br/>[stylist_agent.py]"]
  node_visualizer["Visualizer<br/>image synthesis"]
  node_critic["Critic<br/>quality loop<br/>[critic_agent.py]"]
  node_vanilla["Vanilla<br/>baseline generation<br/>[vanilla_agent.py]"]
  node_polish["Polish<br/>refinement<br/>[polish_agent.py]"]
  node_base_agent["Base Agent<br/>agent base<br/>[base_agent.py]"]
end

subgraph group_support["Support Assets"]
  node_model_config["Model Config<br/>routing config"]
  node_config_utils["Config Utils<br/>config loading<br/>[config.py]"]
  node_generation_utils["Generation Utils<br/>runtime helpers"]
  node_image_utils["Image Utils<br/>image processing<br/>[image_utils.py]"]
  node_eval_toolkits["Eval Toolkits<br/>scoring<br/>[eval_toolkits.py]"]
  node_prompt_diagram["Diagram Prompts<br/>prompt assets"]
  node_prompt_plot["Plot Prompts<br/>prompt assets"]
  node_style_guides["Style Guides<br/>style assets"]
end

subgraph group_ops["Ops and Analysis"]
  node_dataset[("PaperBananaBench<br/>benchmark data")]
  node_results[("Results<br/>runtime outputs")]
  node_visualize_eval["Eval Viewer<br/>analysis ui"]
  node_visualize_pipeline["Pipeline Viewer<br/>analysis ui"]
  node_skill_run["Skill Runtime<br/>clawhub skill<br/>[run.py]"]
end

node_main -->|"batch run"| node_retriever
node_main -->|"plan"| node_planner
node_main -->|"render"| node_visualizer
node_main -->|"evaluate"| node_critic
node_app -->|"interactive flow"| node_planner
node_demo -->|"candidate gen"| node_visualizer
node_demo -->|"refine"| node_polish
node_retriever -->|"lookup"| node_dataset
node_planner -->|"handoff"| node_stylist
node_stylist -->|"spec to image"| node_visualizer
node_visualizer -->|"candidates"| node_critic
node_critic -->|"revise"| node_polish
node_vanilla -->|"direct path"| node_visualizer
node_base_agent -->|"shared base"| node_retriever
node_base_agent -->|"shared base"| node_planner
node_base_agent -->|"shared base"| node_stylist
node_base_agent -->|"shared base"| node_visualizer
node_config_utils -->|"loads"| node_model_config
node_generation_utils -->|"orchestrates"| node_visualizer
node_image_utils -->|"writes"| node_results
node_eval_toolkits -->|"scores"| node_critic
node_prompt_diagram -->|"guides"| node_critic
node_prompt_plot -->|"guides"| node_critic
node_style_guides -->|"guides"| node_stylist
node_visualize_eval -->|"inspect"| node_results
node_visualize_pipeline -->|"trace"| node_results
node_skill_run -->|"entry"| node_main

click node_main "https://github.com/dwzhu-pku/paperbanana/blob/main/main.py"
click node_app "https://github.com/dwzhu-pku/paperbanana/blob/main/app.py"
click node_demo "https://github.com/dwzhu-pku/paperbanana/blob/main/demo.py"
click node_retriever "https://github.com/dwzhu-pku/paperbanana/blob/main/agents/retriever_agent.py"
click node_planner "https://github.com/dwzhu-pku/paperbanana/blob/main/agents/planner_agent.py"
click node_stylist "https://github.com/dwzhu-pku/paperbanana/blob/main/agents/stylist_agent.py"
click node_visualizer "https://github.com/dwzhu-pku/paperbanana/blob/main/agents/visualizer_agent.py"
click node_critic "https://github.com/dwzhu-pku/paperbanana/blob/main/agents/critic_agent.py"
click node_vanilla "https://github.com/dwzhu-pku/paperbanana/blob/main/agents/vanilla_agent.py"
click node_polish "https://github.com/dwzhu-pku/paperbanana/blob/main/agents/polish_agent.py"
click node_base_agent "https://github.com/dwzhu-pku/paperbanana/blob/main/agents/base_agent.py"
click node_model_config "https://github.com/dwzhu-pku/paperbanana/blob/main/configs/model_config.template.yaml"
click node_config_utils "https://github.com/dwzhu-pku/paperbanana/blob/main/utils/config.py"
click node_generation_utils "https://github.com/dwzhu-pku/paperbanana/blob/main/utils/generation_utils.py"
click node_image_utils "https://github.com/dwzhu-pku/paperbanana/blob/main/utils/image_utils.py"
click node_eval_toolkits "https://github.com/dwzhu-pku/paperbanana/blob/main/utils/eval_toolkits.py"
click node_prompt_diagram "https://github.com/dwzhu-pku/paperbanana/blob/main/prompts/diagram_eval_prompts.py"
click node_prompt_plot "https://github.com/dwzhu-pku/paperbanana/blob/main/prompts/plot_eval_prompts.py"
click node_style_guides "https://github.com/dwzhu-pku/paperbanana/blob/main/style_guides/neurips2025_diagram_style_guide.md"
click node_visualize_eval "https://github.com/dwzhu-pku/paperbanana/blob/main/visualize/show_referenced_eval.py"
click node_visualize_pipeline "https://github.com/dwzhu-pku/paperbanana/blob/main/visualize/show_pipeline_evolution.py"
click node_skill_run "https://github.com/dwzhu-pku/paperbanana/blob/main/skill/run.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_app,node_demo toneBlue
class node_retriever,node_planner,node_stylist,node_visualizer,node_critic,node_vanilla,node_polish,node_base_agent toneAmber
class node_model_config,node_config_utils,node_generation_utils,node_image_utils,node_eval_toolkits,node_prompt_diagram,node_prompt_plot,node_style_guides toneMint
class node_dataset,node_results,node_visualize_eval,node_visualize_pipeline,node_skill_run toneRose
```

## Components

### Entrypoints

Command-line, app, and demo surfaces

- [main.py](https://github.com/dwzhu-pku/paperbanana/blob/main/main.py): batch runner · CLI batch execution and evaluation entrypoint · `main.py`
- [app.py](https://github.com/dwzhu-pku/paperbanana/blob/main/app.py): gradio app · Interactive Gradio UI entrypoint · `app.py`
- [demo.py](https://github.com/dwzhu-pku/paperbanana/blob/main/demo.py): streamlit demo · Demo flow for candidate generation and refinement · `demo.py`

### Pipeline Core

Multi-agent generation and refinement stages

- [Retriever](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/retriever_agent.py): reference search · Selects relevant benchmark examples · `agents/retriever_agent.py`
- [Planner](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/planner_agent.py): spec planning · Expands source text into a structured figure plan · `agents/planner_agent.py`
- [Stylist](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/stylist_agent.py): style rewrite · Adapts plans to publication-style conventions · `agents/stylist_agent.py`
- [Visualizer](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/visualizer_agent.py): image synthesis · Calls image generation models to render candidates · `agents/visualizer_agent.py`
- [Critic](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/critic_agent.py): quality loop · Evaluates outputs and drives iterative refinement · `agents/critic_agent.py`
- [Vanilla](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/vanilla_agent.py): baseline generation · Direct generation baseline path · `agents/vanilla_agent.py`
- [Polish](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/polish_agent.py): refinement · Post-processing and refinement path · `agents/polish_agent.py`
- [Base Agent](https://github.com/dwzhu-pku/paperbanana/blob/main/agents/base_agent.py): agent base · Shared agent abstraction and common behavior · `agents/base_agent.py`

### Support Assets

Prompts, style guides, config, and utilities

- [Model Config](https://github.com/dwzhu-pku/paperbanana/blob/main/configs/model_config.template.yaml): routing config · Externalized model and provider configuration · `configs/model_config.template.yaml`
- [Config Utils](https://github.com/dwzhu-pku/paperbanana/blob/main/utils/config.py): config loading · Loads and resolves configuration for runtime use · `utils/config.py`
- [Generation Utils](https://github.com/dwzhu-pku/paperbanana/blob/main/utils/generation_utils.py): runtime helpers · Async orchestration and generation helper routines · `utils/generation_utils.py`
- [Image Utils](https://github.com/dwzhu-pku/paperbanana/blob/main/utils/image_utils.py): image processing · Image manipulation, export, and formatting helpers · `utils/image_utils.py`
- [Eval Toolkits](https://github.com/dwzhu-pku/paperbanana/blob/main/utils/eval_toolkits.py): scoring · Benchmark evaluation helpers and metrics · `utils/eval_toolkits.py`
- [Diagram Prompts](https://github.com/dwzhu-pku/paperbanana/blob/main/prompts/diagram_eval_prompts.py): prompt assets · Prompt templates for diagram evaluation · `prompts/diagram_eval_prompts.py`
- [Plot Prompts](https://github.com/dwzhu-pku/paperbanana/blob/main/prompts/plot_eval_prompts.py): prompt assets · Prompt templates for plot evaluation · `prompts/plot_eval_prompts.py`
- [Style Guides](https://github.com/dwzhu-pku/paperbanana/blob/main/style_guides/neurips2025_diagram_style_guide.md): style assets · Reusable style guidance for academic figure conventions · `style_guides/neurips2025_diagram_style_guide.md`

### Ops and Analysis

Packaging, scripts, visualization, and runtime artifacts

- **PaperBananaBench**: benchmark data · Reference figures, metadata, and task instances
- **Results**: runtime outputs · Generated candidates, intermediate artifacts, and exports
- [Eval Viewer](https://github.com/dwzhu-pku/paperbanana/blob/main/visualize/show_referenced_eval.py): analysis ui · Visual inspection of referenced evaluation results · `visualize/show_referenced_eval.py`
- [Pipeline Viewer](https://github.com/dwzhu-pku/paperbanana/blob/main/visualize/show_pipeline_evolution.py): analysis ui · Visualization of pipeline evolution and traces · `visualize/show_pipeline_evolution.py`
- [Skill Runtime](https://github.com/dwzhu-pku/paperbanana/blob/main/skill/run.py): clawhub skill · Agent-platform integration entrypoint · `skill/run.py`

## Connections

- main.py → Retriever: batch run · Executes the full generation pipeline for benchmark batches
- main.py → Planner: plan · Creates structured figure specifications
- main.py → Visualizer: render · Generates candidate figures
- main.py → Critic: evaluate · Scores outputs and coordinates refinement
- app.py → Planner: interactive flow · Routes user input into the same planning stages
- demo.py → Visualizer: candidate gen · Produces candidate images for inspection
- demo.py → Polish: refine · Supports post-processing and refinement
- Retriever → PaperBananaBench: lookup · Finds similar references from the benchmark
- Planner → Stylist: handoff · Refined plan is adapted to publication norms
- Stylist → Visualizer: spec to image · Converts styled plans into generated candidates
- Visualizer → Critic: candidates · Sends rendered figures for critique
- Critic → Polish: revise · Feeds refinement decisions back into post-processing
- Vanilla → Visualizer: direct path · Bypasses multi-stage planning for baseline generation
- Base Agent → Retriever: shared base · Common agent abstraction used by specialized roles
- Base Agent → Planner: shared base · Common agent abstraction used by specialized roles
- Base Agent → Stylist: shared base · Common agent abstraction used by specialized roles
- Base Agent → Visualizer: shared base · Common agent abstraction used by specialized roles
- Config Utils → Model Config: loads · Resolves model and provider settings at runtime
- Generation Utils → Visualizer: orchestrates · Supports concurrent generation and call sequencing
- Image Utils → Results: writes · Stores exported images and derived artifacts
- Eval Toolkits → Critic: scores · Provides evaluation logic for comparison against targets
- Diagram Prompts → Critic: guides · Shapes diagram-specific evaluation behavior
- Plot Prompts → Critic: guides · Shapes plot-specific evaluation behavior
- Style Guides → Stylist: guides · Provides reusable academic style conventions
- Eval Viewer → Results: inspect · Reads stored evaluations for analysis
- Pipeline Viewer → Results: trace · Shows pipeline evolution and intermediate outputs
- Skill Runtime → main.py: entry · Publishes the pipeline as a skill runtime
