Skip to main content
PraisonAI Code provides AI agents with powerful tools to read, write, and modify code files with surgical precision. Inspired by Kilo Code’s architecture, it uses a SEARCH/REPLACE diff strategy with fuzzy matching for reliable code modifications. The user asks the agent to edit project files; read, write, and SEARCH/REPLACE diffs apply changes safely.

How It Works

Quick Start

1

Set the workspace

2

Read and patch a file

Available Tools

Using with Agents

The CODE_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.
Output format:

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.
Output format:

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

The code_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

Read the file first to get the exact content for your SEARCH block:
Include :start_line:N for faster and more accurate matching:
Group related changes in a single diff, but keep unrelated changes separate for easier debugging.
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:

Code Interpreter

Execute Python code dynamically

Tools

Learn about custom tools

Code UI

Web interface for code interaction

Agents

Learn about PraisonAI agents