← All tools

Code Engineering

Unified Diff

Pure-Java unified diff between two files or two literal strings — no shell-out, no native binary.

diff

Overview

Lets the agent see the difference between a fresh draft and the existing file, or two versions in memory, without spawning git diff.

How it works

READ_ONLY. Output capped at 50 KB. The agent typically uses this to decide whether a proposed change is the change it intended — compose with file_edit/file_write for an edit → verify loop.

Example

When a user asks:

Show me the diff between the current README and the draft I just wrote.

the agent calls the tool:

diff(file_a="README.md", file_b="README-draft.md", context=3)

and gets back: @@ -12,7 +12,7 @@ - Status: alpha + Status: production ...

What it's good for

Real scenarios where agents put this tool to work.

Verify a planned edit before committing it via file_edit
Compare two LLM-generated variants of the same file

Source

Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/code/diff/DiffTool.java in the swarm-ai repository.

Open diff on GitHub →