Skip to main content
file_generation_os.py
"""File generation with AgentOS.

This example serves an agent that generates files (JSON, CSV, PDF, DOCX, TXT, HTML)
through AgentOS using the FileGenerationTools toolkit.

Run:
    .venvs/demo/bin/python cookbook/05_agent_os/file_generation/file_generation_os.py

Then open os.agno.com, connect to the local server, and chat with the agent, e.g.:
    "Generate a DOCX report on Q4 sales trends."
    "Generate a PDF about renewable energy."
    "Generate a CSV of 5 fictional employees."
    "Generate an HTML landing page for a coffee shop."

Generated files are returned as base64-encoded artifacts in the AgentOS response
and saved to tmp/file_gen_out/.
"""

from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIResponses
from agno.os.app import AgentOS
from agno.tools.file_generation import FileGenerationTools

agent_db = SqliteDb(db_file="tmp/file_gen_os.db")

file_agent = Agent(
    name="File Generator",
    model=OpenAIResponses(id="gpt-5.4"),
    db=agent_db,
    tools=[
        FileGenerationTools(
            all=True,
            output_directory="tmp/file_gen_out",
        )
    ],
    description="You generate files (JSON, CSV, PDF, DOCX, TXT, HTML) on request.",
    instructions=[
        "When asked to create a file, pick the right generator tool for the requested format.",
        "Always provide meaningful content and a descriptive filename.",
        "When generating HTML files, produce a complete HTML5 document with doctype, html, head, and body tags.",
        "Briefly explain what was generated.",
    ],
    markdown=True,
    debug_mode=True,
    add_history_to_context=True,
    num_history_runs=3,
)

agent_os = AgentOS(agents=[file_agent])
app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="file_generation_os:app", reload=True)

Run the Example

1

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2

Install dependencies

uv pip install -U "agno[os]" fastmcp openai python-docx reportlab starlette
3

Export your API keys

export JWT_VERIFICATION_KEY="your_jwt_verification_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:JWT_VERIFICATION_KEY="your_jwt_verification_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4

Run the example

Save the code above as file_generation_os.py, then run:
python file_generation_os.py
Full source: cookbook/05_agent_os/file_generation/file_generation_os.py