Stanford CS146S: How always-on agents work
45 minTalk describes how to build always-on, proactive agents that persist beyond a single terminal session. Core pattern: a thin client, thick server with an agent loop on the server and a separate Firecracker VM ‘computer’ the agent can start/stop and snapshot. It emphasizes durable workflows (Temporal) over simple queues, dynamic tool discovery to save context, heavy use of files, and sub-agents for long-running work. Reliability, prompt caching, compaction, safety (auto-review, approvals), and multi-source triggers are central.
- Thin client, thick server: keep the agent loop on the server; clients primarily use a single tool (send_to_user) to communicate back.
- Separate ‘computer’ per agent via Firecracker VM for browser, desktop, files; snapshot/resume to control cost and recover state.
- Wake/sleep lifecycle: agents are triggered by user messages, Slack/email/webhooks/routines; router dedupes and decides whether to notify the user.
Read full briefing
Key technical points
- Thin client, thick server: keep the agent loop on the server; clients primarily use a single tool (send_to_user) to communicate back.
- Separate ‘computer’ per agent via Firecracker VM for browser, desktop, files; snapshot/resume to control cost and recover state.
- Wake/sleep lifecycle: agents are triggered by user messages, Slack/email/webhooks/routines; router dedupes and decides whether to notify the user.
- Use durable workflows (e.g., Temporal) instead of job queues so retries resume at the last step rather than replaying work.
- Main agent orchestrates; heavy or token-expensive work is delegated to sub-agents/helpers with fresh context, then results are returned compactly.
- Dynamic tool discovery: include only tool names by default; fetch full schemas/details on demand to preserve context window.
- Prioritization and batching: direct user messages can interrupt/precede other queued work; multiple quick messages are batched into one turn.
- Computer use tiering: prefer HTML or accessibility tree for DOM interaction; fall back to pixel clicks; escalate to user only when necessary (e.g., 2FA/CAPTCHA).
- Cost/control ladder: try cheapest/reliable sources first (conversation, plugins/APIs), then web search, then computer/browser, then full desktop, then ask user.
- Prompt caching discipline: keep tool definitions/system prompts static and ordered to avoid cache breaks; pre-warm prompts when user focuses the chat.
- Context compaction: move long outputs to files; periodically summarize history and perform compaction while cache is warm to reduce future costs.
- Memory layout: core user facts always present; dated logs for history; ephemeral scratchpad notes; everything else discoverable via files/grep.
- Safety: auto-review by a model for shell/irreversible actions, explicit approvals for sends, and isolation from untrusted inputs to mitigate prompt injection.
- Engineering heuristic: create dedicated tools if shell-based generality causes inefficiency; write error messages that are actionable for agents.
This outlines a concrete, production-minded architecture for persistent agents: server-side agent loops, separable VM ‘computers’, and durable workflows to survive crashes. It details context/prompt-caching tactics, dynamic tool inclusion, and sub-agent orchestration to keep the main conversation lean and cheap. It also covers practical UI/trigger routing, safety/approval gates, and computer-use strategies, offering implementable patterns and trade-offs for long-running, tool-using agents.























