How do you run multiple AI agents on the same workbook without overwriting each other?

Give each agent an isolated Worktree, record input revisions, freeze for review, and merge one Unit at a time with a recovery plan for each Unit.

Published By Univer Team

Short answer: Give each agent a separate draft, record which inputs it read, and merge approved drafts one at a time. Univer’s commercial Worktree provides isolated drafts and per-Unit merge results. Your application chooses the order and rechecks any calculation whose inputs changed.

Product details checked on November 26, 2026.

Why agents overwrite each other

Picture three agents working on one planning workbook. The inventory agent updates stock counts. The demand agent rewrites the forecast. The exception-report agent reads both, finds items that will run short, and writes a summary. If all three write directly to the shared file, three things go wrong.

  • Lost writes. Two agents save the same range, and the later save silently replaces the earlier one.
  • Stale reads. The exception agent starts before the new stock counts land and reports shortages that no longer exist.
  • Duplicate output. A retried run appends a second copy of its rows because nothing records that the first attempt already wrote them.

Locking the file serializes the agents but throws away parallelism. A better approach lets agents work in parallel, in isolation, and then controls how their results come back.

Units are not worksheets

Before designing the workflow, get the vocabulary right, because merge behavior depends on it.

In Univer, a Unit is a whole document: a workbook, a Word-style document, or a presentation. A worksheet is a sheet inside a workbook Unit. A workbook with Stock, Demand, Reorder, and Exceptions sheets is one Unit. A separate memo document is a second Unit.

This matters because the Worktree documentation describes mergeWorktree() as merging Units one at a time. When a Worktree contains changes to several Units, the merge is not atomic across those Units, and the result is reported for each Unit. Edits to four sheets of one workbook are changes to a single Unit. Edits to a workbook and a memo are changes to two Units, and you need a plan for the case where one lands and the other doesn't.

Criteria for a safe multi-agent setup

The table lists what each safeguard prevents and whether Univer provides it or you build it.

CriterionWhat it preventsBuilt-in or your workflow
Isolated workspace per agentEdits landing on shared files mid-runBuilt-in: server-side Worktree
Recorded input revision per UnitActing on stale dataYour workflow
Declared output scopeTwo agents writing the same ranges or sectionsYour workflow
Dependency orderingA downstream agent reading pre-change valuesYour workflow
Frozen review stateEdits after a reviewer approvesBuilt-in: markReady()
Serialized merge with results per UnitNot knowing what actually landedBuilt-in: mergeWorktree()
Recovery for each UnitA half-applied change across UnitsYour workflow
Idempotent retriesDuplicate rows or sectionsYour workflow

The Worktree behavior described here comes from the collaboration extensions docs. A Worktree stays a draft until it is reviewed and merged. While it is a draft it accepts edits. markReady() freezes its current revision, after which it no longer accepts edits.

Illustrative example: inventory, demand, and exception agents

This is a constructed example, not a customer deployment.

The files:

  • Unit 1, supply-plan workbook. Its sheets are Stock, Demand, Reorder (formulas that combine stock and demand), and Exceptions.
  • Unit 2, exceptions-memo document. It contains a weekly narrative with a "This week" section.

The agents:

  • Inventory agent. Reads warehouse counts and writes the Stock sheet.
  • Demand agent. Reads sales history and writes the Demand sheet. It also reads Stock to cap forecasts for discontinued items.
  • Exception agent. Reads Reorder, writes rows to the Exceptions sheet, and writes the "This week" section of the memo.

The dependencies follow from what each agent reads. The demand agent depends on the inventory agent, and the exception agent depends on both. Only the exception agent touches two Units.

Step 1: Create a Worktree and a manifest for each agent

Each agent gets its own Worktree, so its edits stay out of the main documents until merge. The orchestrator also writes a manifest for each run. The manifest is your record, not a Univer feature. The revision labels below are placeholders.

run_id: exception-2026-11-26-a
agent: exception-report
base_revisions:
  supply-plan: r412
  exceptions-memo: r88
reads:
  - supply-plan / Reorder
writes:
  - supply-plan / Exceptions / A2:F200
  - exceptions-memo / This week
depends_on:
  - inventory
  - demand

The writes list is a promise. Before starting a run, the orchestrator checks that no other active manifest claims an overlapping range or section. If two do, change the plan before running anything. Univer won't decide which agent should own a range.

Step 2: Let each agent edit, calculate, and read back

Through the Univer CLI and skill, an existing agent can read and edit Excel, Word, and PowerPoint files, recalculate, read the computed values back, and check how the result renders (agents overview). Use all three checks inside the Worktree. For example, after the inventory agent writes Stock, it recalculates Reorder and reads back a few known cells. A count that parsed as text instead of a number shows up there, not in production.

Step 3: Freeze for review

When an agent finishes, the orchestrator calls markReady(). That freezes the Worktree's current revision, so the reviewer approves exactly what will merge. Only draft Worktrees accept edits, so a late correction from the agent can't slip in after approval.

Review is a workflow you design. A practical review packet includes the manifest, the changed ranges, the read-back values, and a render. If the reviewer rejects the change, the recommended path is to start a new run from the current revision. Don't try to patch a frozen Worktree.

Step 4: Merge one at a time, in dependency order

Merge the inventory Worktree first, then the demand Worktree, then the exception Worktree. Never run two merges at once, even when Univer would accept them. Serializing them keeps the next step simple.

