Skip to main content
Save agent responses to files automatically — pass a path, use OutputConfig, or let the agent call write_file.
The user asks for content; the agent writes the response to the configured output file.

Quick Start

1

Simple Usage

Pass a file path string to output:
2

With Configuration

Use OutputConfig for template formatting:

How It Works

The user sends a request; the agent generates a response and the framework writes it to the configured output file.

Methods Comparison


Method 1: String Path (Simplest)

One line - just pass a file path string to output.

Basic Usage

With Directory

The agent automatically creates parent directories if they don’t exist.

Method 2: OutputConfig (With Template)

Use OutputConfig when you need to save output AND apply template formatting.
Recommended: For response templates without file saving, use TemplateConfig.response instead. See Templates for details.

With Template

The template instructs the agent to format its response accordingly. Both OutputConfig.template and TemplateConfig.response work - use TemplateConfig.response when you don’t need file saving.

Combined with Other Settings


Method 3: write_file Tool

Recommended when the agent needs to decide what to save and where.

Basic Usage

With Multiple File Tools

The agent autonomously decides when to call write_file based on the task.

Method 4: Task output_file

Recommended for task-based workflows where you want automatic file saving.

Basic Usage

Multiple Tasks with Different Outputs


Method 5: Workflow output_file

Recommended for YAML-based workflows with variable substitution.

agents.yaml Example

Run the Workflow


Method 6: Manual Capture

Use when you need full control over the saving process.

Basic Manual Save

With Error Handling


Best Practices

Always set create_directory=True when using Task.output_file to avoid errors:
Use variables for flexible output paths:
For large outputs, consider streaming to file:

Complete Example

1

Install

2

Create Agent with File Tools

3

Run and Save


File Tools

Complete file operations reference

Workflows

YAML workflow configuration