Manual›Guides
How do I make a reflex?
Ask Irene to "make this a reflex", or let it write one itself: an agent writes a reflex mid-job when it's about to make the same kind of call for the third time. A reflex is a small Python program that drives the agent's own tools and hands back one compact result. Everything it reads stays inside the program, out of the conversation. Model calls happen only where you ask for judgement, and an identical question is answered from cache. A run with no judgement steps uses no model at all.
When to write one, when not to, and how a reflex is checked, run, scored and fixed follow below.
Normal mode or reflex mode?
You can let the agent write reflexes as it goes (normal mode), or switch the chat to ⚡ reflex mode (Shift+Tab), where it does everything through reflexes.
- Unclear job, where the agent has to look around and judge first: normal mode. It reads pages itself, decides, and writes a reflex once the path is clear.
- Clear job with steps you can name: reflex mode. It writes one program and keeps it.
- A job you've done before, or a saved reflex that nearly fits: reflex mode. It reuses or edits the reflex. In measured runs a repeated job cost less than half of doing it by hand.
Why: in reflex mode the chat has no reading tools of its own, so on an unfamiliar job it writes code for pages it hasn't seen and repairs it run by run. That first pass cost about 30% more than normal mode. Once a reflex exists, reflex mode is cheaper every time after. The more expensive the model, the bigger the saving. Details: When should I use reflex mode?
Worked example: Instagram posts in true upload order (real runs)
"Get the caption, likes and comments for these Instagram posts, and put them in the order they were actually posted."
1. Irene writes a reflex instead of reading page after page
The Browser agent opens the first post. An Instagram page is enormous: menus, comments, suggested posts, thousands of words around one caption. Reading ten of them by hand would pour all of that into the conversation, and every later step would re-send it.
So the agent writes ig-post-captions, a program that opens each post, reads the page text, and cuts out the caption, relative time, likes and comments by matching the page's own markers. It uses no model.
2. The first run "succeeded", and every row was empty
The first run, on 11 posts, came back ok: true. But all 11 rows were empty, each with the same error: no Verified header found. The program hadn't crashed, so the run looked fine. It had matched nothing.
The only reason this was caught: the reflex returned its evidence, the rows themselves and the error list, not just "done". Irene fixed the matching and ran it again. 9 of 10 posts came back complete; the tenth was reported as failed, with its reason.
This is why every reflex must return proof: counts, a sample and the errors. A program that keeps pages out of the conversation also keeps its failures out, unless it reports them.
3. The second trap: "Edited · 3d"
The table had another problem. Instagram shows when a post was last edited, not when it was posted, and the reflex had found no real date on any row. Sort by what's on screen and the order is wrong.
The by-hand fix would be to go back through every page and look harder. Instead, Irene found that each page carries the post's exact upload time in data the page doesn't display. It wrote a second reflex, ig-post-timestamps, about 40 lines, that reads only that.
Result: 14 of 14 posts, each with its true upload time (for example 2026-10-05 13:02:25 UTC), in 28 tool calls and about 17 seconds, with no model and no page text in the conversation. Its "use when" says exactly why it exists: edited posts display the edit time, not the post time.
4. What it saved
Irene prices each run against the agent doing the same steps itself, with the conversation growing at every step. For the timestamps run, that would have been about $0.17 and 1.6 million tokens of re-sent context. The reflex cost $0.00.
5. Next time
Ask the same thing for another account and Irene finds both reflexes by their "use when", passes in the new list of posts, and runs them. No exploring, no re-learning.
How a reflex works
The program
async def main(tools, llm, var):
rows, errors = [], []
for url in var["urls"]:
await navigate(url=url)
page = await see(mode="content")
row = cut_out(page)
(rows if row["caption"] else errors).append(row)
return {"n_ok": len(rows), "n_failed": len(errors),
"sample": rows[:3], "errors": errors[:5]}
The shape of a real browser reflex, shortened.
tools: every tool the agent has, which you can also call by name directly.var: the run's inputs, plus the reflex's workspace folder.llm: a judgement call (below).step: a guarded action that never repeats (below).- It runs as its own process, in the agent's workspace. API keys are stripped from its environment. It runs with your computer's permissions, so the approval to run it matters (see Approvals).
- Up to 60 tool calls per run. The 61st raises an error the program can catch. There's no time limit: a reflex that sends out helpers can run for minutes.
- Browser reflexes get their own tab, and your tab is put back afterwards.
Judgement calls: llm()
await llm("which of these is the official source?", context=rows)asks one small, bounded question and returns the answer as text. It's a plain question to a model, not an agent with tools.- Answers are cached on your computer. The same question with the same context and model is answered from the cache, so a repeat costs nothing.
- Never one
llm()per row. Use one call to make a template, then let Python apply it to every row. - If a judgement call fails, it returns a message starting with
(llm bridge error, and the program should check for that. - A real hole costs around a tenth of a cent.
Steps that never repeat: step()
For actions that change the world (send, post, write), step("send invoice", action=send, is_done=already_sent) checks the real state first and skips the action if it's already done. That keeps a re-run from sending twice.
Reflexes running reflexes
A reflex can run other reflexes: one manager driving many workers, up to three levels deep. Loops (A → B → A) are refused. Each child gets its own 60 calls. Past three levels, hand the work to a helper agent instead.
What comes back
- The program's return value, plus how many judgement and tool calls it made and how long it took. Any files it created are listed. A large return is stored outside the conversation like any big result.
ok: truemeans the program ran without crashing. It does not mean the data is good. That's what the returned evidence is for.
Writing and fixing one
The agent uses one tool, reflex:
| action | does |
|---|---|
shapes |
shows each tool's real parameters and what it really returns, so the program reads the right fields |
write |
saves the program. Writing is saving, so it's checked first |
run |
runs it with inputs |
open |
shows the program and the input names it expects. The agent opens a reflex before its first run in a chat, and never guesses input names |
edit |
changes one exact piece, re-checks, and saves. A change that breaks the program isn't saved |
review |
lists reflexes that fail more than they work, near-duplicates, ones run cleanly 5+ times, and ones with no trigger |
delete |
removes it |
Checked before it's saved. Syntax, an async main, tools that exist and are attached (with a hint to attach one that isn't), a missing await, and wrong argument names. Two of these checks exist because real reflexes failed:
- one passed tool names as main's parameters and burned 14 calls
- three saved cleanly but called a tool the agent didn't have, and failed on their first run
It needs a "use when…" trigger of 6+ words naming a real situation, the same rule as skills and recipes. That's how Irene finds it again without you asking.
Saving under the same name replaces it; the old version is kept in a .replaced folder.
When a run fails, the agent sees the real one-line error (never a wall of traceback), and fixes the one broken line with edit rather than rewriting the program. One real reflex failed four times on name 'execute_command' is not defined until the agent used the tool's real name.
Before writing or editing a reflex, Irene reads its built-in skill writing-reflexes: the program contract, how llm() behaves, how to check a tool's real output first, and worked examples. You can read it in Capabilities → Skills.
Lifecycle
| loop | what happens |
|---|---|
| Written mid-job | An agent about to make the same call a third time, or open a fourth page of the same shape, writes a reflex instead |
| Offered by dreaming | After a job, dreaming asks will this shape of work come back on new inputs? If yes, a "Worth keeping" card offers to save it as a reflex — the button fills your message box and you press send. Nothing is saved without that send, and a ✕ is remembered |
| Adapts | New inputs mean the same reflex, run again. A slightly different job means Irene opens the reflex, edits it, and saves it under a new name, which costs far less than starting over |
| Repaired | A failed run gets its one broken line fixed |
| Sharpened | If you corrected what a reflex produced, Irene asks change it always, or just this once? /evolve <name> does the same |
| Never pays twice | Repeated judgement questions come from the cache; guarded steps check before acting |
| Kept honest | review and /evolve flag reflexes that fail more than they succeed |
Ask for one yourself
"Make this a reflex so I can run it on any list of posts."
A reflex fits any job you could write as a fixed list of steps: open these, read that, count, sort, total. If you can't name every step up front ("explore until you find the bug"), it isn't a reflex. Irene does that kind of job by hand or hands it to a helper.
/forge <task> goes further: Irene plans the whole task out loud as steps to run as programs and steps to do live, shows you, then builds the reflexes.
Approvals
- The first reflex action in a chat asks you. "Always allow" then trusts reflexes for that chat.
- Writing, editing and deleting a reflex always ask, even when trusted or in auto mode.
- Inside a running reflex, its tool calls aren't approved one by one. The reflex is one unit you trusted. That's why reflexes are saved only with your yes. Hooks still apply, and a hook that blocks a call stops the whole run. In reflex mode this changes: reads run freely and every send or write inside the reflex asks you first. See When should I use reflex mode?
- On the board or a schedule, a reflex runs without a chat. Its inputs are checked first, and a missing one fails in plain words before anything runs.
Find your reflexes
- Capabilities → Routines → Run lists every reflex: its name, healthy or failing, and "Fires when…" with its trigger. A failing one says "Fails more than it succeeds — fix it in a chat."
- To see a program, ask the agent to open it.
- On the board, a card can run a reflex every morning. It's the cheapest thing you can schedule: no model at all unless the reflex asks one.
Built-in reflexes (25): - for coding: understand code, audit for a rule, check my diff, apply many edits, write tests, investigate in parallel - for research: quick web brief, cited research brief, Gmail recent summary, extract fields from many files - for the browser: paginate and extract, extract across many pages, batch a site's own data feed - for spreadsheets: add a total row to every sheet, normalise many CSVs into a workbook, roll up many workbooks - for design: caption and burn, deliver every placement, make the icon set, normalise audio loudness, preflight for print, render a turntable loop - for the desktop: play a song on Spotify, prepare a message, toggle light/dark mode
Irene runs these before writing new ones.
What it costs
| part | cost |
|---|---|
| Writing the reflex | one short turn |
A run with no llm() steps |
no model usage: it runs on your computer |
Each llm() step |
one small call (around a tenth of a cent), and free on a repeat |
| Pages and files read inside | never added to the conversation |
Observability → Savings → Reflexes ("a long back-and-forth compiled into one program") shows what each run saved compared with the agent doing it by hand. A run that cost more shows as a loss. Unpriced runs show "—".
Limits
- A reflex can't stop to ask you a question. Irene gathers what it needs first.
- 60 tool calls per run, three levels deep.
- It runs with your computer's permissions, so only approve reflexes you'd let an agent run.
- "ok" means it ran. Read the evidence it returns. When a site changes, a run will start failing or come back thin, and Irene repairs it.
Related
- Skill: writing-reflexes (Capabilities → Skills)
- When should I use reflex mode?: normal mode vs reflex mode, measured.
- Browser agent · Recipes · Skills & Capabilities
- Dreaming & offers · Offload
[Ask Irene about this]
Updated