AI agents

Architecting always-on agents with event inboxes and durable memory

A technical breakdown of the five core primitives required to build stateful, proactive AI agents that operate across multiple sessions without constant supervision.

Illustration of a digital hourglass on a server rack representing timed agent runs and secure data storage.
Illustration generated for this article

The concept of always-on artificial intelligence agents is gaining traction as model capabilities improve and costs decrease. These systems do not run continuously but instead wake up periodically to process events, execute tasks, and return to a dormant state. This architectural shift allows software to act proactively rather than just reacting to direct user prompts.

Recent advancements in large language models have made this approach more viable by improving judgment and reducing the cost per task for long-horizon work. For instance, newer models have demonstrated significant cost reductions on complex coding benchmarks compared to their predecessors. Developers are now exploring how to integrate these persistent, stateful behaviors into their products, moving beyond simple chat interfaces to autonomous workflows.

What happened

Always-on agents are defined by their ability to maintain context across disjointed sessions and take action without immediate human oversight. While they appear to be constantly active from a user perspective, the underlying system operates in cycles. Each cycle, known as a run, begins when an event triggers the agent, proceeds through task execution, and ends with the agent saving its state before sleeping again.

The architecture supporting these agents relies on five specific primitives: an event inbox, timers, memory, permissions, and an outbox. These components manage when the agent wakes up, what information it retains, and how it interacts with external systems safely. The design prioritizes durability and safety, ensuring that events are not lost during crashes and that sensitive actions are properly controlled.

This structure separates the trigger mechanism from the execution logic. Instead of external services calling the agent directly, which can lead to race conditions or data loss, events are queued in a durable store. A background worker then processes these events sequentially or in batches, ensuring that the agent’s state remains consistent and that no work is duplicated or missed due to transient failures.

How it works

The event inbox serves as the central nervous system for incoming triggers. It consists of a durable database table, an HTTP handler, and a background worker. When an external source sends a webhook or a scheduled task fires, the handler writes the event to the database and acknowledges receipt quickly. This prevents the source from timing out while allowing deeper validation to occur later during the run.

The worker polls the inbox for pending events. If multiple events arrive for the same user, the worker can batch them into a single run to improve efficiency. Crucially, only one worker should be active per inbox at any time to prevent concurrent modifications. If a worker fails mid-run, another instance can pick up the unprocessed event from the database, ensuring reliability.

Timers enable proactive behavior by scheduling future actions. These are stored in a separate durable table and managed by a scheduler service. The scheduler scans for due timers, updates their status, and injects corresponding events into the inbox. This allows the agent to follow up on previous tasks or perform recurring duties like sending daily summaries without requiring constant external triggers.

Memory is handled through a file-based system mapped to durable storage. The agent loads user instructions, notes, past messages, and task progress files at the start of each run. To keep context windows manageable and costs low, only essential indexes are loaded initially, with detailed files retrieved only when needed. This separation ensures that critical information persists even if the worker restarts.

Key details

  • Always-on agents operate in discrete runs triggered by events, rather than running continuously.
  • The event inbox decouples event sources from the agent, using a database to ensure durability and prevent data loss.
  • Timers allow agents to schedule follow-ups and recurring tasks, injecting events into the inbox when due.
  • Memory is stored externally in files or objects, containing user preferences, task progress, and conversation history.
  • Permissions are managed via a credential proxy and auto-mode classifiers, with deferred tool calls for high-risk actions.
  • The outbox delivers final results to users, avoiding the need to stream every intermediate step of the reasoning process.

Why it matters

For software engineers building AI products, this architecture solves the reliability issues inherent in stateless chat interfaces. By treating events as durable records in a database, developers can ensure that no user request is lost due to network glitches or server restarts. This reliability is essential for professional tools where missing a task could have serious consequences.

The separation of memory from the immediate context window also addresses cost and performance concerns. As agents engage in longer conversations and more complex tasks, keeping all history in the prompt becomes expensive and slow. Externalizing memory allows the agent to maintain long-term context without bloating every single request, making the system scalable for heavy usage.

Furthermore, the permission model provides a necessary safety net for autonomous actions. By deferring high-risk tool calls and using proxies for credentials, developers can build agents that act on behalf of users without exposing sensitive data or performing dangerous operations unchecked. This balance between autonomy and control is critical for enterprise adoption.

What you can do

  • Implement a durable event inbox using a relational database to queue incoming webhooks and scheduled tasks.
  • Design a background worker that processes one inbox at a time to avoid race conditions and duplicate work.
  • Store agent memory in external files or object storage, loading only indexes into the context window initially.
  • Use a credential proxy to inject secrets into API requests, keeping tokens out of the agent’s direct environment.
  • Create a scheduler service that polls a timer table and injects due events into the main inbox.
  • Build an outbox mechanism to deliver summarized results to users instead of streaming raw reasoning steps.
  • #ai agents
  • #system architecture
  • #webhooks
  • #backend engineering
  • #llm ops

Tools from the Bytechap store

Keep reading

All stories