> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# File Generation

> The `FileGenerationTools` toolkit enables Agents and Teams to generate files in multiple formats.

<Badge icon="code-branch" color="orange">
  <Tooltip tip="Introduced in v2.0.6" cta="View release notes" href="https://github.com/agno-agi/agno/releases/tag/v2.0.6">v2.0.6</Tooltip>
</Badge>

<Tip>
  Supported file types:

  * JSON
  * CSV
  * PDF
  * DOCX
  * TXT
  * HTML
</Tip>

## Prerequisites

1. **Install dependencies:**
   ```bash theme={null}
   uv pip install reportlab python-docx openai sqlalchemy
   ```
   `reportlab` is required for PDF generation, `python-docx` for DOCX generation, and `sqlalchemy` for the `SqliteDb` used in the example. JSON, CSV, TXT, and HTML generation have no external dependencies.

2. **Set your credentials:**
   For OpenAI API:
   ```bash theme={null}
   export OPENAI_API_KEY="your-openai-api-key"
   ```

## Example

The following agent will generate files in different formats based on user requests.

```python file_generation_tools.py theme={null}
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
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}")
```

<Note>
  Generated files are always available on the `RunOutput` object. Set `output_directory` (or `save_files=True`) to also save them to disk.
</Note>

## Toolkit Params

| Parameter                | Type            | Default | Description                                                                                          |
| ------------------------ | --------------- | ------- | ---------------------------------------------------------------------------------------------------- |
| `enable_json_generation` | `bool`          | `True`  | Enables JSON file generation                                                                         |
| `enable_csv_generation`  | `bool`          | `True`  | Enables CSV file generation                                                                          |
| `enable_pdf_generation`  | `bool`          | `True`  | Enables PDF file generation (requires reportlab)                                                     |
| `enable_docx_generation` | `bool`          | `True`  | Enables DOCX file generation (requires python-docx)                                                  |
| `enable_txt_generation`  | `bool`          | `True`  | Enables text file generation                                                                         |
| `enable_html_generation` | `bool`          | `True`  | Enables HTML file generation                                                                         |
| `output_directory`       | `Optional[str]` | `None`  | Custom output directory path. Implies `save_files=True`                                              |
| `save_files`             | `bool`          | `False` | Saves generated files to disk when True (to `output_directory`, or the current directory if not set) |
| `all`                    | `bool`          | `False` | Enables all file generation types when True                                                          |

## Toolkit Functions

| Name                 | Description                                                  |
| -------------------- | ------------------------------------------------------------ |
| `generate_json_file` | Generates a JSON file from data (dict, list, or JSON string) |
| `generate_csv_file`  | Generates a CSV file from tabular data                       |
| `generate_pdf_file`  | Generates a PDF document from text content                   |
| `generate_docx_file` | Generates a Word (DOCX) document from text content           |
| `generate_text_file` | Generates a plain text file from string content              |
| `generate_html_file` | Generates an HTML file from a complete HTML5 document        |

## Developer Resources

* [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/file_generation.py)
