Building a Multi-Stage Document Translation and Proofreading Agent Workflow
This article explains how to build a multi-stage agent workflow for document translation and proofreading. Instead of relying on a single model call, the workflow splits the task into an initial translation stage and a review stage, connected by structured data contracts. It covers the overall architecture, prompt design for both agents, chunking strategy, quality gates, human-in-the-loop feedback, and common tuning pitfalls. The same orchestration pattern can be applied to summarization, code comment generation, and structured report extraction.
1. Why Single-Pass Translation Is Not Enough
In scenarios such as enterprise knowledge management, technical documentation localization, and cross-border collaboration, document translation is rarely a single model call. Single-pass translation has three typical weaknesses: long-document context gets compressed, causing inconsistent terminology; the model tends to over-paraphrase, producing free-form sentences that drift from the original technical meaning; and there are no verifiable intermediate artifacts, making it impossible to tell whether an error came from translation or formatting.
Splitting the task into two stages, initial translation and review, turns one uncontrollable large task into two small tasks with clear responsibilities and measurable outputs. The first stage only translates the meaning correctly; the second stage only unifies expression and catches errors. This multi-stage agent orchestration is similar to a compiler front end plus an optimization back end: only when each stage has a clear input/output contract can stages be tested and replaced independently.
2. Overall Architecture: Two Stages and Data Contracts
The workflow is a linear main path with one side branch:
Document parsing → Chunking → [Agent A: Initial translation] → [Agent B: Review] → Quality gate → Layout reinsertion → Output↑ ↓Glossary Issue list → Human feedback
The key is the data contract between stages. Do not let the second stage read the first stage’s natural-language output directly. Define a structured intermediate format instead, for example:
{"chunk_id": "c-017","source": "The retry budget is bounded by the backoff ceiling.","target": "重试预算受退避上限约束。","terms_used": ["retry budget=重试预算", "backoff ceiling=退避上限"],"flags": ["long sentence", "passive voice"]}
With chunk_id and terms_used, the review stage can make targeted edits instead of rewriting everything, which makes issue localization and regression testing possible.
3. Agent A: Prompt Design for Initial Translation
The initial translation agent has one goal: faithfulness. The prompt should state three do’s and three don’ts: keep numbers, units, code identifiers, and placeholders; do not merge or split sentences; do not add explanations that are not in the source.
In practice, protect untranslatable elements with placeholders before passing them to the model:
You are a technical document translator. Translate <SRC> into Simplified Chinese.Rules:1) Keep placeholders such as {{0}} and {{1}} exactly as they are; do not translate them or change their order;2) Keep code blocks, commands, and variable names unchanged;3) Output JSON: {"target": "...", "terms_used": [...]};4) Mark uncertain spots with "flags":["to be confirmed"]; do not fabricate.<SRC>{{chunk_text}}</SRC>
Chunking strategy also matters. Split by heading hierarchy and paragraph boundaries, keep each chunk to a few hundred characters, and allow slight overlap between chunks to avoid broken cross-chunk references.
4. Agent B: The Dual Role of the Review Stage
The review agent does two things: terminology unification and error correction. Its input should include the source text, the initial translation, the glossary, and the flags marked by the previous stage. Its output is the revised translation plus a structured issue list.
You are a senior technical reviewer. Produce a revised version based on <SRC> and <DRAFT>.Priority: technical accuracy > terminology consistency > readability > style.Compare every entry in the glossary <GLOSSARY> one by one; if inconsistent, change it to the glossary translation.Output JSON: {"target":"...", "issues":[{"type":"terminology|omission|semantic drift","detail":"..."}]}<GLOSSARY>{{glossary}}</GLOSSARY>
Maintain the glossary as “source term=standard translation” pairs. It can be compiled manually or extracted as high-frequency candidates from existing confirmed documents and then confirmed by a human before being added. The review stage should use a low temperature to favor determinism over creativity.
5. Quality Gates and Human Feedback
The end of the pipeline needs an automatic gate to send unqualified results back. Several generic checks can be combined: whether placeholder count and order match the source; whether numbers, units, and identifiers correspond one to one; whether glossary hit rate meets the threshold; whether the ratio of translation length to source length falls in a reasonable range; and whether the issue list contains “to be confirmed”.
def gate(src, out, glossary, ratio=(0.6, 2.2)):if len(out["target"]) / max(len(src), 1) < ratio[0]: return "suspected omission"if out["target"].count("{{") != src.count("{{"): return "placeholder mismatch"hit = sum(1 for k in glossary if k in out["target"])if hit / max(len(glossary), 1) < 0.9: return "insufficient terminology coverage"return "PASS"
Chunks that fail the gate enter a human feedback queue. Human revisions also serve as optimization input for the glossary and prompts, forming a closed loop.
6. Common Pitfalls and Tuning Tips
First, do not allow too much creativity in the review stage, or content not present in the source will be introduced. Second, chunks that are too large cause context compression, while chunks that are too small lose references; tune values by testing on the document type. Third, keep a diff view of review results so humans can verify quickly. Fourth, log the input snapshot, prompt version, and model version of every run to ensure traceability and regression testing.
If throughput and cost are sensitive, the whole pipeline can be containerized and deployed on a container platform, with a message queue handling chunk-level task distribution and retries, object storage holding source text, intermediate artifacts, and the glossary, and logging and monitoring services observing pass rates and average revision rounds per stage. Baidu AI Cloud offers corresponding product categories for these general capabilities and they can be combined as needed, but the architecture itself is vendor-neutral.
7. Summary
The value of a two-stage agent workflow is not making the model write one more time. It turns translation, a fuzzy task, into an engineering process that is contract-based, measurable, and able to feed results back: initial translation pursues faithfulness, review pursues consistency, the gate pursues control, and humans provide a fallback. Once you master this orchestration pattern, the same structure can be transferred to summarization, code comment completion, and structured report extraction.
