Moving State Out of Framework Memory: A Multi-Agent Architecture Refactoring Guide

Refactoring multi-agent systems by externalizing state to email threads for efficiency and resilience.
Multi-agent systems often waste 70% of their memory graph on non-reasoning housekeeping tasks. This article presents a refactoring approach that moves state out of framework memory into email threads, leveraging decades-old SMTP/IMAP protocols for persistent, auditable, and resilient agent communication—dramatically improving token efficiency and fault tolerance for long-running workflows.
Introduction: The Hidden Burden of Multi-Agent Systems
When building complex multi-agent pipelines, developers often encounter a hidden yet severe performance bottleneck. A deep analysis of the state payloads in these systems reveals a startling fact: approximately 70% of the memory graph isn't used for actual reasoning or task execution—it's consumed by "housekeeping" tasks.
The memory graph here refers to the graph-structured data used in multi-agent frameworks to represent inter-agent relationships, execution states, and data flows. In typical agent orchestration frameworks (such as LangGraph, CrewAI, etc.), this graph structure carries dependency relationships between nodes, conditional branching logic, and intermediate runtime results. As system scale grows, graph complexity increases exponentially.
These housekeeping tasks include: tracking transport state, validating tool execution results, passing user IDs, and reassembling multi-day conversation histories after script restarts. In other words, we're painstakingly rebuilding a message queue system inside the framework's context.

