From monolithic AI to distributed intelligence: explore how the Model Context Protocol (MCP) and Agent2Agent (A2A) standards enable scalable Multi-Agent Systems
)
Long-Running AI Agents: Engineering Multi-Agent Systems for Extended Autonomous Operation
A guide to engineering long-running multi-agent systems that maintain reliability over extended autonomous operation through deliberate memory management, forgetting strategies, workflow orchestration, and token consumption optimisation.
From single-model configurations to orchestrated environments
AI system architectures have progressed significantly since 2023, moving from simple single-model configurations to complex orchestrated environments capable of sustained autonomous operation. The earliest AI deployments relied on a single large language model, responsible for every task within a conversation. This approach gave way to multi-agent systems, in which a planner agent distributes tasks between multiple agents, each possessing its own specialised skills and tools.
The most recent evolution is the long-running multi-agent system, where a planner agent iteratively distributes tasks across multiple agents over extended execution timeframes, introducing new challenges around memory, cost, and reliability. The transition to long-running agents brings distinct engineering challenges that do not exist in short-lived interactions. These challenges centre on context degradation, resource consumption, and workflow resilience.
Memory management in long-running agents
Effective memory management is fundamental to the success of any long-running AI agent system. As execution time extends, the context window becomes a critical resource requiring deliberate architectural decisions.
Three Types of Memory
Single-Agent Memory
All data that one agent needs to perform its assigned tasks within its own operational scope.Shared Memory
The collective data of the entire workflow that the planner has executed, accessible across agents.Long-Term Memory
Data that must be stored and retrieved across sessions, persisting beyond any single execution cycle.
Each memory type serves a distinct purpose in the overall architecture. Single-agent memory keeps individual agents focused and efficient. Shared memory enables coordination between agents working on related sub-tasks. Long-term memory provides continuity across sessions, allowing the system to build on prior work without repeating completed steps.
Four Critical Memory Issues
Context Rot
The overall decay of context quality and usefulness over time as the context window fills with accumulated information.Lost in the Middle
Positional bias where large language models underweight information positioned in the middle of long context windows.Memory Pollution
Contamination of the memory space with incorrect concepts acquired during execution, which then propagate through subsequent reasoning steps.Contextual Drift
The agent continues referencing outdated data because its memory has not been properly updated with current information.
These memory issues compound over time. In short interactions, they may be negligible. In long-running operations spanning hours or days, they can render the entire system unreliable. Context rot gradually erodes the foundation upon which all subsequent reasoning depends. The lost-in-the-middle effect means that critical information placed centrally within a growing context window receives diminishing attention from the model. Memory pollution is particularly insidious because once an incorrect concept enters the shared memory space, it propagates through subsequent reasoning steps and contaminates downstream agent outputs. Contextual drift creates a subtler failure mode, where the agent continues operating with apparent confidence whilst referencing information that no longer reflects the current state of the task.
Forgetting by Design: strategic memory reduction
Forgetting is not a failure mode but a mandatory engineering requirement. Implementing deliberate forgetting strategies ensures that long-running agents maintain context quality throughout their operational lifetime.
Compaction
Compaction is the periodic shrinking of interaction history. It preserves essential data while discarding anything that no longer contributes to task completion. This process can be triggered by time intervals, context window utilisation thresholds, or task completion milestones.
Results Clearing
As agents execute tools and accumulate intermediate outputs, these results quickly become outdated or redundant. Tool results clearing discards these outdated intermediate states and removes erroneous information that accumulated during tool execution, preventing it from influencing future reasoning.
Memory Shrinker Pattern
The Memory Shrinker pattern involves deploying a dedicated large language model running in the background, monitoring context window saturation percentage and performing automatic summarisation without loss of critical information. By assigning a separate model to continuously monitor and compress context, the primary agents maintain operational efficiency without manual intervention. The Memory Shrinker operates transparently, ensuring that the working agents never encounter context window limits that would force abrupt truncation or failure.
Workflow management for Long-Running Agents
The architecture of the orchestration workflow determines both the reliability and the cost profile of a long-running agent system. There is a significant difference between naive and well-engineered approaches.
Naive Approach vs. Well-Engineered Workflow
A naive approach carries low initial setup cost but results in high maintenance cost, excessive token usage, and increased risk of hallucinations and incorrect outputs. Without structured orchestration, agents operate without clear boundaries, duplicate effort, and consume tokens on unproductive reasoning loops.
A well-engineered workflow follows a structured cycle. Task input is first received and parsed by the planner agent, which then creates appropriate sub-tasks based on the input requirements. The planner handles agent spawning or selection for each sub-task, determining whether parallel or sequential execution should proceed based on task dependencies. Once agents produce their outputs, the planner evaluates results against quality criteria. At each iteration boundary, memory context is evaluated and shrinking is applied as needed. This entire cycle iterates until the desired output quality is achieved, creating a self-correcting loop that improves outputs progressively.
Essential Workflow Requirements
Three capabilities are essential for any production-grade long-running agent workflow. Checkpoints enable flow resumption after interruptions, avoiding the need to restart entire processes and preserving all progress made prior to the interruption. Error handling ensures graceful management of tool errors, server errors, and unexpected states without cascading failures that could compromise the entire execution chain. Human interaction capability provides the ability to pause execution, request human input, and resume based on guidance when uncertainty exceeds acceptable thresholds. This ensures that the system degrades gracefully rather than producing unreliable outputs when facing novel situations.
Token consumption optimisation
Controlling token consumption is essential for making long-running agents economically viable. Four complementary strategies address this challenge.
Different tasks require different model capabilities. Frontier models should be reserved for complex reasoning tasks, while smaller or locally hosted models handle simpler operations such as data formatting, classification, or routine extraction. This selective deployment reduces costs without compromising output quality where it matters most. The planner agent plays a critical role here, assessing each sub-task's complexity and routing it to the most cost-effective model capable of producing acceptable results.
Adaptive reasoning levels allow the system to calibrate computational intensity to task complexity. Low reasoning is appropriate for straightforward, well-defined tasks with minimal ambiguity. Medium reasoning suits tasks requiring moderate interpretation or multi-step logic. High reasoning is reserved for complex tasks demanding deep analysis and careful evaluation. By matching reasoning intensity to actual requirements, the system avoids spending expensive computation on tasks that do not benefit from it.
Caveman Prompting is a prompting strategy that eliminates large language model verbosity by enforcing minimal output formatting. This technique removes articles, courtesy reformulations, and unnecessary explanatory phrases from model responses. The name reflects the telegraphic communication style enforced on the model, prioritising information density over grammatical completeness.
The result is significantly reduced token output per interaction, which compounds into substantial savings across thousands of iterations in a long-running system. When every agent response across every iteration consumes fewer tokens, the cumulative effect on both cost and context window utilisation is substantial.
Render bulky, low-precision agent context (old chat turns, logs, repeated tool docs, large output) as images before sending it to the model. Vision tokens are priced and counted differently from text tokens, so a dense page rendered into a fixed-size image can be significantly cheaper than the equivalent plain-text token stream. This technique functions as lossy compression rather than summarisation. The visual form of the content is preserved, but model access becomes probabilistic: it may read the gist correctly, but it may misread a character that matters. Any value the agent will act on as an exact value (file paths, IDs, etc.) must stay in text. Compressible context comprises only information where overall orientation matters more than byte-perfect recall.
Teams adopting this need a context accounting layer (precision classes, recall checks, and source pointers) to guard against silent misreads. However, the economics are clear: images carry more context for fewer tokens, and that makes them the cheaper way to keep agents informed.
Sustaining efficiency in Long-Running Agent Systems
Memory management must be treated as a mandatory engineering requirement. Context rot, memory pollution, and contextual drift will compromise any long-running system that lacks deliberate forgetting strategies. The Memory Shrinker pattern, compaction, and tool results clearing together form a comprehensive approach to maintaining context quality over extended operation.
Workflow architecture deserves significant upfront investment. A robust planner agent avoids high recurring operational costs by preventing redundant processing, managing errors gracefully, and incorporating human interaction capability at critical decision points. The initial engineering effort pays dividends throughout the system's operational lifetime.
Token consumption optimisation requires a multi-pronged approach: selecting the appropriate model per task type, tuning reasoning levels to match complexity, and employing token-reduction prompting techniques. The overarching goal is to reduce costs and computational intensity while creating sustainable and trustworthy long-running agent solutions.
Blue Reply delivers long-running AI agent architectures incorporating memory management strategies, workflow orchestration, and token optimisation across multi-agent systems. The engineering teams work with organisations operating in different industries, implementing these patterns in production environments.
Frequently Asked Questions
Blue Reply is the Reply company providing system integration services and core modernisation for the insurance market, including Property & Casualty, Life Insurance, Claims Management, CRM, Bancassurance and Beyond Insurance (Property, Mobility, Health and Assistance). Combining strong process expertise with advanced technology capabilities, the company implements omnichannel applications for agents, employees, brokers, prospects and policyholders. Insurance-specific capabilities include the integration of portfolio management solutions, rating and pricing engines, and electronic signature services. The company has developed assets such as BlueScan and other platforms, covering policy quotation, sales, claims management and CRM. These incorporate conversational AI-powered workflows to enhance the digital experience and operational efficiency. The company is expanding the adoption of AI through recommendation engines, intelligent data acquisition, damage recognition and estimation solutions, and anti-fraud controls.