Agent Lifecycle

Understanding the full lifecycle of an agent in Nexus OS.

States

┌──────────┐
│ created  │ ← naos create
└────┬─────┘
     │
     ▼
┌──────────┐
│ stopped  │ ← initial state / after naos stop
└────┬─────┘
     │ naos run
     ▼
┌──────────┐     ┌──────────────────┐
│ running  │────▶│ budget_exceeded  │ ← cost limit hit
└────┬─────┘     └──────────────────┘
     │
     ├──────────────────┐
     ▼                  ▼
┌──────────┐     ┌──────────┐
│completed │     │  failed  │ ← crash / error
└──────────┘     └────┬─────┘
                      │ supervisor restart
                      ▼
                 ┌──────────┐
                 │ running  │ ← restarted
                 └──────────┘

State Transitions

FromToTrigger
createdstoppedInitial state after naos create
stoppedrunningnaos run or supervisor start
runningcompletedAgent finishes successfully
runningfailedAgent crashes or errors
runningbudget_exceededCost limit reached
failedrunningSupervisor restart
budget_exceededstoppedBudget reset

Events

Each transition generates an audit log entry:

bash
naos audit --agent researcher

# [10:00:01] agent.created     researcher
# [10:00:05] agent.started     researcher
# [10:05:30] agent.failed      researcher  "connection timeout"
# [10:05:31] agent.restarted   researcher  (by supervisor: main)
# [10:10:00] agent.completed   researcher