How to Choose an Always-On Agent Framework: Five Core Components
“Which agent framework is best?” is the wrong question for always-on agents. This article explains why task shape comes first, how runs and sessions differ from a permanently running process, and how five runtime parts—an event inbox, timers, memory, permissions, and an outbox—determine whether a long-lived agent stays reliable, recoverable, and controllable.
1. Ask the right question first: “best” depends on the task shape
On November 13, a cloud vendor published an engineering blog on how to build always-on agents. It was not a product review. It described the skeleton of a class of systems: an agent that can wake itself, keep its own record, and ask a human for permission when needed—and which parts that system is made of.
So “which framework is easiest to use” is a false question. A one-shot Q&A task can be a single in-process loop. A task that must stay online and react to external change is hard because of the runtime, not the model. Decide the task shape first, then compare frameworks.
2. Two basic units: run and session
To understand an always-on agent, separate two ideas.
- Run: one unit of work. An event arrives, the work is finished, what happened is written to storage, and the run ends.
- Session: the full record of a conversation, including every message and tool-call sequence. A run executes inside a session.
When a run ends, the agent sleeps and does not hold compute. When the next event arrives, the system must choose: continue the old session, or open a new one. Three checks decide that: whether the event is strongly related to the existing context; whether the context budget still has room; and whether isolation is needed to avoid contamination. “Always on” does not mean a process that never exits. It means this short loop is repeated many times.
3. Five core components
1. Event inbox: pull concurrency and reliability out of the business logic
A normal agent has one trigger: a user message. An always-on agent has many: external service callbacks, scheduled jobs, background work, and completion notices from another agent.
The naive approach is to let each source call the agent directly. Two events arriving together then start two runs that fight over the same state. If the process crashes, the event is gone. The correct pattern is an inbox in the middle: every source only writes to the inbox, and a worker reads from it. In practice this is usually a persistent table, an HTTP endpoint that accepts writes, and a background worker.
Four practical rules:
- Handlers must return quickly. Validate and persist only. Do not run business logic on the request path.
- Writes carry an idempotency key. A unique constraint on the event ID deduplicates naturally.
- Consumption uses a lease or visibility mechanism so two workers cannot claim the same event.
- Failures retry and then go to a dead-letter path. Events that exceed the limit enter a separate queue for human handling.
def handle_event(req):if not valid(req):return 400inbox.insert(event_id=req.id, source=req.source,payload=req.body, status="PENDING")return 202 # return immediately; the worker does the workdef worker_loop():while True:ev = inbox.claim_one() # lease, to prevent duplicate consumptionif not ev:sleep(1); continuetry:run_agent(ev) # real execution happens hereinbox.mark(ev, "DONE")except Exception as e:inbox.retry_or_dead(ev, e) # exponential backoff; dead-letter when the limit is exceeded
2. Timers: emit events, do not execute directly
An always-on agent needs three kinds of timing: a fixed period (a daily check), a one-shot delay (follow up in ten minutes), and conditional polling (wait until a resource is ready). Four engineering points matter: use one time-zone convention and handle daylight saving explicitly; define a catch-up policy for missed windows (run once, or skip); add jitter to jobs on the same period so they do not wake together and stampede; and have the timer only write events into the inbox, so there is a single entry point.
3. Memory: layered, retrievable, and governed
Memory should have three layers. Working memory is the current context. Episodic memory is summaries of past sessions. Semantic memory is structured facts and user preferences. Write at the end of a run, not on every message; otherwise noise drowns the signal. On retrieval, filter by subject and session first, then mix keyword and vector recall, then rerank and take the top K. Governance matters as much as storage: tag each memory with source and timestamp, let newer facts override older ones on conflict, and set TTL and forgetting policies. Control the context budget with summary compression and truncation of tool results.
4. Permissions: decide before execution, not inside the prompt
High-risk actions cannot rely on the model’s self-restraint. A workable design is least privilege plus resource scoping: authorize by tool and by data range; suspend high-risk operations as approval events, write them back to the inbox, and wait for a human; keep credentials short-lived, revocable, and bound to a specific session; and write every authorization and execution into an audit log. The rule is that the runtime enforces the permission check before the tool is called.
5. Outbox: same transaction as the business write
The agent’s output has to be delivered reliably. Put the outbound message and the business state change in the same transaction that writes the outbox. A dispatcher sends asynchronously afterward. That avoids “state changed, but the notification was lost.” Delivery is at-least-once, so consumers must be idempotent. Failures retry with exponential backoff and then go to a dead-letter queue. The message body carries run_id and session_id for end-to-end tracing.
4. Selection checklist
| Dimension | Key question |
|---|---|
| Triggers | Does it support multi-source events and a single entry point? |
| State persistence | Can runs and sessions be recovered and replayed? |
| Concurrency control | Are deduplication, leases, and serialization built in? |
| Memory | Are layering, retrieval, and forgetting all present? |
| Permission model | Does it support human-in-the-loop and audit? |
| Observability | Is there end-to-end tracing and alerting? |
| Scalability | Can workers scale horizontally? |
| Cost | Does sleep actually release resources? |
5. Common pitfalls and how to land it
Six mistakes show up often: treating “always on” as a process that never exits; running business logic in the handler until it times out; missing idempotency and executing twice; writing memory without governing it until context balloons; putting permissions only in the prompt so they are effectively optional; and having no dead-letter queue so problems pile up in silence.
For implementation, reuse ordinary cloud building blocks: a message queue for the inbox and outbox, object storage for memory and artifacts, a container platform for workers that can scale elastically, logging and monitoring for observability, and a secrets manager for credentials. Baidu AI Cloud offers capabilities in these general categories and can be composed along the skeleton above.
The conclusion is simple. There is no absolutely best agent framework—only a runtime that matches the task shape. Draw the run and session boundary first, then make the five components solid. The framework itself is an implementation detail.
