← All posts
·7 min read

AutoGen + AgentGen: Give Your Agents a Download Link

Last Updated: March 2026

TL;DR

  • Register AgentGen as functions in your AutoGen AssistantAgent config
  • Map the functions in UserProxyAgent for execution
  • Any AutoGen agent — solo or multi-agent — can now produce a PDF or image and return a download link

Why AutoGen agents need file output

AutoGen excels at multi-step reasoning and agent-to-agent collaboration. A typical AutoGen workflow ends when the assistant agent returns its final text response. But for many real-world tasks, the expected output is a file, not a summary: an invoice, a report, a certificate. Text is the working draft; the file is the deliverable.

AgentGen closes this gap with a simple API: POST HTML, get a CDN download URL. Register it as a function in AutoGen and your agents gain the ability to produce downloadable artifacts in any workflow.

Setup

pip install pyautogen requests python-dotenv

Step 1 — Implement the functions

import os, requests

AGENTGEN_KEY = os.environ["AGENTGEN_API_KEY"]

def generate_pdf(html: str, page_size: str = "A4") -> dict:
    """
    Render an HTML string to a PDF using AgentGen.
    Returns: {"url": "https://cdn.agent-gen.com/...", "tokens_used": 2}
    Cost: 2 tokens per page.
    """
    r = requests.post(
        "https://www.agent-gen.com/api/v1/generate/pdf",
        headers={"X-API-Key": AGENTGEN_KEY, "Content-Type": "application/json"},
        json={"html": html, "format": page_size},
        timeout=30,
    )
    if r.status_code == 402:
        return {"error": "Insufficient tokens — top up at agent-gen.com/pricing"}
    r.raise_for_status()
    return r.json()

def generate_image(html: str, width: int = 1200, height: int = 630) -> dict:
    """
    Render an HTML string to a PNG image using AgentGen.
    Returns: {"url": "https://cdn.agent-gen.com/..."}
    Cost: 1 token.
    """
    r = requests.post(
        "https://www.agent-gen.com/api/v1/generate/image",
        headers={"X-API-Key": AGENTGEN_KEY, "Content-Type": "application/json"},
        json={"html": html, "width": width, "height": height, "format": "png"},
        timeout=30,
    )
    r.raise_for_status()
    return r.json()

Step 2 — Configure the AutoGen agents

import autogen, os

config_list = [{"model": "gpt-4o", "api_key": os.environ["OPENAI_API_KEY"]}]

assistant = autogen.AssistantAgent(
    name="DocumentAgent",
    system_message=(
        "You generate professional PDFs and images. "
        "Write complete, styled HTML with inline CSS. "
        "Call generate_pdf for documents and generate_image for visual assets. "
        "Always return the URL from the tool result to the user."
    ),
    llm_config={
        "config_list": config_list,
        "functions": [
            {
                "name": "generate_pdf",
                "description": "Render HTML to a PDF. Returns a download URL. Cost: 2 tokens/page.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "html": {"type": "string"},
                        "page_size": {"type": "string", "enum": ["A4", "Letter"], "default": "A4"},
                    },
                    "required": ["html"],
                },
            },
            {
                "name": "generate_image",
                "description": "Render HTML to a PNG image. Returns a CDN URL. Cost: 1 token.",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "html": {"type": "string"},
                        "width": {"type": "integer", "default": 1200},
                        "height": {"type": "integer", "default": 630},
                    },
                    "required": ["html"],
                },
            },
        ],
    },
)

user_proxy = autogen.UserProxyAgent(
    name="User",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=5,
    function_map={"generate_pdf": generate_pdf, "generate_image": generate_image},
)

Step 3 — Run the agent

user_proxy.initiate_chat(
    assistant,
    message=(
        "Create a professional PDF invoice:
"
        "- Client: Acme Corp
"
        "- Service: Backend API development, 40 hours at $125/hr
"
        "- Due: April 15, 2026
"
        "- Issued by: Yair Levi"
    ),
)
# DocumentAgent: Generating invoice HTML...
# (calls generate_pdf)
# DocumentAgent: Your invoice is ready!
#   Download: https://cdn.agent-gen.com/output/abc123.pdf

Multi-agent report workflow

For more complex workflows, combine a data analyst agent with the document agent in a GroupChat:

analyst = autogen.AssistantAgent(
    name="Analyst",
    system_message=(
        "You analyse data and produce structured summaries with key metrics, "
        "highlights, and concerns. Format your output as clear sections."
    ),
    llm_config={"config_list": config_list},
)

groupchat = autogen.GroupChat(
    agents=[analyst, assistant, user_proxy],
    messages=[],
    max_round=8,
)
manager = autogen.GroupChatManager(
    groupchat=groupchat,
    llm_config={"config_list": config_list},
)

user_proxy.initiate_chat(
    manager,
    message=(
        "Analyse this week's data: "
        "Active users 12,847 (+8.3%), Revenue $48,200 (+12.1%), Churn 2.1% (-0.4%). "
        "Then generate a styled PDF report."
    ),
)
# Analyst summarises the data
# DocumentAgent generates the HTML report and calls generate_pdf
# → https://cdn.agent-gen.com/output/report_abc123.pdf

Cost

A one-page PDF invoice costs 2 tokens (~$0.03). A two-page report costs 4 tokens (~$0.06). The image endpoint costs 1 token. Tokens never expire — buy in bulk at the pricing page.

Get started free → — 50 free tokens on signup, enough to test 25 invoices or 12 full reports.

Ready to start generating?

Create a free account and generate your first PDF or image in minutes.

Get started free