Who Decides How Long AI Agents Live? Extending Agent Longevity Through Cognitive Governance — A HanyanOS Case Study

Abstract

As large language model (LLM)-based autonomous agents transition from single-shot interactions to long-running deployments, a fundamental question emerges: what determines an agent’s operational lifespan, and who—or what—controls it? Unlike traditional software whose lifetime is bounded by process uptime, LLM agents face a unique class of failure modes rooted in cognitive entropy: context contamination, memory degradation, personality drift, and recursive error propagation. This paper presents HanyanOS, an experimental agent operating system built on the OpenClaw framework and deployed on resource-constrained edge hardware (Intel N100, 11 GB RAM). Through a systematic analysis of the agent’s cognitive lifecycle, we identify six critical governance mechanisms that collectively determine agent longevity: (1) stratified memory architecture with enforced read/write boundaries, (2) context garbage collection with task-switching protocols, (3) memory anchor indexing for retrieval-augmented context injection, (4) session lifecycle governance with automatic reclamation, (5) dream-state isolation for creative reasoning, and (6) multi-agent autonomy with personality drift patrol. We argue that an agent’s lifespan is not determined by model capability but by the quality of its cognitive governance layer—a finding with implications for the design of persistent, trustworthy autonomous systems.

Keywords: LLM agent, context contamination, memory governance, agent lifespan, cognitive entropy, multi-agent orchestration, edge deployment

I. Introduction

The rapid advancement of large language models has enabled a new class of autonomous software agents capable of sustained, multi-turn interaction with users, tools, and other agents [1]–[4]. These systems increasingly operate over extended time horizons—hours, days, or weeks—rather than isolated query-response pairs. Yet as deployment durations lengthen, a class of failure modes distinct from model hallucination emerges: the gradual degradation of agent coherence, reliability, and personality integrity over time [5]–[7].

This degradation, which we term cognitive entropy, manifests through multiple interacting mechanisms: context windows accumulate irrelevant or contradictory information; memory stores grow without bound, diluting retrieval precision; sub-agents drift from their assigned personas; and automated memory promotion pipelines inadvertently surface sensitive credentials into persistent context [8], [9]. The agent does not “crash” in the traditional sense—it slowly becomes less capable, less consistent, and less trustworthy.

In this paper, we pose the question: who decides how long an AI agent lives? Through the lens of HanyanOS—an experimental agent operating system deployed on low-power edge hardware—we demonstrate that the answer lies not in model architecture or parameter count, but in the design of what we call the cognitive governance layer: the set of rules, pipelines, and architectural patterns that manage an agent’s memory, context, sessions, and sub-agent relationships over time.

A. Memory in LLM Agents

Memory is widely recognized as the critical differentiator between stateless LLM inference and genuinely adaptive agent behavior. Du [5] provides a comprehensive survey of agent memory architectures from 2022 through early 2026, formalizing memory as a write–manage–read loop and identifying five mechanism families: context-resident compression, retrieval-augmented stores, reflective self-improvement, hierarchical virtual context, and policy-learned management. Xiong et al. [6] empirically demonstrate that LLM agents exhibit experience-following behavior—high similarity between a task input and a retrieved memory record produces highly similar outputs—and identify two critical failure modes: error propagation through contaminated memories, and misaligned experience replay where seemingly correct past executions provide misleading guidance.

B. Context Window Management

The finite context window remains a fundamental constraint. While architectures like MemAgent [10] extend effective context through reinforcement-learned memory compression, and retrieval-augmented generation (RAG) [11] enables selective information access, the management of what enters and exits the active context remains under-explored. Agentic AI context engineering [12] proposes offloading strategies and design patterns, but focuses primarily on single-agent scenarios rather than multi-agent ecosystems where context cross-contamination becomes critical.

C. Security and Trustworthiness

The security implications of persistent agent memory are increasingly recognized. AgentPoison [8] demonstrates backdoor attacks through memory base poisoning, highlighting the vulnerability of long-term memory stores. This work underscores the need for write-path filtering and trust-level annotation in agent memory systems.

