Skip to main content

LangChain integration for Adeu — track-changes for DOCX in the LLM era

Project description

langchain-adeu

PyPI version License: MIT

LangChain integration for Adeu — Track Changes for Microsoft Word (.docx) in the LLM Era.

This package wraps the local, cross-platform, and offline-capable subset of Adeu's document-editing engine as native LangChain tools. It enables LangChain and LangGraph agents to read, edit, diff, sanitize, and finalize Microsoft Word documents while preserving the underlying formatting, layout, custom styles, and XML structures.


Installation

Install the package via pip or uv:

Using pip

pip install langchain-adeu

Using uv

uv add langchain-adeu

Quick Start

Instantiate the AdeuToolkit and register its tools with a tool-calling chat model. This short example initializes an agent capable of managing docx operations.

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from langchain_adeu import AdeuToolkit

# Load a tool-calling model
model = ChatOpenAI(model="anthropic:claude-sonnet-4-6")

# Initialize the toolkit
toolkit = AdeuToolkit()
tools = toolkit.get_tools()

# Create the agent
agent = create_agent(model=model, tools=tools)

Worked Example: Multi-Tool Review & Redline Flow

Below is a complete, runnable workflow illustrating how an agent can read an existing draft, apply tracked changes, generate a visual diff, and sanitize metadata before sending it to a counterparty.

from langchain_adeu import AdeuToolkit

# 1. Instantiate the toolkit
tools_map = {t.name: t for t in AdeuToolkit().get_tools()}

read_tool = tools_map["adeu_read_docx"]
apply_tool = tools_map["adeu_apply_changes"]
diff_tool = tools_map["adeu_diff_docx"]
sanitize_tool = tools_map["adeu_sanitize_docx"]

input_path = "MSA_draft.docx"
redline_path = "MSA_redlined.docx"
clean_path = "MSA_final.docx"

# 2. Read the document to extract text with active tracked changes & comments
# clean_view=False ensures the LLM sees inline CriticMarkup (e.g. {++inserted++})
read_result = read_tool.invoke({
    "reasoning": "Reading the draft to review tracked changes and comments.",
    "file_path": input_path,
    "clean_view": False,
    "mode": "full",
    "page": 1
})
print("--- Document Contents ---\n", read_result)

# 3. Apply a batch of edits (tracked modifications + a comment reply)
apply_result = apply_tool.invoke({
    "reasoning": "Applying jurisdiction edits and replying to a comment.",
    "file_path": input_path,
    "author_name": "AI Reviewer",
    "output_path": redline_path,
    "changes": [
        {
            "type": "modify",
            "target_text": "Governing Law shall be the State of New York.",
            "new_text": "Governing Law shall be the State of Delaware.",
            "comment": "Updating jurisdiction to corporate standard."
        },
        {
            "type": "reply",
            "target_id": "Com:1",
            "text": "Agreed. Applied jurisdiction change."
        }
    ]
})
print("\n--- Changes Applied ---\n", apply_result)

# 4. Generate a word-level diff to verify edits
diff_result = diff_tool.invoke({
    "reasoning": "Verifying the applied edits with a word-level diff.",
    "original_path": input_path,
    "modified_path": redline_path,
    "compare_clean": True
})
print("\n--- Word-Level Diff ---\n", diff_result)

# 5. Sanitize document properties and remove author history for final delivery
# keep_markup=True preserves unresolved track changes while stripping metadata
sanitize_result = sanitize_tool.invoke({
    "reasoning": "Stripping metadata before delivering the redline.",
    "file_path": redline_path,
    "output_path": clean_path,
    "keep_markup": True,
    "author": "Anonymous Advisor"
})
print("\n--- Sanitization Report ---\n", sanitize_result)

Per-Tool Reference

Tool Name Purpose / When to Use Key Input Parameters Response Format / Output Shape
adeu_read_docx Reads a .docx file into Markdown. Use clean_view=False to audit active track-changes. file_path (str), clean_view (bool), mode (Literal), page (int) content_and_artifact (Returns projected Markdown text + structured metadata artifact)
adeu_apply_changes Commits a transactional batch of edits as native track-changes and comment threads. file_path (str), author_name (str), changes (list[dict]), output_path (str) content_and_artifact (Returns completion text + structured change stats)
adeu_diff_docx Generates a word-level patch showing insertions and deletions between two files. original_path (str), modified_path (str), compare_clean (bool) content (Returns free-form @@ Word Patch @@ visual text)
adeu_accept_all_changes Resolves and bakes all tracked changes and format modifications into plain text. file_path (str), output_path (str) content_and_artifact (Returns completion text + artifact mapping paths)
adeu_sanitize_docx Cleans document properties (author names, RSIDs, Custom XML, DMS traces). file_path (str), output_path (str), keep_markup (bool), accept_all (bool) content_and_artifact (Returns human-readable report text + structured cleanup stats)

What's NOT Included

This package intentionally focuses on local, cross-platform, offline-capable workflows. For the following, use the Adeu MCP server directly:

  • Live MS Word Interop (Windows COM) — real-time edits on an active Microsoft Word canvas.
  • Adeu Cloud Features — email fetching, multi-document asynchronous semantic validation.
  • MCP Apps UI — interactive Markdown preview rendering inside custom client interfaces.

Development & Testing

We use uv for dependency management and workspace isolation.

Installation

Sync development and testing dependencies locally:

make install

Running Tests

To run unit tests (isolated, socket-disabled):

make test

To run integration tests (requires real fixture .docx documents):

make integration_test

Code Formatting & Linting

We enforce Ruff for formatting and linting:

make format
make lint

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_adeu-1.19.1.tar.gz (176.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_adeu-1.19.1-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file langchain_adeu-1.19.1.tar.gz.

File metadata

  • Download URL: langchain_adeu-1.19.1.tar.gz
  • Upload date:
  • Size: 176.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for langchain_adeu-1.19.1.tar.gz
Algorithm Hash digest
SHA256 de5d79308ed07b1440ac897749b3bcfbacca936a59e89fac395a93e0b9d88511
MD5 1563c82f296c91df3ccff0ffc30fabcf
BLAKE2b-256 9823826fdd0ccc6af9e4c9be62ff69984f7ffc451c3ca32edbc699639e230e7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_adeu-1.19.1.tar.gz:

Publisher: release.yml on dealfluence/adeu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_adeu-1.19.1-py3-none-any.whl.

File metadata

  • Download URL: langchain_adeu-1.19.1-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for langchain_adeu-1.19.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4c438b9be884e75b01da0be33f8a2a806abe798d8f0e4da6d6a935e4ae13fe4
MD5 d318200e6ed397c7d78f1e5bd113e040
BLAKE2b-256 0afbd4a98b3aeedc6188f6152414408747bdea23c9ad02b54f4c846ca19da771

See more details on using hashes here.

Provenance

The following attestation bundles were made for langchain_adeu-1.19.1-py3-none-any.whl:

Publisher: release.yml on dealfluence/adeu

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page