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
- Open an AI coding agentClaude Code, Codex, Cursor, GitHub Copilot, … in your harness folder.
- Give it this
Read https://class.xhelio.ai/week-5/homework.md and help me with my homework. - 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
- 1 · Waking up. One event queue fed by watchers in code: Telegram, new email (checked every minute or two, never by the model) and a
schedule.tomlwith at least one job useful for your research. Each event becomes a labelled user message with the time. Ascheduletool lets the agent list, add and remove jobs. It runs as a service (launchd, systemd or Task Scheduler) that restarts it when it dies. - 2 · Remembering. Compaction when the conversation passes a threshold you set: one summarizing call, the system prompt kept in front, the last few messages kept as they were, tokens before and after logged. Just before, the agent saves what it must not forget to
memory/MEMORY.md; that file and yourAGENTS.mdare read at every wake-up. - 3 · Control. Limits in
limits.toml(turns and minutes per wake-up, dollars per day, replies per address), checked before every model call. The four commands above. A command approval nobody answers within 10 minutes counts as no. Never a reply to automatic mail. - 4 · Surviving. Every message appended to
logs/main.jsonl. After a crash it resumes from the log, doesn't blindly re-run a command that was in flight, and never sends an email twice (an outbox with a key per email, checked against the Sent folder).
Show it working
- 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.
- CompactionTokens before and after, the summary, a question it still answers, and one thing the summary lost.
- The kill switch
/stopfrom your phone kills a runningsleep 600. - A limitA tiny budget, hit; it stops and tells you.
- A crash
kill -9mid-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.
More
- The assignment on GitHubThe full text, and where you submit.
- What your agent readsPlain text; the full guide is in the repository.
- The loop around the loop, from classOne wake-up, end to end.
- Compaction on the wire, from classBefore and after, and the prompt to start from.
- All homeworkYour task and your agent, all quarter.