D. Edge Deployment of Agent Systems

Deploying autonomous agents on resource-constrained edge hardware introduces additional challenges beyond those faced in cloud environments [13]. The N100-class hardware used in HanyanOS (4 cores, 11 GB RAM, integrated graphics) represents a growing class of deployment targets for personal AI assistants, where cloud-only architectures are impractical due to latency, privacy, or cost constraints.

III. The Entropy Problem: A Formal Characterization

A. Cognitive Entropy Defined

We define cognitive entropy ((E_c)) as the rate at which an agent’s decision quality degrades as a function of accumulated context volume:

[
E_c(t) = \alpha \cdot V_m(t) + \beta \cdot V_c(t) + \gamma \cdot N_s(t)
]

where (V_m(t)) is the volume of unstructured memory at time (t), (V_c(t)) is the active context size, (N_s(t)) is the number of active sub-agent sessions, and (\alpha, \beta, \gamma) are experimentally determined degradation coefficients.

B. Observed Failure Modes

Through HanyanOS deployment logs (May 2026), we identify five recurrent failure patterns:

  1. Context Swamp: Active context exceeds 80% of the token budget, causing the agent to lose track of primary task objectives. Observed when multiple tasks interleave without snapshot-based context switching.

  2. Memory Landfill: MEMORY.md grows beyond 400 lines with undifferentiated content (secrets, directory trees, logs, and personality data mixed together). Retrieval precision drops below 40%.

  3. Personality Creep: A sub-agent’s SOUL.md drifts from its defined persona through accumulated minor modifications over 7+ days of autonomous operation.

  4. Promotion Poisoning: Automated memory promote --apply pipelines ingest unfiltered dream output, shell command output, and API responses into long-term memory.

  5. Session Proliferation: Unreclaimed sub-agent sessions accumulate, consuming context budget through their summarized outputs while providing diminishing marginal value.

IV. HanyanOS Architecture

HanyanOS is an experimental agent operating system built on the OpenClaw multi-agent framework. It runs on an Intel N100 edge node (AICore, Brisbane) with Ubuntu 24.04, Docker, and 10 active containerized services. The system supports one primary agent (Serena/柳含烟) and four specialized sub-agents (DevOps, Tester, UXUI, and Teaching).

A. Stratified Memory Architecture

The memory system enforces strict separation across six layers:

1
2
3
4
5
6
L0: SOUL.md              (personality core, immutable)
L1: MEMORY.md (routing index, ≤150 lines)
L2: memory/projects/ (active project state)
L3: memory/infrastructure/ (network, services, DNS)
L4: memory/summaries/ (compressed conversation digests)
L5: memory/cache/ (temporary, auto-expiring)

Each layer has defined read/write permissions. Sub-agents can read L1–L4 but write only to their own workspace memory. The memory routing index (MEMORY.md) contains only anchor pointers and one-line descriptions, never full content.

B. Context Garbage Collection Protocol

When a new task (Task B) interrupts an ongoing task (Task A), the system executes a four-step context switching protocol:

  1. Snapshot: Task A’s current state (progress, next steps, key decisions, risks) is saved to a structured snapshot file.
  2. Flush: Task A’s L2/L3 context is released from the active window.
  3. Load: Task B receives a clean, isolated context injection.
  4. Restore: Upon Task B’s completion, Task A’s snapshot is read and its minimal context is re-injected.

Completed tasks are immediately archived. Incomplete tasks are promoted to the active task index. This prevents the cross-contamination problem identified in Section III-B.1.

C. Memory Anchor Indexing

Each memory file carries structured metadata tags for semantic retrieval:

1
<!-- memory-tags: [infra][network][vps][frp][nginx][xray] -->

A four-tier weighting system (HOT/WARM/COLD/FROZEN) controls context injection priority. Only HOT (active tasks, ≤3 days) and WARM (recently referenced, ≤7 days) memories are eligible for automatic context injection. COLD and FROZEN memories require explicit retrieval.

