Homework 5

Keep your agent on

Due before class on Wednesday, November 4, 2026

An always-on agent is mostly asleep: a small program waits, something wakes it, the model works until it answers, and it goes back to sleep. This week your harness becomes one. It runs as a service, wakes on Telegram, email and a schedule, compacts its conversation when it grows too long, stays inside limits you set, takes orders from your phone, and picks up where it left off after a crash. Leave it on overnight, and write down everything that goes wrong.

Missed earlier weeks? That's fine. Write the outer loop around Claude Code or Codex run headless, and use their built-in compaction. But building on your own agent loop teaches you considerably more, so if you can, use your harness.

Start

  1. Open an AI coding agentClaude Code, Codex, Cursor, GitHub Copilot, … in your harness folder.
  2. Give it this Read https://class.xhelio.ai/week-5/homework.md and help me with my homework.
  3. Build it togetherIt adds the outer loop, the schedule, the limits and commands, compaction, crash recovery and the service with you, helps you run the night and the demos, and opens your pull request.

You'll need your harness from weeks 2–4 with its Telegram and email plugins, a computer that can stay on overnight (plugged in and not sleeping), uv, and a GitHub account.

The outer loop

messages = load_log()              # 4: carry on
while True:
    event = events.get()           # 1: asleep
    if paused() or over_budget():  # 3: code decides
        hold(event); continue
    messages.append(user(event.as_text()))
    save(messages)                 # 4: on disk first
    run_loop(messages)             # week 2's loop
    if count_tokens(messages) > COMPACT_AT:
        compact(messages)          # 2: make room

Week 2's loop is the inner loop. This week adds the loop around it; the numbers are the four parts.

From your phone

/status    state, today's tokens and dollars,
           the next job, running subagents
/stop      stop the current work now, killing
           a running command, then sleep
/pause     stop waking on events (messages wait)
/resume    start again

Handled by your harness before anything reaches the model, and only from your own chat ID.

What you build

Show it working

  1. The nightAt least 8 hours on, a scheduled job and a message waking it; one line per wake-up, and zero model calls while asleep.
  2. CompactionTokens before and after, the summary, a question it still answers, and one thing the summary lost.
  3. The kill switch/stop from your phone kills a running sleep 600.
  4. A limitA tiny budget, hit; it stops and tells you.
  5. A crashkill -9 mid-task: it comes back, resumes, and sends nothing twice.

Plus failures.md: everything that went wrong, small things too. We use these in week 6, on how AI fails.

What you submit

A pull request adding week-5/submissions/<your-github-username>/: a README.md linking to your harness and saying how it runs, your schedule.toml and limits.toml, your service file in service/, the five demos in transcripts/ (with night.md), and failures.md.

It counts when it runs as a service and comes back after kill -9, nothing calls the model while it's asleep, the schedule, compaction, limits, commands, approval timeout and robot rule work, it resumes without re-running or re-sending, the demos and failures.md are there, and no secret is committed. Say in your pull request which AI helped you, and how.