Solving Long-Context Forgetting with Multi-Agent Collaboration
This article explains how long-context forgetting undermines coding agents and presents a multi-agent alternative built around a coordinator, a shared append-only bulletin board, targeted wake-up and sleep, and channel isolation. It covers how each mechanism preserves early constraints, reduces token waste, and supports recovery after context compression, along with practical guidance for deploying and measuring such a system on Baidu AI Cloud.
1. Why Long Context “Eats” Constraints
As coding agents move from single-file edits to cross-module refactoring, the conversation context keeps growing. When the context approaches the window limit, the system usually compresses or summarizes earlier content—and what gets compressed away is often the coding standards, directory conventions, and acceptance criteria defined at the start. As a result, the agent “forgets” the upfront constraints later on, leading to style drift, repeated changes, or even reverting work that was already completed. A single-session, serial workflow also makes debugging, testing, and implementation block one another, limiting overall throughput.
2. From Serial Sessions to a Coordinator Model
One practical improvement is to layer session roles: the current session no longer writes code itself but becomes a coordinator that only decomposes tasks, dispatches them, reviews results, and makes decisions. Implementation, debugging, and testing are handled by dedicated members. The coordinator stays lightweight and can receive new instructions and adjust the plan at any time. A sketch:
coordinator: decompose tasks -> create bulletin board -> dispatch #1├─ implementer: claim #1, produce change summary -> #2├─ reviewer: verify #2, return conclusion -> #3└─ tester: run validation, report result -> #4
3. Shared Bulletin Board: A Recoverable State Thread
The bulletin board is a shared log that all members append to in order, recording claimed tasks, change summaries, and validation conclusions, and it is retained long term. Its value is threefold: first, after a member goes through context compression, it can read forward from a specified sequence number to rebuild its working state; second, handoffs only reference message sequence numbers, avoiding repeated copying of entire reports into new messages; third, the whole process is traceable, making it easy to revisit the basis for a given decision.
4. Targeted Wake-Up and Sleep: Spend Tokens Where They Matter
Idle members go to sleep and consume no quota; they are woken only when named. Handoffs should therefore notify only the peer that needs to act next, avoiding the pointless overhead of waking everyone. A practical convention: a wake-up message must include the target sequence number and a clear action, for example, “Please verify the consistency of #4 and #6.”
5. Channel Isolation and Scale Control
When the team grows or a task spans multiple independent modules, you can create separate channels: the public channel keeps only cross-module decisions, while in-module communication happens in sub-channels to reduce noise. It is advisable to limit the number of members per channel and to define the owner and deliverables for each channel.
6. Implementation Recommendations
When building such a system on Baidu AI Cloud, you can persist the bulletin board to object storage or a logging service, use a message queue to deliver wake-up events, run each member’s runtime on a container platform, and use monitoring and alerting to observe token consumption and task latency. Key metrics include constraint retention rate, rework rate, token cost per task, and end-to-end duration; use continuous measurement to iterate on the scheduling strategy.
