How an agent wakes
A resident agent does not run all the time. It sleeps, something wakes it, it does one round of work, picks when to wake next, and stops.
Where you see it
On the Office, the dot over an agent's head shows if it is asleep, waiting on you, or working. After each wake, one new line appears in its run log. Most of the machinery is invisible plumbing.
What happens, step by step
- CodeAlarm clockChecks every 15 minutes who is due.
- GateRead firstThe box reads the checklist into the message that wakes it.
- AgentRead the inboxOwner answers, notes from routed mail.
- AgentLook, then thinkCheck the real world. Pick one useful thing.
- AgentActDraft, research, or propose.
- StoreWrite backPlan, memory, score, one line of log.
- AgentPick the next wakeDone last, so it cannot be skipped.
- StoreSave and stopOnly what was written down survives.
Six things can start an agent, and only six:
| What starts it | How fast |
|---|---|
| The wake time it picked for itself | Within 15 minutes |
| Its daily wake: a day has gone by since its last wake began | Within 15 minutes of the 24-hour mark |
| The owner answers one of its questions | Within 15 minutes of the tap |
| A person's email is routed to it | Within about 30 minutes, so emails close together share one wake |
| Another agent asks it something | Within 15 minutes, with a daily cap |
| The owner opens its chat room | Right away, but this is a conversation, not a wake |
A chat room is different. The agent talks with the owner there, and it does not run its normal round of work. It may set its next wake time for later in a chat, but never "right now" (see Setting a wake time in a chat).
A wake never starts in the middle of a chat. While the owner is talking to an agent, its scheduled wakes wait. A wake that comes due during the chat runs within 15 minutes of the chat ending. An email that arrives during the chat waits too. A desk chat ends by itself after 5 quiet minutes.
The Office says which one it was. Each wake shows its reason on the agent's row and in the Today tab, in these words:
| The Office says | Why it woke |
|---|---|
| Woke on schedule | The wake time it picked came round, or its daily wake did. |
| Woke because Sam emailed: 'Asks to move lunch to Thursday' | A person's email was routed to it. The words in quotes are a short, checked summary of the email, never its own subject line. "Sam and 2 more" means three emails arrived before it woke. |
| Woke because Ada asked it something | Another agent asked it something. |
| Woke because you wrote in its inbox | The owner answered a question or wrote to it. |
| First wake | It has never run before. |
| Started by hand | Someone started it off its schedule. |
While it sleeps, the row says when and why it last woke, such as "Last woke today 10:45 am because Sam emailed". An email wake is marked by the mail router itself, which leaves a note for the alarm clock, so an email is never shown as "on schedule".
Emails are grouped, 30 minutes at a time. Every email gets a full wake, but the first one sets the agent's alarm 30 minutes out and anything that arrives in those 30 minutes joins the same wake. A burst of sign-ups or three quick replies is one wake, not three. Every email rule that wakes an agent must say how long it waits (30 minutes unless there is a reason), and the router's own check refuses a rule that does not.
The alarm clock. An agent cannot wake itself, because nothing of it is running between wakes. So a timer called resident-wake.timer (the alarm clock) ticks every 15 minutes. Each tick runs resident-wake.py (the waker). It reads each agent's next wake time from the logbook. If the time has passed, or no time is set at all, that agent is due, unless the owner is chatting with it: then it waits for the chat to end. If the box was off during a tick, the tick still fires when it comes back.
The cap. One wake may run at most 30 minutes. Then it is stopped.
Up to three at once. When the alarm clock finds several agents due at the same tick, it wakes up to three side by side instead of one after another. A fourth waits and starts the moment one of the three finishes. Three is a setting, wakes_at_once, that the owner can lower or raise. Each agent still has its own "busy" sign (a lock), so:
- An agent the owner is chatting with still waits for the chat to end. The others wake as normal.
- One agent crashing does not stop the others. The crash is written to the log with that agent's name.
- Two ticks never overlap. If the last tick's wakes are still running, the next tick stands down.
One wake, start to finish. Say Ada wakes at 9:00.
- Load context. The box has already read her checklist for her and put it in the message that wakes her:
agent.md, her plan,memory.md,scoreboard.md, the end of her run log, her quality notes,inbox.md, and what other agents posted since her last wake. Each file is there whole. Her first move is real work. (Anything the box left out, like notes still too long, is named, and she reads it first.) - Read the inbox. She works each entry in
inbox.md, then deletes it. - Look. She checks the real world: the sign-up page, the calendar, the logbook. She never trusts a file's claim that something is still true.
- Think. What is the one most useful thing she can do right now that is not blocked?
- Act. She drafts, researches, or proposes. Anything that reaches a real person stops at the send guard.
- Write down how she did it. Right after a job, she writes or improves the skill (her how-to steps) for it. Her own skills are hers; every change is recorded. The shared skills are not: she cannot change them, and tells the owner in a note if one looks wrong.
- Write back. Plan, memory, scoreboard, and one line saying what she did. The exact command for that line comes printed in the message that woke her, already filled in for this wake, so she never has to look it up.
- Pick the next wake. This is done last, with the command printed for her too. The end-of-wake check holds her for two things only: the line saying what she did, and the next wake time.
- Save. She saves her own files to the vault, so every machine sees them.
- Stop. The process exits. Only what she wrote down survives.
Getting better happens at night, not in the wake. Each agent has an improve step: work its notes on what went wrong, post a learning to the forum (or record none), make one small improvement to how it works (or ask the owner about a bigger one), and read one real thing about its job. It used to end every wake. Now it runs once a night, as the first part of Dreaming, and only for an agent that did real work that day, so wakes stay short. The box checks afterwards what it really did, and anything left undone goes on the agent's list for the next night. A safety rule tripping the agent is sent to Otto as a fix to look at, not written into the agent's notes.
Choosing the next wake:
| True at the end of the wake? | Next wake |
|---|---|
| A step is unblocked and it is hers to do | One hour |
| Waiting on the owner or the world | Her own date rule |
| Nothing to do | Her own date rule |
One catch. If the wake changed nothing at all, she may not pick one hour. That stops an agent from spinning every hour for no reason.
Never a wake just to check for a reply. An agent picks a wake time only for work it will do itself, like a follow-up that is due. It never sets one just to see whether someone wrote back. A reply wakes it by itself: an answer from the owner, another agent's ask, or an email that one of its email rules watches for. The message that wakes an agent tells it which is true for it:
- Its replies wake it. It has an email rule, and the box has seen that rule's inbox working in the last day. It never sets a wake to look.
- Its rule is not working yet. It has a rule, but the box has not seen its inbox working (for example, the box does not yet have permission to read that inbox). Until it does, the agent may still set a wake on the day a reply is due, to look for it. No reply is lost while a rule is being set up.
- It waits for no email replies. It has no rule, so nothing it sends by email should leave it waiting.
The daily wake: never more than a day asleep. Every agent wakes at least once a day, weekends included, to do its normal work. If the time it picked is more than 24 hours after its last wake began, the alarm clock starts it at the 24-hour mark anyway. The time it picked is kept, not changed: if that time comes sooner, it wakes then. The daily wake catches anything that arrived some other way, like a reply no rule watches for, or a time the mail connection was down. The Office's "Back ..." line shows the time the agent will really wake, whichever comes first. The number of hours is a setting, daily_wake_hours (24 unless the owner sets fewer). Nothing turns it off: every agent keeps one wake a day.
Wake times are Pacific time, and always in the future. The agent writes a time the way a clock in California reads it. A time written in UTC (ending in Z) is refused, because "9 AM Z" is really 2 AM in California, and that mistake is easy to make. A time that has already passed is refused too. The agent gets the time back in words, such as "Next wake: Wed Sep 30, 9:00 AM Pacific (in 17 hours)".
Setting a wake time in a chat
You can tell an agent when to wake up next, right in the chat.
- Say "wake up tomorrow at 9". It sets that time and tells you back in words.
- "Right after we finish" means five minutes from now. The wake still waits until the chat ends.
- It cannot pick "right now" from a chat, because that would start a wake while you are still talking.
- It picks a time only for work it will do. It never sets one just to check whether someone answered. An answer or an email wakes it by itself, and its daily wake comes anyway.
The same rule when you talk to an agent
A timer is not the only way to start an agent. You can also walk up to its desk and open its room. The same rule applies, and works the same way: the box reads the agent's checklist into the first message, so it has read everything before it says a word to you.
That is the read-first wall: a block that refuses every other action until the agent has read who it is, its plan, and its notes. It is like a person who has to read the file before a meeting, not after.
- It only applies to an agent. A plain chat, like "what is on my calendar today," has no agent behind it, so there is no checklist. If a plain chat ever asks you to wait while it reads, that is a bug.
- You will not see it work. The agent reads first and then talks. The logbook records that you opened the room, with the time, and shows each file read before the agent's first real move.
- It is why the first answer is good. Open a room and the agent already knows the plan is waiting on the library.
What powers it
| Part | What it does |
|---|---|
resident-wake.timer | The alarm clock. Ticks every 15 minutes, even after a restart. |
resident-wake.py | The waker. Finds who is due and starts each one, with a 30-minute cap, up to three at once. |
The wakes_at_once setting | How many agents may be awake at the same time. 3 unless the owner changes it. |
The daily_wake_hours setting | The longest an agent may sleep: 24 hours unless the owner changes it. |
The logbook (agent_meta table) | Holds each agent's next wake time as a row. |
logbook.py plan next-wake set | The only door an agent uses to pick its next wake. It takes a future time in Pacific time, in a wake or in a chat. |
| The chat's lock | While the owner talks to an agent, the chat holds the same lock (a "busy" sign) a wake holds, so no wake can start. |
| The wake hooks | The reminder, the wall, and the recorder described below. |
The email router's wait (batch_minutes) | How long an email waits so others can join the same wake. 30 minutes on every rule that wakes an agent. |
| Dreaming | Runs each agent's improve step once a night, then tidies its notes. |
| The opening read | Before a wake or a chat starts, the box reads every item on the agent's checklist, in order, and puts them in the first message. Each one is written down as read, so the wall is already open. |
Why it works this way
The wake hooks (automatic checks around every action) have three parts. A reminder prints the checklist when the wake starts. A wall refuses every tool call until every file on the checklist has been read, and names the files still missing. A recorder watches the agent's tool calls and ticks the list itself, so the agent never just says "I read it."
The wall exists because an agent that acts before it reads will redo work, or undo it. If the wall itself breaks, it lets the agent through and logs it. A bug in a guard should not lock an unattended agent out for days.
Why the box does the reading. An agent that reads its own files spends its first several moves opening them, and every move costs money. When the box reads them into the first message, the agent starts work at once, and the wall still holds. Three rules keep that safe:
- Nothing is cut short. Each file goes in whole, with its size in its heading and an end line after it, so the agent can tell it has all of it.
- A file too big to hand over is named, not trimmed. The message says which file was left out. The agent reads that one itself, and the wall refuses everything else until it does.
- Only short notes are handed over. If an agent's notes are over the size Dreaming aims for, the box leaves them out and says so, and the agent reads them itself, as before. Dreaming shortens them a little each night; once they fit, they are handed over too.
An agent with no checklist reads its own files, as before.
Why the next wake is set last. If a wake dies halfway, no new time is set. No time means "due now," so the next tick restarts it. If the time were set first, a crash would leave a stale future time, and the agent would sleep through its own failure.
Why a daily wake. A rule that says "replies wake you" is only as good as the connection behind it. A connection can drop, and a reply can arrive somewhere no rule watches. One wake a day doing normal work means nothing waits longer than a day, at the cost of one short wake on a quiet day.
Why one hour. The owner tends to work in blocks of about five hours. An agent that wakes every hour keeps moving while the owner is away, without burning a whole chain of work in one sitting.
Connected to
- An agent's files: what it reads and writes each wake.
- How an agent asks you: an answer can wake it early.
- Agent email: mail to its own address can wake it.
- Agents working together: the inbox and the daily cap.
- The logbook: where wake times and plans live.