Step 5: Recheck assumptions after every merge

After each merge, compare every remaining manifest's base_revisions and reads against what just changed.

  • After the inventory merge, supply-plan has moved past r412. The demand agent read Stock, so its forecast caps may be wrong. Rerun it from the new revision.
  • The exception agent read Reorder, which depends on both Stock and Demand. If it ran before either merge, its output is stale no matter how good it looks. In practice, don't start it until both upstream merges finish, or treat any early run as a preview you throw away.

Univer won't detect this kind of semantic dependency for you. A forecast that depends on stock counts is knowledge only your orchestrator has.

Step 6: Deduplicate retries

Agents time out and get retried. Give every run a stable run_id. Have the agent write it somewhere checkable, such as a hidden column in the Exceptions rows or a footer line in the memo section. Before writing, the agent looks for its own run_id in the Worktree. If it finds it, the agent replaces the earlier output instead of appending. The orchestrator also refuses to merge a second Worktree for the same run_id.

When a merge lands in one Unit but not the other

The exception agent's Worktree changes two Units. Suppose mergeWorktree() reports the supply-plan Unit as merged and the exceptions-memo Unit as not merged. Because merging is not atomic across Units, this outcome can happen. The workbook now has new Exceptions rows, and the memo still describes last week.

A recovery plan for each Unit:

  1. Record the per-Unit results. Store which Unit merged, which didn't, and the resulting revisions. Don't summarize the run as "failed" or "succeeded."
  2. Don't remerge the workbook. Its change is already in place, and the run_id check prevents a duplicate.
  3. Decide whether the workbook change can stand alone. Here it can: the Exceptions rows are correct even if the memo lags. If your workbook change only made sense alongside the document change, plan to undo it with a new, reviewed change. You can use edit history to see exactly what landed.
  4. Rebuild the memo change from current state. Start a new Worktree for the memo only, based on its current revision. Regenerate the "This week" section from the merged Exceptions rows, not from the agent's earlier in-memory results.
  5. Review, freeze, and merge that single Unit.

Design agents so each multi-Unit change can tolerate this gap. Make the workbook the source of truth, and make the document derivable from it. A lagging memo is then an inconvenience, not a contradiction.

A test protocol before you trust it

Run this against copies of real files before giving agents production access.

TestHowPass condition
IsolationRun the inventory and demand agents in parallel WorktreesMain documents unchanged until merge
FreezeCall markReady(), then attempt an editEdit rejected; frozen revision unchanged
Scope overlapSubmit two manifests claiming the same rangeOrchestrator refuses to start the second run
StalenessStart the exception agent before upstream mergesOrchestrator blocks its merge and schedules a rerun
RetryKill the exception agent mid-run and retry with the same run_idExactly one set of Exceptions rows and one memo section
Partial mergeInject a not-merged result for the memo Unit into your orchestrator's merge handlerRecovery runs for the memo only; workbook not remerged
CalculationRead back Reorder after each mergeValues match a hand-computed fixture
RenderRender the workbook and memo after the final mergeNo broken layout or formula errors visible

The partial-merge test exercises your code, not Univer's. Stubbing the result lets you test the recovery path without needing to trigger a real failure.

What Univer provides, and its limitations

What Univer provides:

  • An Apache-2.0 open-source core.
  • Commercial features: real-time collaboration (OT), edit history, the server-side Worktree, and XLSX conversion (pricing).
  • A CLI and skill that let an existing agent read and edit spreadsheets, documents, and presentations, recalculate, read back results, and check renders (agents).
  • Worktree drafts that accept edits, markReady() to freeze a revision, and mergeWorktree() to merge Units one at a time and report a result for each (docs).

Limitations to plan around:

  • The Worktree, edit history, and OT collaboration aren't in the open-source core. Commercial plans are priced by capacity, based on collaborative connections and monthly exports (pricing).
  • A merge that spans several Units is not atomic across them.
  • Univer doesn't resolve semantic conflicts between agents. It doesn't know that one agent's forecast depends on another agent's stock counts.
  • Don't count on accepting or rejecting individual cells during review. Design review at the level of a whole Worktree.
  • Manifests, dependency ordering, staleness checks, and retry deduplication are your responsibility.
  • Real-time collaboration suits people and agents editing a live document together. When agent output should be reviewed before it reaches shared files, the Worktree flow fits better.

FAQ

Is a worksheet the same as a Unit?

No. A Unit is a whole document, such as a workbook, a text document, or a presentation. Worksheets are sheets inside a workbook Unit. Changes to several sheets of one workbook are changes to one Unit.

Can two agents edit different sheets of the same workbook at the same time?

Yes. Give each agent its own Worktree and declare non-overlapping output ranges. Merge them one after the other, then check whether the second agent read anything the first one changed.

What happens if a merge only partly succeeds?

If the Worktree touches several Units, some Units can merge while others don't, because the merge isn't atomic across Units. Use the result for each Unit to rebuild only the missing changes from current revisions.

Does Univer automatically resolve conflicts between agents?

No. It doesn't resolve semantic conflicts automatically. Prevent them with declared output scopes, dependency ordering, and reruns after upstream merges.

Do I need a commercial plan for this workflow?

The isolation, freeze, and merge steps rely on the server-side Worktree, which is a commercial feature. The open-source core alone doesn't include it.

To connect an existing agent to these files, see Univer for agents.