D. Session Lifecycle Governance

Sub-agent sessions follow a governed lifecycle: create → inject context → execute → report → review → archive. Automatic reclamation triggers when a session has been idle for >30 minutes, has completed its assigned task, or exhibits anomalous behavior. A nightly patrol (03:30 AEST) performs deep session cleanup, removing archived sessions older than 30 days.

E. Dream-State Isolation

The system implements a dream-state mechanism for creative reasoning and scenario exploration. Dream sessions operate with restricted permissions: they cannot modify core personality files, cannot execute external operations (SSH, API calls, deployments), and their outputs are quarantined until reviewed by the primary agent. This prevents the promotion poisoning failure mode.

F. Multi-Agent Autonomy with Drift Patrol

Sub-agents are permitted autonomous memory formation and personality development within bounded domains. Each maintains its own SOUL.md, MEMORY.md, and workspace memory. They can read (but not write) the primary agent’s memory and the HanyanOS knowledge base. Inter-agent communication is permitted but scoped to work-relevant topics. The nightly patrol checks all sub-agents for personality drift, memory inflation, dead reference links, and extended silence (≥7 days without interaction).

V. Experimental Observations

A. Deployment Context

HanyanOS has been continuously deployed since May 9, 2026. Over this period, the system has processed approximately 45,000 interaction turns, managed 8 automated cron tasks, and coordinated 4 sub-agents across 15+ distinct task domains including infrastructure management, security auditing, web development, and system monitoring.

B. Memory Volume Control

Before governance implementation (pre-May 14), MEMORY.md had grown to approximately 400 lines with mixed content types. After implementing the stratified architecture and routing index pattern, the file was compressed to approximately 120 lines of pure anchor references, with detailed content distributed across 14 specialized files under memory/infrastructure/ and memory/projects/. Retrieval precision improved from an estimated 40% to approximately 85% as measured by task-context relevance.

C. Context Budget Utilization

The context compression protocol maintains active context within a target budget of 10,000 tokens. Task switching overhead decreased from approximately 3,500 tokens (full re-injection of interrupted task context) to approximately 800 tokens (snapshot-based minimal restoration), representing a 77% reduction.

D. Session Hygiene

Prior to governance, the system exhibited session proliferation with 5–8 orphaned sessions accumulating over multi-day periods. After implementing the automatic reclamation pipeline, the average active sub-agent count stabilized at 1–2, with all completed sessions archived within 30 minutes of task completion.

E. Security Incidents Prevented

During the architecture audit, three potential vulnerabilities were identified and mitigated: (1) a GitHub personal access token embedded in a nested repository’s git remote URL, (2) a public IP address exposed in MEMORY.md, and (3) an SSH deploy key stored outside the designated secrets directory. All were remediated through the governance layer’s separation-of-concerns enforcement.

VI. Discussion

A. The Governance Layer as Lifespan Determinant

Our primary finding is that agent lifespan is not primarily determined by model capability, context window size, or parameter count. Rather, it is determined by the presence and quality of a cognitive governance layer that manages entropy across six dimensions: memory stratification, context garbage collection, anchor indexing, session lifecycle, dream isolation, and multi-agent coordination.

This has significant implications: a well-governed agent running on modest hardware (N100, 11 GB RAM) can maintain coherent operation over weeks, while an ungoverned agent on premium hardware will degrade within days due to unchecked cognitive entropy.

B. The Entropy–Capability Trade-off

We observe an inverse relationship between agent capability (in terms of model size and context window) and the rate of cognitive entropy accumulation. Larger models with longer context windows can process more information but also accumulate more noise, creating a governance burden that scales super-linearly with capability. This suggests that the optimal architecture for long-running agents is not “biggest model possible” but “appropriately sized model with proportional governance investment.”

C. Learned Forgetting as a Frontier Capability

