Contract review: a four-task DAG with step-level retries
Official cookbook recipe
- Industry
- Business services · Contract review
- Source
- Official open-multi-agent cookbook
- Stage
- Runnable example
This is an official open-multi-agent cookbook example, maintained by YuanASI. It splits one contract review into a directed acyclic graph of four tasks: after clause extraction, a compliance branch and a summary branch run in parallel, then merge into a Markdown review report. Each of the last three tasks has its own retry settings.
Scenario
A typical case: a legal or procurement team receives a contract awaiting signature and usually has four jobs to do — pull out the clauses, check each one against the compliance standard, give the business side an executive summary, and finally combine everything into a report that can be circulated. Done by hand in sequence, the summary waits until the compliance check is finished, even though the two do not depend on each other; and if any step fails, the whole flow starts over.
The example shows what the orchestration layer does with parallelism and failure once those four jobs are written as an explicit dependency graph: the two independent tasks start at the same time, a failed task reruns on its own, and upstream tasks that already finished stay finished.
How it works
| Roles | Task DAG | Tools | Model | Deployment |
|---|---|---|---|---|
| extractor | Task 1 extract-clauses (root task, no dependencies) | None declared | claude-sonnet-4-6 / anthropic | Local script, single run via npx tsx |
| compliance-checker | Task 2 compliance-check, depends on task 1 | None declared | claude-sonnet-4-6 / anthropic | Same |
| summarizer | Task 3 summary, depends on task 1 (parallel with task 2) | None declared | claude-sonnet-4-6 / anthropic | Same |
| notifier | Task 4 notify, depends on tasks 2 and 3 | None declared | claude-sonnet-4-6 / anthropic | Same |
The models in the table are the example repository's defaults; the actual choice is made per scenario at the design stage.
None of the four agents declares tools or a toolPreset. OMA's tool grants are deny-by-default (src/tool/grants.ts: with no positive grant, an agent resolves to zero built-in tools), so this pipeline makes model calls only.
Tasks 2, 3 and 4 each set maxRetries: 2, retryDelayMs: 500, retryBackoff: 2 — up to three attempts. The framework's backoff uses equal jitter: retry.ts computes 500 × 2^(n-1) (capped at 30 seconds), then sleeps for a jittered value between half and the full amount. Errors are classified first: unrecoverable ones such as authentication failures, structured-output validation failures and cancellations skip retries entirely.
The team sets sharedMemory: true, but none of the four tasks sets memoryScope: 'all', so each prompt receives the output of its direct prerequisites (the ## Context from prerequisite tasks section). The contract text comes from fixtures/sample-contract.txt in the repository, a fictional service agreement with placeholder parties.
Result
Runnable output and how to verify it:
An API key is required. The script header lists ANTHROPIC_API_KEY as the prerequisite; run it with npx tsx packages/core/examples/cookbook/contract-review-dag.ts.
Parallelism is observable. A progress callback prints task_start / task_complete timestamps for every task; after the run, verifyParallelism() compares the start times of compliance-check and summary, and prints Parallel execution (< 500ms): YES only if they are under 500 ms apart — otherwise it prints ASSERTION FAILED and exits with code 1.
Retries can be triggered on purpose. Run with FORCE_FAIL=task2 npx tsx …, and the compliance-checker's beforeRun hook throws [FORCE_FAIL_TRIGGERED] on the first attempt only. It is a plain error without an HTTP status code, which isRetryableError classifies as retryable, so the console shows a task_retry event, the second attempt passes, and the flow still completes. Tested locally on 2026-09-06 at commit 36e99fe: task_retry printed attempt 1 / maxAttempts 3 with a 267 ms backoff, compliance-check completed on its second attempt, all four tasks succeeded and produced the final Markdown report, exit code 0. That run swapped the committed anthropic / claude-sonnet-4-6 for DeepSeek's deepseek-v4-flash and left the rest of the logic as is.
The final output is the report text. The console prints each agent's output in turn and, on success, prints the notifier's Markdown report separately (executive summary, compliance results, risk details, recommended actions), followed by input / output token totals.
The example runs on a fictional contract and produces model-generated text, for demonstrating and verifying the flow.
Sources
How this relates to YuanASI
The material on this page is a cookbook example from the official open-multi-agent repository, maintained by YuanASI.
If you run a real contract or document review flow and want clause extraction, rule checks and report generation split into tasks that run in parallel and rerun individually, wired into your own contract repository and approval system, the matching YuanASI service is Custom AI Agent Development →
Related services
Last updated
Want to know how a workflow like this would land on your side?