Resident AI Agent Design Philosophies: Orchestration-First vs. State-First
This article examines the core design choices behind resident AI agents, which stay online to run periodic checks, execute long-running batch jobs, and push results back to users. It compares two design philosophies—orchestration-first and state-first—covers a layered hybrid architecture, and details key engineering practices for model access, tool execution safety, task scheduling, and result delivery.
1. Why Resident Agents Are Becoming a New Paradigm
Early AI assistants were mostly one-shot and session-based: the user asked a question, the model answered, the session ended, and the context was discarded. Real business scenarios often require an assistant to stay online continuously. It needs to run periodic inspections while unattended, complete long-running batch jobs in the background, and proactively push conclusions back to the user once a task finishes. These requirements have given rise to a new software form: the resident AI agent.
Abstracted from the source material, the capability list falls into five categories: model access, tool and command execution, external message channel integration, persistent memory, and task scheduling with result delivery. Together these five capabilities form the minimal complete set for a resident agent. The differences between implementations are not about whether a capability exists, but about what the capabilities are organized around. This article groups them into two typical design philosophies and discusses them from an engineering perspective.
Note that this article does not evaluate or recommend any specific open-source project. Instead, it strips away identifiable product attributes and focuses on general technical problems and engineering practices.
2. Design Philosophy A: Orchestration-First
The core claim of this school is that an agent’s capability boundary is defined by its set of callable tools. The model is responsible only for decisions and parameter filling, while determinism is guaranteed by the orchestration layer.
2.1 Architecture Characteristics
- Externalized control flow: a state machine or workflow engine owns the main process, and the model is invoked within nodes.
- Tool contracts first: every tool has a well-defined input and output schema, making validation and replay straightforward.
- Recoverable failures: node-level retries, idempotency keys, and compensating actions are first-class citizens.
2.2 Advantages and Costs
The strengths are strong observability and testability, which suit enterprise scenarios that require auditing. The cost is limited flexibility: when an unanticipated long-tail request arrives, the agent may find no available tool.
An illustrative tool contract definition:
from dataclasses import dataclass@dataclassclass ToolSpec:name: strdescription: strinput_schema: dicthandler: callableidempotent: bool = FalseTOOLS = [ToolSpec(name="query_metrics",description="Fetch monitoring metrics by time range",input_schema={"type": "object","properties": {"range": {"type": "string"}}},handler=lambda **kw: {"ok": True, "data": []},idempotent=True,)]
3. Design Philosophy B: State-First
This school treats memory as a first-class asset: the continuity of an agent’s behavior comes from long-term state rather than a predefined process. It behaves more like a continuously running process than a one-shot function call.
3.1 Memory Layers
In engineering practice, memory is usually divided into three layers to avoid stuffing all information into the context window:
- Working memory: intermediate results of the current task, with a short lifecycle.
- Episodic memory: summaries of historical interactions, used to maintain continuity across conversations and tasks.
- Semantic memory: structured preferences and facts, such as a user’s usual entry points, time zone, and approval thresholds.
3.2 Governing Memory Writes
Memory is a double-edged sword and must be governed; otherwise it will pollute later decisions:
- Tiered writes: only explicitly confirmed information may enter semantic memory.
- Expiration and revocation: set a validity period and a revocation interface for each memory entry.
- Isolation and minimization: isolate by user or tenant and follow the principle of least necessity.
An illustrative memory write policy:
def should_persist(memory) -> bool:if memory.kind == "semantic" and not memory.confirmed:return False # Unconfirmed information does not enter long-term memoryif memory.ttl and memory.age() > memory.ttl:return False # Discard once expiredreturn True
4. Combining Both Philosophies: A Layered Hybrid Architecture
Production systems rarely adopt one school in pure form. A hybrid is more common: the outer layer uses state and memory to maintain continuity, while the inner layer uses tool orchestration to guarantee determinism.
- Ingress layer: unified message integration that hides differences between channels.
- Decision layer: the model performs intent recognition and plan generation.
- Execution layer: the orchestration engine schedules tools and commands with timeout and idempotency controls.
- State layer: layered memory plus persistent storage.
- Scheduling layer: scheduled jobs and a background queue for long-running tasks.
- Delivery layer: results are pushed proactively through message channels.
When deploying in the cloud, you can use a container platform to host the resident process, object storage to hold memory snapshots, a message queue to buffer tasks, and logging and monitoring services to ensure observability. General-purpose capabilities from cloud providers such as Baidu AI Cloud can serve as the underlying platform, but the specific selection should return to your own SLA and compliance requirements.
5. Key Engineering Areas in Detail
5.1 Model Access and Fallback
Model access should be abstracted behind a unified interface to make switching and canary rollouts easy. A fallback chain is essential: if the primary model times out, switch to a backup model; if that also fails, return a templated reply and hand off to a human, avoiding silent failures.
5.2 Security Boundaries for Tool Calls and Command Execution
Command execution is a high-risk capability. Recommended practices:
- Prefer allowlists and prohibit arbitrary string concatenation.
- Run with least privilege and drop privileges inside the container.
- Keep full audit logs recording the caller, a parameter summary, and the result status.
- Require a second confirmation for high-risk actions.
5.3 Scheduled Jobs and Long-Running Tasks
Scheduled jobs must handle clock drift and duplicate triggers, and long-running tasks must support resuming from a checkpoint. A “task table plus lease” pattern is recommended to prevent multiple instances from consuming the same task.
-- Illustrative: a task table with leasesCREATE TABLE task (id BIGINT PRIMARY KEY,payload TEXT,status TEXT, -- pending/running/done/failedlease_until TIMESTAMP,retry_count INT DEFAULT 0);
5.4 Result Delivery
Delivery must be idempotent and deduplicated. A common approach is to assign a unique key to each notification and have the receiving end deduplicate by