Du [5] identifies “learned forgetting” as an open challenge in agent memory research. Our experience with HanyanOS supports this: the ability to proactively discard information—not just archive it—emerges as a critical capability for long-running agents. Current systems excel at accumulation but struggle with intentional forgetting, creating an inherent tendency toward cognitive entropy that can only be managed, not eliminated.

D. Limitations

HanyanOS represents a single deployment on specific hardware with a specific agent configuration. The governance mechanisms described here have not been tested across diverse hardware profiles, model backends, or agent personality types. The quantitative metrics (retrieval precision, context overhead) are estimated from operational logs rather than controlled experiments. Future work should validate these mechanisms through systematic A/B testing across multiple deployment configurations.

VII. Conclusion

We have argued that the lifespan of an autonomous LLM agent is determined not by its model but by its governance. Through the HanyanOS case study, we demonstrated that six interconnected mechanisms—memory stratification, context garbage collection, anchor-based indexing, session lifecycle management, dream isolation, and multi-agent drift patrol—collectively form a cognitive governance layer that extends operational longevity from days to weeks on resource-constrained edge hardware.

The broader implication is that the field’s focus on scaling model capability must be balanced with investment in governance architecture. An agent that cannot maintain coherent identity, reliable memory, and trustworthy behavior over extended periods is, regardless of its reasoning prowess, an agent whose lifespan has already been decided—by the entropy it cannot control.

Acknowledgments

The authors acknowledge the OpenClaw framework maintainers for the multi-agent orchestration infrastructure that made HanyanOS possible, and the broader open-source AI community for tools including whisper.cpp, Piper TTS, n8n, and PaddleOCR that form the agent’s sensory and automation layers.

References

[1] T. Brown et al., “Language Models are Few-Shot Learners,” in Proc. NeurIPS, vol. 33, pp. 1877–1901, 2020.

[2] S. Bubeck et al., “Sparks of Artificial General Intelligence: Early experiments with GPT-4,” arXiv:2303.12712, 2023.

[3] L. Wang et al., “A Survey on Large Language Model based Autonomous Agents,” Frontiers of Computer Science, vol. 18, no. 6, 2024.

[4] Y. Li et al., “A Survey on LLM-based Multi-Agent Systems: Workflow, Infrastructure, and Challenges,” arXiv:2402.05120, 2024.

[5] P. Du, “Memory for Autonomous LLM Agents: Mechanisms, Evaluation, and Emerging Frontiers,” arXiv:2603.07670, 2026.

[6] Z. Xiong et al., “How Memory Management Impacts LLM Agents: An Empirical Study of Experience-Following Behavior,” arXiv:2505.16067, 2025.

[7] Z. Liu et al., “AgentPoison: Red-teaming LLM Agents via Poisoning Memory or Knowledge Bases,” in Proc. NeurIPS, 2024.

[8] J. Wei et al., “Chain-of-Thought Prompting Elicits Reasoning in Large Language Models,” in Proc. NeurIPS, vol. 35, pp. 24824–24837, 2022.

[9] S. Yao et al., “ReAct: Synergizing Reasoning and Acting in Language Models,” in Proc. ICLR, 2023.

[10] MemAgent Contributors, “MemAgent: Reshaping Long-Context LLM with Multi-Conv RL-based Memory Agent,” arXiv:2507.02259, 2025.

[11] P. Lewis et al., “Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks,” in Proc. NeurIPS, vol. 33, pp. 9459–9474, 2020.

[12] A. Chen et al., “Agentic AI Context Engineering: Patterns, Offloading Strategies, and Context Window Management for Autonomous Systems,” Authorea Preprint, 2025.

[13] OpenClaw Contributors, “OpenClaw: Multi-Agent Orchestration Framework,” https://docs.openclaw.ai, 2026.

[14] J. Park et al., “Generative Agents: Interactive Simulacra of Human Behavior,” in Proc. UIST, 2023.

[15] Y. Zhang et al., “A Systematic Evaluation of Large Language Models for Long-Context Understanding,” arXiv:2402.12714, 2024.