Building Agentic Document Intelligence Pipelines: Creating Scientific Figures with AutoFigure

Introduction


In this tutorial, we explore AutoFigure, a practical toolkit for generating scientific figures directly from text descriptions, paper-like content, and structured methodological explanations. We walk through setting up the complete AutoFigure environment, resolving dependency issues such as Pillow compatibility, and preparing the required rendering tools for SVG and PNG outputs. We then build a custom reference figure, configure an API-backed generation workflow, and use AutoFigure to transform a detailed agentic document intelligence pipeline into a publication-style scientific diagram. Along the way, we also test offline SVG rendering, inspect the generated files, create a sample paper and PDF, and export the final outputs to a reusable gallery and a zip archive.


Setting Up the AutoFigure Environment


To begin, we clone the AutoFigure repository and install its dependencies. The setup process requires careful attention to version compatibility, particularly for Pillow, which may need a specific version to work correctly with the rendering backend. We also verify that the necessary tools for SVG and PNG conversion (such as cairosvg or rsvg-convert) are available in the environment.


import os
import sys
import json
import time
import glob
import shutil
import textwrap
import subprocess
import importlib
from pathlib import Path
from getpass import getpass

REPO_URL = "https://github.com/ResearAI/AutoFigure.git"
REPO_DIR = Path("/content/AutoFigure")
OUTPUT_ROOT = Path("/content/autofigure_colab_outputs")
PROVIDER = os.environ.get("AUTOFIGURE_PROVIDER", "openrouter")
DEFAULT_MODELS = {
    "openrouter": "google/gemini-3.1-pro-preview",
    "gemini": "gemini-3.1-pro-preview",
    "bianxie": "gemini-3.1-pro-preview",
}
GENERATION_MODEL = os.environ.get(
    "AUTOFIGURE_MODEL",
    DEFAULT_MODELS.get(PROVIDER, "google/gemini-3.1-pro-preview")
)
MAX_ITERATIONS = int(os.environ.get("AUTOFIGURE_MAX_ITERATIONS", "1"))
QUALITY_THRESHOLD = float(os.environ.get("AUTOFIGURE_QUALITY_THRESHOLD", "8.5"))
RUN_TEXT_TO_FIGURE = True
RUN_PAPER_TO_FIGURE = False
RUN_MXGRAPH_DEMO = False
RUN_IMAGE_ENHANCEMENT = False
TEXT_OUTPUT_FORMAT = "svg"
MXGRAPH_OUTPUT_FORMAT = "mxgraphxml"
ART_STYLE = (
    "clean publication-ready scientific illustration, precise alignment, subtle shadows, "
    "clear academic typography, high contrast, minimal clutter"
)
FIGURE_DESCRIPTION = """
Create a publication-ready scientific method figure for an agentic long-document intelligence system.
The figure should explain the following pipeline in a left-to-right flow:

Dependency Fixes


One common issue is Pillow's incompatibility with newer Python versions. We resolve this by pinning a compatible version before installing the rest of the requirements. Additionally, we ensure that the system has the necessary rendering libraries for high-quality SVG output.


Building a Custom Reference Figure


With the environment ready, we create a custom reference figure that serves as a style template. This figure establishes visual consistency, including color schemes, typography, and layout conventions, which AutoFigure will use as a guide for subsequent generations.


The reference figure is constructed programmatically, defining shapes, connectors, and labels that mirror the aesthetic expected in academic publications. We save this reference in a dedicated directory where AutoFigure can easily access it.


Configuring API-Backed Generation


AutoFigure supports multiple API providers for model-backed figure generation. In this tutorial, we configure it to use OpenRouter as the default provider, with a Google Gemini model as the generation engine. We set up the necessary environment variables and API keys, allowing the system to call the model for translating text descriptions into figure code.


The configuration allows flexibility in switching between providers and models, making it adaptable to different user preferences or cost considerations. We also define quality thresholds and iteration limits to balance output quality with computational efficiency.


Converting Text to a Scientific Diagram


We provide AutoFigure with a detailed textual description of an agentic document intelligence pipeline. The system parses this description and, using the configured model, generates a structured figure that visually represents the workflow.


Offline SVG Rendering


We test the offline rendering capability by generating an SVG file directly from the output. This allows us to inspect the figure without needing additional conversions or external services. The SVG format ensures that the figure remains scalable and editable for further refinements.


Generating a Sample Paper and PDF


To contextualize the generated figure, we create a sample paper that includes the diagram alongside explanatory text. We then compile this paper into a PDF, demonstrating how the figure integrates into a full document. This step highlights the practical utility of AutoFigure in real research workflows.


Exporting Outputs


The final outputs, including the generated figures, the sample paper, and the PDF, are organized into a reusable gallery structure. We also create a zip archive for easy distribution and sharing. This modular approach ensures that users can integrate AutoFigure outputs into their own projects seamlessly.


Conclusion


AutoFigure provides a robust workflow for generating publication-ready scientific figures from text descriptions, significantly reducing the manual effort involved in diagram creation. By following this tutorial, you can set up your own pipeline, customize reference styles, and leverage API-backed models to produce high-quality visual content for your research documents. As AI-driven tools continue to evolve in 2026, AutoFigure represents a valuable addition to the researcher's toolkit, streamlining the path from idea to illustration.

via MarkTechPost

Related