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

Task.output_file only writes inside the project root. See Project-Root Containment.

framework: praisonai honours output_file on YAML tasks and creates parent directories automatically. See Headless YAML Runs.

Method 5: Workflow output_file

Recommended for YAML-based workflows with variable substitution.

agents.yaml Example

Run the Workflow

Workflow step output_file only writes inside the project root, after {{variable}} substitution. See Project-Root Containment.

Project-Root Containment

Agent.output_file, Task.output_file and Workflow step output_file only write inside the project root. A path that escapes it is skipped with a warning log — no exception is raised. Relative paths are resolved against the project root.
The skipped write logs Output file '<path>' is outside project root '<root>'; skipping save. Only Agent.output_file also prints ⚠️ Output path outside project root to stdout — Task and Workflow writes log the warning only.
A hardlinked file is replaced with a new file under the same name, so a file it shares data with outside the root is never changed. Existing file permissions are kept on overwrite.
Same rules on every write path. Since PraisonAI PR #6172, Agent(output=OutputConfig(output_file=...)) and Agent(output="file.txt") use the same writer as Task.output_file and Workflow step output_file, so the root check, symlink and hardlink protection, and permission preservation apply to all three. See PRAISONAI_PROJECT_ROOT for details.

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