Five Core Components for Building Always-On Agents

    This article explains how to build an always-on AI agent by assembling five core runtime components: an event inbox, a scheduler, memory, permissions, and an outbox. It first defines the two basic units, run and session, then details how each component works, including single-active-worker constraints, event merging, follow-ups versus recurring schedules, gated long-term memory, approval holds for high-risk actions, and reliable delivery. It also recommends a practical build order and observability practices, showing that "always online" is not an idle infinite loop but a short wake-execute-sleep cycle repeated reliably.

    Five Core Components for Building Always-On Agents

    Many teams hit the same wall after shipping their first conversational agent: it is only alive when the user sends a message. The moment the user closes the window, it loses all memory; with no one prompting it, it never takes the initiative to do anything. An agent that can genuinely own business responsibilities must be able to wake itself up, remember things on its own, and come back to ask you for permission. Getting past this wall does not depend on swapping in a stronger model. It depends on completing the runtime structure.

    This article answers one question: what parts make up an agent that runs continuously?

    1. Two Basic Units: run and session

    Understanding always-on operation starts with two minimal concepts.

    A run is one complete unit of work. It is woken by an event, receives input, calls the model and tools, writes intermediate conclusions and the final result to storage, and then ends. A run has a clear start and termination. It is the smallest scheduling unit that can fail, be retried, and be observed.

    A session is a complete record of a stretch of context. It contains all messages in that conversation, tool calls and their returns, and intermediate conclusions. A run executes on top of a session: one session can carry multiple runs.

    The relationship can be summarized this way: when a run ends, the agent goes dormant; when the next event arrives, the scheduling layer decides whether to continue an existing session or create a new one. The decision usually depends on whether the session identifier continues, whether the context is still relevant, and whether the interval since the last interaction exceeds a business-defined window.

    “Always online” does not mean a process spinning in an infinite loop. It means repeating the short cycle of “wake, execute, sleep” many times. This perspective matters: it turns the always-on problem from “how to keep a process alive” into “how to reliably wake up again and again,” and the latter is a problem that mature engineering practices can solve.

    2. The Overall Skeleton: Five Core Components

    A usable always-on agent has a skeleton made of five components:

    1. Event inbox: receives trigger signals from all directions;
    2. Scheduler: reminds the agent that there is still work to do;
    3. Memory: retains facts and conclusions across runs and sessions;
    4. Permissions: requires human or policy confirmation for high-risk actions;
    5. Outbox: delivers results reliably, without duplication or loss.

    Each is described below.

    3. Event Inbox: Turning “Something Outside Needs You” into a Reliable Queue

    An ordinary agent has only one trigger source: user messages. An always-on agent has mixed trigger sources: callbacks from external systems, scheduled jobs, background job completion notifications, and delegation results from another agent all count as events.

    The most intuitive approach is to let each source call the agent directly. This works under light traffic, but it has two hard flaws: when two events arrive almost simultaneously, two runs start and compete for the same context; once the process crashes, the event being processed vanishes with no record to trace.

    So an inbox layer must sit in the middle. All sources are only responsible for writing to the inbox, and workers are only responsible for reading from it. In implementation, it is usually a persisted table: a handler writes to it, typically an HTTP endpoint; a background worker polls or subscribes to consume it.

    Four practices determine whether this structure is reliable.

    The handler must return quickly. Many event providers treat slow responses as failures and keep resending, which creates duplicate events and traffic amplification. Deep validation, such as input security checks and prompt injection protection, should happen inside the run rather than being pushed into the handler.

    The inbox is the single source of truth. After a worker is woken, it first pulls the latest events from the table instead of relying on in-memory variables or a snapshot passed by the caller. That way, if a worker dies halfway through execution, a newly started worker can still pick up the event and retry.

    Only one active worker is allowed on the same inbox at any moment. This is the key constraint that prevents two runs from doing duplicate work or overwriting the same context. In implementation, you can use lease-based acquisition: when a worker starts, it tries to acquire the lock and write an expiration time, and exits on its own if lease renewal fails.

    The worker must merge pending events. If a user sends three messages in a row, they should be merged into one run with a single reply, rather than queued and executed three times to produce three contradictory responses. The merge strategy can aggregate by a window per session, or define discardable intermediate states by event type.

    An illustrative table structure and consumption logic:

    1. CREATE TABLE inbox (
    2. id BIGSERIAL PRIMARY KEY,
    3. session_key TEXT, -- NULL means a new session is needed
    4. source TEXT NOT NULL, -- event source type
    5. payload JSONB NOT NULL,
    6. status TEXT NOT NULL DEFAULT 'pending', -- pending/running/done/failed
    7. attempts INT NOT NULL DEFAULT 0,
    8. lease_until TIMESTAMPTZ,
    9. created_at TIMESTAMPTZ NOT NULL DEFAULT now()
    10. );
    1. def worker_loop():
    2. while True:
    3. if not try_acquire_worker_lock(): # single active worker globally
    4. sleep(1); continue
    5. batch = fetch_pending(limit=50) # single source of truth
    6. for group in merge_by_session(batch):
    7. run = create_run(group) # one run handles a group of events
    8. try:
    9. run.execute()
    10. mark_done(group)
    11. except Exception as e:
    12. mark_failed(group, e) # preserve the scene and wait for retry
    13. sleep(0.5)

    4. Scheduler: Letting the Agent Remember Work on Its Own

    The inbox solves external driving; the scheduler solves self-driving. It also comes in two types.

    A follow-up is a deadline the agent sets for itself. For example, coming back in three days to ask how the proposal is going. It is one-time and ends once marked complete.

    A schedule is a recurring task at a fixed cadence. For example, generating a daily report at eight every morning. It is periodic, and after each completion the due time must be advanced to the next cycle before waiting again.

    Two easy pitfalls need emphasis. First, the scheduler does not initiate a run itself; it only writes an event to the inbox when something is due, and the worker still consumes it uniformly. This decouples scheduling logic from execution logic, so retry, rate limiting, and the single-active constraint exist in only one place. Second, the scheduler must be stored in a separate table from the inbox, because their lifecycle semantics differ: the inbox records “facts to be processed,” while the scheduler records “future intent.” Mixing them makes cleanup and retry strategies interfere with each other.

    5. Memory, Permissions, and Outbox: Making Always-On Truly Usable

    Memory needs layers. Message history within a session handles coherence; long-term memory across sessions stores confirmed facts, preferences, and decision conclusions. The key principle is that writes must have a threshold: only verified information or information the user explicitly confirms is promoted to long-term memory; otherwise noise keeps polluting the judgment of every subsequent run.

    Permissions are the most essential difference between an always-on agent and a one-off script. Since it can wake itself up, it must be able to stop itself and ask for authorization. A workable approach is to define high-risk actions as operations that require confirmation: when a run reaches such a step, it creates a pending-approval record and suspends, sends the request through the outbox, and resumes execution after a confirmation event arrives. A policy-layer auto-approval allowlist should also be kept so that low-risk actions do not block the flow.

    The outbox handles delivery reliability. A run does not call external channels directly; it writes the message to be sent into the outbox, and a separate dispatcher handles sending, retry, and deduplication. That way, even if a downstream channel is briefly unavailable, it will not cause the whole run to roll back and rerun.

    You do not need to build everything at once. The recommended order is “inbox and single active worker → outbox → scheduler → permission hold → long-term memory”: first make the wake-up path reliable, then gradually add autonomy. Every stage should ensure observability: each run has a unique identifier, every state transition is logged, and failures can be traced back to a specific event.

    When deploying on the cloud, general-purpose capabilities are available for these components: persisted tables can go to a relational database, event buffering can use a message queue, scheduled triggering can use a scheduling service, permission approval can integrate notification and form capabilities, and logs and metrics can go to logging and monitoring/alerting services. When choosing, prioritize delivery semantics, retry mechanisms, and lease support rather than whether the interface is convenient.

    The complexity of an always-on agent never comes from the model; it comes from the runtime. Define run and session clearly, draw the boundaries of the five components, and “always online” becomes nothing more than a short cycle repeated reliably many times.