A contract redlining API lets you build your own review agent. Your application defines the model, prompt, tools, permissions, and legal workflow.
DOCX Editor supplies two layers for that agent:
- A document API reads clauses and writes proposed changes.
- A review UI shows each proposal for user action.
The agent does not flatten the contract into HTML. Each proposal remains a Word tracked change that a reviewer can accept or reject.
Try the document surface
Open a contract or edit the sample document:
This preview shows the open-source editor. Programmatic editing and review features use the commercially licensed packages.
Configure the review UI
Programmatic redlining in the browser needs three settings:
reviewModule()to enable tracked changes- an
authorfor revision attribution mode="suggesting"to record edits as proposals
import { DocxEditor } from "@docx-editor.dev/react";
import { DocxEditorReview, reviewModule } from "@docx-editor.dev/pro/react";
import "@docx-editor.dev/core/styles/editor.css";
const MODULES = [reviewModule()];
export function RedlineEditor({ bytes }: { bytes: Uint8Array }) {
return (
<DocxEditor.Root
document={bytes}
modules={MODULES}
author="Contract agent"
mode="suggesting"
>
<DocxEditor.Toolbar />
<DocxEditor.Viewport>
<DocxEditor.Content />
<DocxEditorReview />
</DocxEditor.Viewport>
</DocxEditor.Root>
);
}The review rail shows each proposed insertion, deletion, or replacement. Reviewers can accept or reject proposals before saving the contract.
Define tools for your redlining agent
@docx-editor.dev/editor-api does not impose a model or agent framework. Define
the smallest tool catalog that your workflow permits.
For example, Vercel AI SDK tools can describe one allowed redlining operation:
import { tool } from "ai";
import { z } from "zod";
export const redliningTools = {
propose_replacement: tool({
description: "Propose an exact replacement as a Word tracked change.",
inputSchema: z.object({
source: z.string().describe("Exact text from the open contract."),
replacement: z.string().describe("Replacement text."),
reason: z.string().describe("Short reason shown to the reviewer."),
}),
}),
};Pass the catalog to an AI SDK model loop. In this route excerpt, your
application supplies model and messages:
import { streamText } from "ai";
const result = streamText({
model,
system: "Review the contract against the approved clause playbook.",
messages,
tools: redliningTools,
});
return result.toUIMessageStreamResponse();The example tool has no server execute function. AI SDK forwards the tool
call to your client. Your browser executor validates the request and runs it
against the open document.
You can also use a ToolLoopAgent or another tool-calling framework. Your
server owns the system prompt and model selection. It can combine document
tools with playbook, matter, approval, or clause-library tools.
The tool catalog is an allowlist. A read-only agent can receive search and comment tools. A redlining agent can also receive proposal tools. A model cannot call a document operation that you do not expose.
Execute a proposal through the document API
The browser handles a propose_replacement call against the document that the
user has open. Search for the exact source text, then replace each match:
import { DocxEditor } from "@docx-editor.dev/editor-api/browser";
const runtime = DocxEditor.createBrowser(editor, {
author: "Contract agent",
});
try {
await runtime.run(async (context) => {
const matches = context.document.body.search("$50,000");
matches.load("items");
await context.sync();
for (const match of matches.items) {
match.insertText("$100,000", "Replace");
}
await context.sync();
});
} finally {
runtime.dispose();
}The attached editor is in suggesting mode, so the replacement enters the
document review flow. One sync() applies the complete write batch or none of
it.
The same tool can use the server runtime for a background review. The server runtime takes DOCX bytes and returns DOCX bytes. The browser runtime instead updates the open editor, uses its undo history, and shows the result at once.
The editing API overview explains server and browser runtimes. The Office.js compatibility guide lists the supported object model and its deliberate differences.
Customize the agent and user interaction
The document API and review UI are separate, composable layers. You can change one without replacing the other.
Your application can customize:
- The agent prompt, model, tool descriptions, and tool allowlist.
- Clause retrieval, playbook rules, validation, and approval limits.
- The editor toolbar, document layout, review rail, and agent panel.
- Tool progress, citations, explanations, suggestion chips, and error states.
- The point where a user accepts, rejects, changes, or comments on a proposal.
The React components expose the editor surface and review controls. Your application owns the chat or task interface around them. A user can review an agent proposal in the document, edit it manually, undo it, or reject it.
Use React composition for custom panels and controls. Use custom styles for the document style system. Use tracked changes and comments for the review interaction.
Choose embedded or hosted redlining
@docx-editor.dev/editor-api is an embedded software library. Your application
owns users, permissions, storage, negotiation state, and audit records.
It is not a hosted redlining service. It does not issue participant links, send webhooks, or manage negotiation turns. Use it when your product already owns that workflow and needs DOCX editing inside it.
Continue the review workflow
The Pro overview covers package setup, evaluation rights, and production licensing. The Word fidelity guide helps you verify the contract structures that your workflow depends on.
For a broader legal product design, see Word document editing for legal applications. For more agent patterns, see the DOCX editing API for AI agents.