Files
Read and write files with agents
Agents can work with files – read documents, write outputs, and manage data.
Quick Start
- Simple Usage
typescript import { Agent } from 'praisonai'; const agent = new Agent({ instructions: 'You analyze documents', tools: ['read_file'] }); await agent.chat('Summarize the contents of report.pdf'); // Agent reads and summarizes the file - With Configuration
typescript const agent = new Agent({ tools: ['read_file', 'write_file'] }); await agent.chat('Create a summary.txt with key points'); // Agent creates the file
User Interaction Flow
Configuration Levels
// Level 1: Array - Enable file tools
const agent = new Agent({
tools: ['read_file', 'write_file']
});
// Level 2: String - Allow directory access
const agent = new Agent({
tools: ['read_file'],
allowedPaths: './docs/'
});
// Level 3: Dict - Full control
const agent = new Agent({
files: {
read: true,
write: true,
delete: false,
allowedPaths: ['./docs/', './output/'],
maxFileSize: '10MB'
}
});File Tools
| Tool | Description |
|---|---|
read_file | Read file contents |
write_file | Create or update files |
list_files | List directory contents |
delete_file | Remove files (use carefully) |
API Reference
Tools ModuleTools including file operations
Best Practices
Limit allowed paths
Restrict file access to specific directories.
Disable delete by default
Only enable delete_file when absolutely needed.
Use approval for writes
Combine with approval for production safety.