OutputConfig, or let the agent call write_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
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
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
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.
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
Choose the Right Method
Choose the Right Method
Use create_directory
Use create_directory
Always set
create_directory=True when using Task.output_file to avoid errors:Use Variables in Workflows
Use Variables in Workflows
Use variables for flexible output paths:
Handle Large Outputs
Handle Large Outputs
For large outputs, consider streaming to file:
Complete Example
1
Install
2
Create Agent with File Tools
3
Run and Save
Related
File Tools
Complete file operations reference
Workflows
YAML workflow configuration

