Anatomy of an Always-On Agent: Five Core Components

    This article breaks down the architecture of an always-on agent into five core components: an event inbox, a scheduler, layered memory, a permission model with an outbox, and the run/session execution model. It explains how these parts work together to make continuous operation crash-recoverable, deduplicated, and auditable, and offers practical implementation guidance for each component.

    Anatomy of an Always-On Agent: Five Core Components

    In agent engineering, a question comes up constantly: what actually makes a framework “good”? The answer rarely depends on how long the feature list is. It depends on whether the framework breaks down the problem of continuous operation clearly enough. A recent architecture write-up on always-on agents from a cloud vendor’s engineering team offers a transferable, general-purpose model: it skips the specific product and talks only about the parts. Building on that, this article presents a neutralized, expanded architecture guide with practical implementation notes.

    1. Two Basic Units First: run and session

    To understand what “always-on” means, you have to drop the “one question, one answer” intuition and adopt two basic units.

    • run (a single execution): receives one event, does the corresponding work, persists the state produced along the way, and then ends.
    • session (a conversation): the complete record of a conversation, including all messages and the tool-call trace. A run executes inside a session.

    The relationship can be summarized like this: a run is a short-lived compute unit, and a session is a long-lived state container. When a run ends, the agent goes dormant and consumes no compute. When the next event arrives, the scheduling layer decides whether to resume the existing session or open a new one.

    “Always online” does not mean letting a process occupy resources indefinitely. It means repeating this short loop — event arrives, wake a run, persist to disk, go dormant — frequently and reliably. With that in mind, all five components share a single evaluation standard: any component that cannot guarantee crash recovery and a single source of truth for state is not good enough.

    A schematic state flow:

    1. def handle_event(event):
    2. session = store.get_or_create(event.session_id)
    3. with lock(event.inbox_key): # ensure a single active worker per inbox
    4. for e in inbox.pull_pending(): # the inbox is the single source of truth
    5. result = run_once(session, e)
    6. session.append(result)
    7. store.save(session) # persist first, then acknowledge
    8. inbox.ack(e)

    2. The Event Inbox: Collapsing Many Trigger Sources into One Queue

    An ordinary agent has exactly one trigger source: the user message. An always-on agent has many: webhook callbacks, scheduled jobs, background tasks, and callbacks from another agent all count. If every source calls the agent directly, two typical failures appear: when concurrent events arrive at once, multiple runs start and fight over the same state; and when the process crashes, events are simply lost.

    So you need an inbox layer in between: all sources only write, and the worker only reads. In practice this is usually a persistent table, an HTTP endpoint responsible for writes, and a background worker that polls or subscribes. Four implementation points:

    1. The write side must return quickly. Many event providers treat a slow response as a failure and keep resending, so deep validation (prompt-injection detection, content-compliance checks) should run inside the run.
    2. The inbox is the single source of truth. When the worker wakes up, it queries the table for the latest events rather than relying on in-memory state or a message broker’s temporary cache.
    3. Only one active worker is allowed per inbox at any given time. Implement this with a distributed lock or lease mechanism to avoid duplicate execution and state overwriting.
    4. Pending events should be coalesced. If a user sends three messages in a row, they should be merged into a single run with a single reply, which saves compute and avoids garbled responses.

    3. The Scheduler: Letting the Agent Remember “I Have Something to Do”

    The inbox handles “something outside wants to reach you.” The scheduler handles “you have something to do yourself.” It comes in two types:

    • follow-up (one-time): a deadline the agent sets for itself, such as checking back in three days on whether a proposal was accepted; it terminates once marked complete.
    • schedule (recurring): a fixed-cadence loop, such as generating a daily report at 8 a.m. every morning; after this run completes, the next due time must be advanced.

    The key design constraint: the scheduler does not initiate a run itself. It keeps its own table, decoupled from the inbox. After the scheduler scans for due items, it only posts an event to the inbox, which the unified worker then consumes. This leaves a single wake-up path, so permissions, auditing, and rate limiting only need to be implemented in one place.

    4. Memory: Layered Storage and Write Strategy

    Memory is the dividing line between an always-on agent and an ordinary script. Organize it in three layers:

    • Short-term memory: the messages and tool-call trace of the current session, persisted along with each run.
    • Working memory: structured summaries that span runs, such as user preferences and current task state, usually kept in a relational or document store.
    • Long-term memory: retrievable vectorized fragments, combined with keyword search for hybrid recall.

    On the engineering side, emphasize “persist first, then acknowledge” and “idempotent writes,” and tag each memory with its source and timestamp to make conflict resolution and retrospection easier.

    5. Permissions and the Outbox: A Controllable, Auditable Output Boundary

    The biggest risk of an always-on agent is not weak capability but excessive permissions. Apply the principle of least privilege: authorize tools at session granularity, route sensitive operations into a human-approval queue, and keep credentials in a key management service rather than in prompts or code.

    The outbox is the single exit for all outbound output, symmetric to the inbox: a run only writes pending content to the outbox, and a separate dispatcher handles sending, retries, and rate limiting. The benefit is that jitter in an external channel cannot take down the main flow, and every outbound statement has a complete audit record.

    6. Conclusion

    Back to the original question: the standard for a good agent framework is not the number of integrations, but whether it turns the five parts — events, scheduling, memory, permissions, and output — into a recoverable, deduplicated, auditable closed loop. General-purpose capabilities on cloud platforms such as Baidu AI Cloud — persistent storage, message queues, container platforms, key management, and monitoring and alerting — can directly support the components above, letting teams focus their energy on business logic instead of infrastructure.