This approach is not only bloated—it triggers a cascade of problems including token waste, poor maintainability, and fragile stability. This article explores a creative refactoring approach: moving state entirely out of framework memory.
The Root Problem: Why Agent Frameworks Are Reinventing the Wheel
State Management Bloat
Modern agent frameworks (such as various Agent Graph orchestration tools) typically store all intermediate state in the framework's own memory structures. For simple, short-lived tasks, this works fine. But once you're dealing with asynchronous, long-running workflows, the problems become apparent.
Every state transfer must carry a large amount of metadata unrelated to business logic. This data flows back and forth between agents, filling the context window with irrelevant information. When your task spans multiple days or needs to continue after a service restart, persisting this state becomes a thorny engineering challenge. In the distributed systems domain, these problems have long had mature solutions—message queues (like RabbitMQ, Apache Kafka) provide asynchronous communication, persistent delivery, and backpressure control, while Event Sourcing patterns achieve complete state traceability and point-in-time reconstruction by recording immutable event sequences. Agent frameworks, however, are reimplementing low-grade versions of these capabilities in their own memory.
The Token Efficiency Disaster
The most direct cost manifests in token consumption. When state is stuffed into every payload, the LLM must "read" this redundant information with every call. This not only increases API costs but may also dilute critical information due to excessive context length, degrading reasoning quality.
It's worth noting that while LLM context windows continue to expand (from GPT-3's 4K to GPT-4 Turbo's 128K tokens), research shows that models exhibit a "Lost in the Middle" phenomenon—attention to information in the middle of long contexts drops significantly. This means that even if more tokens can technically fit, stuffing irrelevant state information into the context still substantively reduces the model's reasoning accuracy on key task information. Meanwhile, at GPT-4-level pricing, the cumulative cost of redundant tokens becomes quite substantial in high-frequency call scenarios.
The Refactoring Solution: Using Email Threads as Agent State Memory
To address these pain points, an unconventional but clever solution has emerged in the community. The core idea: don't manage long-lived state inside the framework—leverage external, mature persistence protocols instead.
Core Implementation Approach
The specific refactoring steps are:
- Strip out heavy state graphs: For asynchronous, long-running workflows, eliminate the framework's internal heavyweight state graph structures entirely.
- Assign each sub-agent an independent mailbox: Use services like
agentmail.toto provide each Sub-Agent with an isolated email endpoint for message routing. - Let email threads serve as persistent memory: Leverage the natural chronological ordering and persistence of standard email threads as the state storage medium for agents.
The elegance of this approach lies in the fact that email itself is a highly reliable asynchronous messaging system validated over decades. It natively supports threaded conversations, persistent storage, and cross-system routing—precisely the complete set of characteristics needed for long-running multi-agent collaboration. From the technical protocol layer, SMTP/IMAP protocols have undergone decades of engineering refinement since the 1980s, featuring global-scale interoperability, built-in retry mechanisms, and standardized thread identifiers (via Message-ID and In-Reply-To headers). These properties map directly to the reliable delivery, message correlation, and asynchronous response capabilities required for agent communication.
Architecture Comparison: In-Memory State vs. Externalized State
The traditional approach is "pack everything into memory," while the new approach is "externalize state to the email system." The former is like spreading all your files across your desk; the latter is like filing documents into an organized inbox, retrieving them when needed.
Three Core Benefits of State Externalization
1. Significant Token Efficiency Gains
This is the most obvious benefit. Since context becomes on-demand rather than fully transferred every time, agents only retrieve historical emails when truly needed. This means the input to each LLM call becomes lean, directly reducing token costs and latency. This pattern is essentially similar to the RAG (Retrieval-Augmented Generation) philosophy—rather than stuffing all information into the prompt, retrieve relevant fragments and inject them into context when needed.
2. Native Auditability
Once execution steps are recorded as email threads, the entire execution flow becomes naturally human-auditable. Developers or operations staff can open the mailbox and clearly see what each sub-agent did and what information was passed, just like reading a chain of correspondence. The value of this "transparency" for debugging complex agent systems is immeasurable—it completely solves the pain point of black-box reasoning being difficult to trace.
3. Built-in Resilience
Since state is persisted in the email system rather than volatile process memory, state automatically recovers after script restarts. This means even if a service crashes or a machine reboots, long-running tasks in progress won't lose their context. This resilience is critical for long-cycle workflows in production environments. In traditional distributed systems, achieving similar fault tolerance typically requires introducing checkpoint mechanisms, Write-Ahead Logs (WAL), or distributed state stores (like Redis, etcd), while email systems naturally provide equivalents of these capabilities.
Applicable Scenarios and Potential Trade-offs
While elegant, this approach deserves a balanced evaluation.
Applicable scenarios: It's best suited for asynchronous, long-cycle, loosely-coupled workflows. For example, tasks requiring external approvals, data processing spanning multiple days, or tasks involving multi-party collaboration. In these scenarios, the email system's latency characteristics aren't just acceptable—they actually align with the natural rhythm of the business.
Potential trade-offs: For real-time agents requiring low latency and high-frequency interaction, email's inherent latency may become a bottleneck. Additionally, externalizing state introduces dependency on third-party services (like agentmail.to), requiring consideration of their availability and security. Structured parsing of email content may also introduce additional engineering complexity.
From a broader perspective, this approach reveals an important architectural principle: don't re-implement in your framework what infrastructure has already solved. Message queues, persistent storage, event sourcing—these are solutions from mature domains. Agent frameworks should focus on reasoning and orchestration, delegating state persistence to specialized components. This principle aligns with the Unix philosophy of "do one thing well" and the Single Responsibility Principle in microservices architecture.
Conclusion
The idea of "moving state out of framework memory" is essentially applying classic software engineering principles to the emerging field of agent development. It reminds us that while pursuing LLM capabilities, the fundamentals of architecture design—separation of concerns, single responsibility, leveraging mature infrastructure—remain the cornerstones of building reliable systems.
Regardless of whether you ultimately choose email as the carrier, this refactoring philosophy of "lightening the load on agents and slimming down context" deserves deep consideration from every AI engineer.
Key Takeaways
Related articles

GitHub Daily · August 4th: Uber Open-Sources AI Agent Security Framework, Enterprise-Grade Agent Protection Takes Center Stage
Uber open-sources ADR, an enterprise AI Agent security framework gaining 140 stars in one day. Plus webpack, Deno, Angular, Tailwind CSS hold steady.

PassiveShorts Review: AI Auto-Generates Short Videos and Publishes to TikTok and YouTube
In-depth review of PassiveShorts, an AI faceless short video generator covering topic selection, scripting, voiceover, captions, and auto-publishing to TikTok and YouTube.

Murmell: A Cloud Canvas Tool for Multi-AI Agent and Team Collaboration
Murmell is a cloud-first AI collaboration tool supporting Claude Code, Codex and other agents running simultaneously, using file claiming to resolve conflicts, with all output committed to Git.