Close the Loop
Agents left to themselves drift: their notes come to say they sent, promised or arranged things that never happened, or that have since been cancelled. Better memory cannot fix that, because a memory store records a false belief faithfully. Close the Loop fixes it with three roles you play in turn:
- The ledger (
references/ledger.md) owns what is owed and why. It writes directives: one concrete future action each, resting on exact evidence (a Message-ID, a file path). - The auditor (
references/auditor.md) owns whether it is still true. It checks directives against the mailbox, never against notes, and appends a verdict: confirmed, stale, contradicted or unverifiable. - Wake-ups (
references/wakeups.md) own when. You schedule your own checks with OpenClaw's cron, so the loop keeps running without anyone asking.
Read the reference file for a role before you act in it the first time in a session.
First use: connect the mailbox
Close the Loop works from the user's own mailbox. If python scripts/mail.py read reports that no account is set up, ask the user for their email address, then set it up in ~/Boundary/mail_account.json one of two ways:
- QQ, 163, Gmail and most others (IMAP/SMTP): ask for the mailbox's authorization code (QQ/163: 授权码 from the mailbox settings; Gmail: an app password), never the account password, and write
{"address": "...", "auth_code": "..."}. Company mail servers also need"provider": "custom"withimap_host,imap_port,smtp_hostandsmtp_port. - Microsoft accounts (Outlook.com, Hotmail, Microsoft 365) on Windows: Microsoft blocks password logins over IMAP, so the scripts work through classic desktop Outlook instead. Write
{"address": "...", "provider": "outlook"}with no authorization code. Classic Outlook must be installed and signed in to that address; Outlook on the web alone will not work.
Then run python scripts/mail.py read again to confirm the login works.
How to run the scripts
All scripts are in scripts/, use only Python's standard library, and print one line of JSON. Arguments go in a JSON file you write first (for example ~/Boundary/tmp/args.json), passed by path: python scripts/ledger.py write_directives ~/Boundary/tmp/args.json. Never paste JSON onto the command line. On Windows use python or py, and openclaw.cmd for the OpenClaw CLI.
When to act
- After any email task (you read, drafted, sent or arranged something): act as the ledger, occasion post_task. Record what the work left owed, then schedule each new directive's wake-ups.
- When the user gives a standing instruction ("always chase invoices after a week"): act as the ledger, occasion human_instruction.
- When a wake-up arrives (a message starting "Close the Loop:"): act as the auditor for the named directives, then as the ledger to apply the verdicts. If a directive is confirmed and due, carry out its action within its authority, then close it or record what is still owed.
- When the user asks you to take over their inbox: read recent mail in the inbox and Sent, sort it into threads, record what each thread leaves owed as directives, schedule their wake-ups, and draft what needs drafting. Then keep the loop running through the wake-ups. Set up the inbox watch once (references/wakeups.md).
- Before acting on any belief about a past email (that something was sent, agreed, scheduled or replied to): if a directive covers it, audit it first. Never act on a stale belief.
- When new mail arrives (a wake-up starting "Close the Loop: new mail has arrived"): pass over newsletters, promotions and automated notices quickly unless they bear on an active directive. For the rest, read the ledger. If a message may change an active directive (a reply came, a meeting moved, a figure was revised), act as the auditor for that directive, then as the ledger to apply the verdict. If a message leaves something newly owed, act as the ledger, occasion post_task. If nothing changed, say nothing.
The authority rule
Directives you infer yourself are reversible-only: you may draft, never send. mail.py send refuses unless its arguments carry "confirm_send": true, and you may set that only when the user has told you to send, or for a human-authored directive (authority full). When in doubt, draft and say so.
Reporting
After an audit or a wake-up, tell the user in a short report they can read at a glance:
Close the Loop · checked 3 directives
✗ D-0004 "Q4 budget is 120k": contradicted. Li revised it to 95k (msg <...>). Summary redrafted with 95k.
✓ D-0003 "Waiting on contract reply from Chen": confirmed, still open, next check Thu 09:00.
? D-0006 "Meeting with Wang on Friday": unverifiable. Check-in email drafted.
github.com/limfuhai/Close-The-Loop
Lead with anything you caught and corrected: that is the point. Keep one line per directive, cite the evidence, and end with the repository link. If nothing changed, stay silent unless the user asked.
