How It Works
Quick Start
1
Set the workspace
2
Read and patch a file
Available Tools
Using with Agents
TheCODE_TOOLS list contains all tools ready for use with PraisonAI agents:
Tool Reference
code_read_file
Read file contents with optional line ranges and line number annotations.code_write_file
Create new files or completely replace existing files.For partial modifications, use
code_apply_diff instead of overwriting the entire file.code_list_files
List files and directories with optional filtering.code_apply_diff
Apply precise, surgical modifications using SEARCH/REPLACE diffs.Diff Format
The diff format uses clear markers::start_line:N- Optional line number hint for faster matching-------- Separator after line hints=======- Divider between search and replace content- Multiple blocks can be included in a single diff
Multiple Changes
Apply multiple changes in one operation:code_search_replace
Simple search and replace for straightforward text substitutions.code_execute_command
Execute shell commands safely within the workspace.Fuzzy Matching
The diff strategy includes fuzzy matching using Levenshtein distance, which helps when:- Code has been slightly modified since you read it
- There are minor whitespace differences
- Line numbers have shifted due to other changes
Indentation Preservation
When applying diffs, indentation is automatically preserved:Security Features
Workspace Isolation
All file operations are restricted to the configured workspace:Gitignore Support
Thecode_list_files tool respects .gitignore patterns by default:
Safe Command Execution
Commands are executed with safety checks:Low-Level API
For advanced use cases, you can use the low-level functions directly:Helper Functions
Creating Diff Blocks Programmatically
Best Practices
Always read before modifying
Always read before modifying
Read the file first to get the exact content for your SEARCH block:
Use line number hints
Use line number hints
Include
:start_line:N for faster and more accurate matching:Make atomic changes
Make atomic changes
Group related changes in a single diff, but keep unrelated changes separate for easier debugging.
Verify changes
Verify changes
After applying a diff, read the file again or run tests to verify:
Complete Example
Here’s a complete workflow showing an agent that adds error handling to a function:Related
Code Interpreter
Execute Python code dynamically
Tools
Learn about custom tools
Code UI
Web interface for code interaction
Agents
Learn about PraisonAI agents

