Skip to main content
Run your project’s formatter after every agent file edit so style stays consistent without extra steps.
from praisonaiagents import Agent
from praisonaiagents.tools.edit_tools import create_edit_tools

edit_tools = create_edit_tools(post_edit_format="auto")

coder = Agent(
    name="Coder",
    instructions="Edit files cleanly and keep formatting consistent.",
    tools=edit_tools,
)
coder.start("Refactor utils.py to use list comprehensions")
The user asks for a refactor; the formatter runs automatically after each file edit.

How It Works

Quick Start

1

Simple Usage

Enable auto-formatting on edit tools:
from praisonaiagents import Agent
from praisonaiagents.tools.edit_tools import create_edit_tools

edit_tools = create_edit_tools(post_edit_format="auto")

coder = Agent(
    name="Coder",
    instructions="Edit the file as requested.",
    tools=edit_tools,
)
coder.start("Add type hints to models.py")
2

With Configuration

Pin formatters per extension:
from praisonaiagents import Agent
from praisonaiagents.tools.edit_tools import create_edit_tools

edit_tools = create_edit_tools(
    post_edit_format="auto",
    formatters={
        ".py": ["ruff", "format", "{path}"],
        ".ts": ["./node_modules/.bin/prettier", "--write", "{path}"],
    },
)

coder = Agent(name="PolyglotCoder", instructions="Edit Python and TypeScript.", tools=edit_tools)
A missing or failing formatter never fails the edit — the original write is kept and errors are logged at debug level.

How It Works

After a successful edit_file or apply_patch, the pipeline detects a formatter by file extension, runs it, and re-reads the file on exit code 0.
ExtensionDefault command
.pyruff format {path} (falls back to black)
.js, .ts, .tsx, .json, .css, .mdprettier --no-config --no-editorconfig --write {path}
.gogofmt -w {path}
.rsrustfmt {path}
The {path} placeholder is the absolute path to the edited file. If omitted from your argv list, it is appended automatically.

Configuration Options

OptionTypeDefaultDescription
post_edit_formatstr"off""off", "auto", or "on"
formattersdict[str, list[str]]Built-in mapPer-extension formatter argv
post_edit_diagnosticsstr"auto"Separate linter/diagnostics pass

Best Practices

post_edit_format="auto" runs a formatter only when one is on PATH — zero cost when none is installed.
Prefer ./node_modules/.bin/prettier so the version matches package.json.
Match local and CI formatter versions to avoid diff churn between runs.
Most useful for interactive agent sessions where you want immediate clean output.

File Editing

Core edit and patch tools

Code Agent

Code assistant configuration