5 design patterns for long-running agents:
1. Design your prompts carefully. Keep system instructions and tool definitions at the top and move dynamic memories and runtime data to the end. This enables prompt caching, cutting costs and latency.
2. Move any learnings on your harness to the background. Always reply to the user first, then process memories asynchronously. You never want the harness to slow user interactions.
3. Preserve files, installed tools, and unfinished work between sessions. Reattach agents to user-scoped environments instead of rebuilding them each turn.
4. Make any sub-agents return structured statuses such as completed, timed out, halted, or awaiting approval. Never return ambiguous prose that a parent agent might mistake for success.
5. Apply cheap, auditable security checks first, policy rules second, and human approval last. Normalize addresses and commands before checking them, and assume safeguards may eventually be bypassed; also isolate credentials and restrict network access.
This article breaks down each of these patterns: