file_generation_os.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your OpenAI API key
4
Run the example
Save the code above as
file_generation_os.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Serve an agent with FileGenerationTools through AgentOS to produce JSON, CSV, PDF, DOCX, TXT, and HTML files returned as base64 artifacts.
"""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)
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U "agno[os]" openai python-docx reportlab
Export your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
Run the example
file_generation_os.py, then run:python file_generation_os.py
Was this page helpful?