Skip to main content
Supported file types:
  • JSON
  • CSV
  • PDF
  • TXT

Prerequisites

  1. Install dependencies:
    uv pip install reportlab openai
    
  2. Set your credentials: For OpenAI API:
    export OPENAI_API_KEY="your-openai-api-key"
    

Example

The following agent will generate files in different formats based on user requests.
file_generation_tools.py
from agno.agent import Agent
from agno.models.openai import OpenAIResponses
from agno.tools.file_generation import FileGenerationTools

agent = Agent(
    model=OpenAIResponses(id="gpt-5.2"),
    db=SqliteDb(db_file="tmp/test.db"),
    tools=[FileGenerationTools(output_directory="tmp")],  
    description="You are a helpful assistant that can generate files in various formats.",
    instructions=[
        "When asked to create files, use the appropriate file generation tools.",
        "Always provide meaningful content and appropriate filenames.",
        "Explain what you've created and how it can be used.",
    ],
    markdown=True,
)

response =agent.run(
        "Create a PDF report about renewable energy trends in 2024. Include sections on solar, wind, and hydroelectric power."
    )
print(response.content)
    if response.files:
        for file in response.files:
            print(f"Generated file: {file.filename} ({file.size} bytes)")
            if file.url:
                print(f"File location: {file.url}")
    print()
You can use the output_directory parameter to specify a custom output directory for the generated files. If not specified, the files will be available in the RunOutput object.

Toolkit Params

ParameterTypeDefaultDescription
enable_json_generationboolTrueEnables JSON file generation
enable_csv_generationboolTrueEnables CSV file generation
enable_pdf_generationboolTrueEnables PDF file generation (requires reportlab)
enable_txt_generationboolTrueEnables text file generation
output_directorystrNoneCustom output directory path
allboolFalseEnables all file generation types when True

Toolkit Functions

NameDescription
generate_json_fileGenerates a JSON file from data (dict, list, or JSON string)
generate_csv_fileGenerates a CSV file from tabular data
generate_pdf_fileGenerates a PDF document from text content
generate_text_fileGenerates a plain text file from string content

Developer Resources