A New Approach to Multi-Agent Collaboration: How a Two-Layer Architecture Prevents Context Gaps

    Multi-agent systems must balance two competing goals: parallel execution and continuous context. This article explores a two-layer architecture that separates interaction and coordination from task execution, using thread-based message associations to preserve context without sacrificing concurrency. It also examines the remaining challenge of long-term memory across completed sessions and the architectural principles that follow from this design.

    The Context Challenge in Multi-Agent Collaboration

    When building agent systems for software development, a common goal is to let multiple agents handle different tasks at the same time and improve overall efficiency. In practice, however, parallel execution and continuous context are naturally in tension.

    A Typical Scenario

    Consider the following workflow. A developer asks an agent in a team chat to modify code according to Approach A. The agent completes the changes and submits a code change request. Later, the developer leaves a comment on the code review page:

    “Let’s use Approach B instead.”

    A human collaborator can quickly understand what this means. The comment revises an earlier decision. The collaborator can combine the original request from the team chat with the current code changes, reassess the direction, and communicate the updated approach to the person or system still working on the task.

    For an automated system, this is much more difficult. The team chat message and the code review comment may have triggered two separate sessions. If the system cannot associate them, the developer must explain the entire background again. That undermines much of the value of automation.

    What Session Granularity Determines

    The root cause is often the granularity of sessions.

    • Coarse-grained sessions: All messages enter the same session. This provides strong context continuity. The agent can see the full decision chain, understand how the original approach was selected, and recognize subsequent changes. The drawback is that when multiple tasks arrive concurrently, execution logs, user instructions, and task results become interleaved. Tasks may be processed in sequence, significantly reducing parallelism.

    • Fine-grained sessions: Each task runs in its own session. Tasks can be processed independently, which improves parallel efficiency. However, when two tasks share a decision, or when a user adds information through another interface, the system may have no mechanism to route that message to the correct session. Developers are often forced to perform this routing manually by maintaining multiple conversation windows and repeatedly supplying missing context.

    This is the central trade-off in session design:

    The finer the task separation, the higher the potential parallelism—but the harder it becomes to maintain context across related interactions.

    A Practical Architecture: Separating Interaction from Execution

    One way to address this conflict is to divide the system into two layers.

    The Upper Layer: Interaction and Coordination

    The upper layer receives messages, assigns tasks, and coordinates work across tasks. It serves as the entry point for all user interactions, including team chat tools and code collaboration platforms.

    After receiving a message, it determines which task the message belongs to, whether a new task should be created, or whether the message should be forwarded to an execution unit that is already handling related work.

    Its core workflow can be summarized as follows:

    1. Receive message → Identify intent and task ownership → Make routing decision
    2. ├─ New task → Create execution unit
    3. └─ Existing task → Forward to the related execution unit

    The Lower Layer: Independent Execution

    The lower layer consists of multiple execution units. Each unit handles a specific task in its own session and working directory. Because the units are isolated from one another, they can operate in parallel without interfering with each other.

    A Key Optimization: Thread-Based Association

    If every follow-up message—for example, every comment on a code change request—must be evaluated individually by the upper layer before being forwarded, the coordination layer itself may become a bottleneck. The time saved through parallel execution could be lost while tasks wait for message routing.

    A more effective approach is to introduce the concept of a thread. All comments associated with the same code change request, or all messages belonging to the same topic in a team chat, are organized into one logical thread.

    The upper layer performs the initial assignment for the first message. After that, the lower-level execution unit subscribes to the thread. Subsequent messages associated with the same thread can be delivered directly to that execution unit instead of being routed through the upper layer each time.

    This allows the upper layer to focus on cases that genuinely require coordination, such as:

    • Identifying a completely new task and creating an execution unit;
    • Handling decisions that involve relationships between multiple tasks, such as when the result of one task changes the direction of another;
    • Processing ambiguous input that cannot be associated with an existing thread.

    An Unresolved Challenge: Long-Term Memory Across Sessions

    Thread-based association works well for maintaining context within the same topic. It does not fully solve problems that span a longer period.

    Consider a task that has already been completed and archived—for example, the code has been merged. A week later, the user starts a new session and says, “Use the approach we agreed on last time.”

    The system must then be able to:

    1. Identify the reference: Determine which project and discussion the phrase “last time” refers to;
    2. Reconstruct the historical decision: Retrieve the relevant discussion and the approach that was ultimately selected;
    3. Connect the decision to the new task: Apply the historical decision correctly to the newly initiated work.

    This is fundamentally a long-term memory problem across sessions. It involves decisions such as which information should be retained, how long it should be stored, and what conditions should trigger retrieval.

    There is currently no universally accepted technical pattern for this problem. Different teams are exploring various approaches to memory structures, retrieval strategies, and forgetting mechanisms, and the field is still evolving rapidly.

    This also explains the practical value of the two-layer architecture. The upper layer can focus on maintaining relationships between tasks, while each lower-level execution unit retains only the local context required for execution. This separation leaves room for a long-term memory capability to be added later.

    A memory system could operate as an independent module and provide historical decision retrieval to the upper layer without requiring changes to the internal logic of every execution unit.

    Architectural Lessons

    Several broadly applicable principles can be derived from this approach to multi-agent system design.

    Separation of responsibilities is better than combining unrelated responsibilities. Dividing message routing and coordination from task execution gives each layer a clearer objective and makes it easier to optimize and extend them independently.

    Structured associations are better than manual context reconstruction. The core purpose of threads is to turn context transfer—previously performed manually across multiple windows—into a relationship that the system can maintain automatically.

    This principle is also relevant when building enterprise-grade agent orchestration systems. Regardless of the underlying cloud infrastructure, the same layered coordination model remains useful. Object storage can be used to archive historical conversation data, message queues can decouple upper-layer routing from lower-layer execution, and logging services can track task execution chains.

    Long-term memory is a natural extension of system capabilities, not merely an add-on feature. Once a system has a clear mechanism for maintaining relationships between tasks, adding a memory module becomes a natural next step rather than an entirely separate effort.

    Conclusion

    The choice of session granularity directly determines how a multi-agent system balances parallel efficiency against context continuity. Separating interaction and coordination from task execution, combined with thread-based message association, can preserve parallelism while reducing the collaboration costs caused by context gaps.

    Long-term memory across sessions remains a more complex extension. Its storage and retrieval strategies must be adapted to specific business scenarios, making it an important area for continued exploration as agent systems move toward production use.