Skip to content

Automation

Automation is how Alfred does things without you being there. It has two halves, and it helps to know which one you’re asking for.

  • A reflex is code Alfred writes and runs when an event happens. No conversation, nobody watching, no AI in the loop.
  • A background agent is an AI worker with its own instructions, model and files. It has no trigger of its own, a reflex is what wakes it.

So a reflex is Alfred acting, and a background agent is Alfred thinking. Most automation only needs the first one.

Automation is part of the Automation module, which you can manage from the Modules Page.

A reflex has three parts:

  1. A trigger, which is the event it listens for. That could be a schedule, a Discord message, an event from a connected client, something on one of your places (a submit, a change, a file sent, a button pressed, a tracker saying something is due or low), records written to your data, a delivery to one of your webhooks, or something one of your jobs did: finishing, failing, being cancelled, parking on something it needs, moving to another phase of its plan, or clocking out a shift.
  2. A handler, which is the code that runs on each matching event and decides what to do.
  3. Optionally a background agent to wake when the handler decides an AI is needed.

The handler ends in one of three outcomes: it ignores the event, it handles the event itself, or it escalates to the background agent. Because the handler is just code, a reflex costs a small sandbox run instead of a full AI message, which is why it’s fine to have a reflex firing all day.

Handlers can call Alfred’s tools, so a reflex can send you a Discord message, write to a card, search the web, or generate an image on its own without waking anything. A handler only gets the tools it was given when it was saved, and nothing else.

A handler can also call another service with one of your keys, without the code ever seeing the key, and ask the judge a yes/no or pick-one question when plain code can’t decide (is this message hostile, which rule does it break), which costs a fraction of a cent rather than a full AI run.

Each reflex also has its own small private store, which is how it remembers things between runs. That’s what lets a reflex count something, notice a change since last time, or avoid telling you about the same thing twice.

You don’t write reflexes yourself, you ask Alfred and he builds it. Some examples:

  • “Every morning at 8, send me a Discord DM with the weather and my reminders for the day.”
  • “Watch this page once a day and message me if the price drops below R500.”
  • “When someone posts in #support, if nobody replied within an hour, ping me.”
  • “After any job about the game finishes, post an announcement in the updates channel.”
  • “Let me know whenever a phase of a job moves forward.”
  • “When Stripe says someone paid, add them to my customers list and DM me their name and the amount.”
  • “Whenever someone opens an issue on my GitHub repo, tell me what it’s about and how urgent it looks.”

The last two run on a webhook: an address Alfred gives you to paste into Stripe’s or GitHub’s settings, so the service tells Butler when something happens. Secrets and webhooks covers setting one up.

Alfred will test the handler before saving it, so if he tells you a reflex failed to save that’s a real error in the code and not a permissions problem.

A reflex on a busy source can fire a lot, so Alfred can attach a few controls:

  • A prefilter drops events before the handler even runs, so nothing is spent on events you don’t care about.
  • Debounce batches events together instead of running once per event, for example ten messages or thirty seconds, whichever comes first.
  • Concurrency decides what a second event does while a run is already going: queue it, run it alongside, or drop it.

You can just describe what you want and Alfred picks sensible values, but it’s worth being specific if you’re pointing a reflex at something noisy.

A reflex that has something to say to you sends it as a message from Alfred, to you and nobody else: “the server’s been down for ten minutes”, “your order shipped”. It lands in your notifications and on Discord if it’s connected, and waits out your quiet hours unless the reflex marks it urgent. Only five urgent messages an hour get through across all your automation; past that they wait like the rest. A run a visitor’s event set off can never send an urgent one.

A schedule runs in a time zone: yours, unless you name another (“every weekday at 9 New York time”). Yours is the one your Dashboard last saw. Editing a reflex keeps the zone it had.

When the clocks change, it depends on how often the schedule fires:

  • Daily or less often keeps the time on the clock. “Every day at 9” is nine in winter and in summer. A time that doesn’t exist on the night the clocks go forward (2:30 in a zone that skips from 2:00 to 3:00) fires at the moment the clocks jump, and a time that happens twice when they go back fires once, the first time.
  • Hourly or more often keeps real time. “Every hour” is sixty real minutes apart, even across the change, so the clock times it fires at shift by the change.

A schedule can fire as often as once a minute. Schedules made before time zones existed run on UTC, as they always did. Ask Alfred to set a zone on one if it’s drifting by an hour.

A single run gets about ten seconds. A reflex with more to do than that (going through a long list, a big import) can carry on where it left off: the run ends saying how far it got, and runs again straight away on the same event from that point. All of those together count as one run, for its limits and in its history, up to 20 continuations and two minutes of running in total. Ask for the work and Alfred writes the handler that way when it needs it.

A button on a page has to answer in one run, so it can’t carry on like this.

Every run is held to a short time budget, at most one agent wake, and a spending limit for its tool calls (five cents by default, up to a dollar if you raise it for one reflex). What its tool calls may do is counted by what they do rather than how many there are:

A tool call thatPer runAcross all your reflexes
Only readsNot countedNot counted
Sends a message5600 an hour, 3,000 a day
Changes or publishes something20A cap on how much they carry an hour

A call over one of these is refused, naming the limit and when it resets, and you’re told once; nothing is paused for it. Your reflexes together also run at most 2,000 times an hour and 20,000 a day.

A reflex is paused if it runs away (far past its rate within a minute) or fails ten runs in a row, and you’re told. Before that point, if it starts failing (at least half of five or more runs in the last hour, or its last three in a row, however far apart), you get a notice once an hour saying so, so you can look before it’s paused.

Ask Alfred to list your reflexes and he’ll show you what each one does, what it last did, and whether it’s currently paused. He can also read a reflex’s recent runs, the last 50 over the past week: what each decided, how long it took, the tools it called, what it spent, and the error when it failed.

  • “Why did the price watcher fail last night?”
  • “Show me what the support reflex has done today.”
  • “Pause the morning digest.”

Add a background agent when a run needs actual judgement, writing, or a conversation with you. An agent has its own instructions, its own model, and its own files, and it can carry a conversation across runs so it can build something up over time.

Because agents have no trigger of their own, every agent needs a reflex pointed at it. Several reflexes can wake the same agent, which is how you’d have one “moderator” agent woken by a few different situations.

Good uses for an agent:

  • Reading through something and writing a summary that’s actually worth reading.
  • Deciding whether something is worth telling you about at all.
  • Producing a document over many runs, a piece at a time.

Bad uses for an agent, where a plain reflex is better:

  • Sending a message at a fixed time.
  • Copying a value from one place to another.
  • Anything where the answer is a simple yes or no.

The handler decides what an agent remembers. escalate(reason, payload, thread) takes an optional third argument, and every run given the same thread picks up the conversation where the last one left it. Pass one when the agent is having a conversation with someone or something, like a channel, a DM or a ticket. Leave it out when each run starts from nothing, like a daily report. If the agent should always remember, pass a constant like "daily": every run then continues one conversation. Background Agents covers what happens when a thread gets long.

For the moderator agent, the reflex passes the channel id, so the agent keeps one conversation per channel instead of mixing them together:

escalate("possible rule break", { text: event.content, author: event.author?.username }, event.channel?.id);

Complex automation needs more handholding from you, so be precise about the shape you want:

“Here’s the outline of a book I want you to write. Create a background agent for each chapter that’ll do its own independent research and write its chapter over time in a chapter.md file. Run 5 background agents at a time, each offset by 1 minute, with a cooldown of 5 minutes inbetween runs. Once a background agent completed its chapter, have it send me a message in Discord DMs. Once we’re through all chapters I’ll come back to you so you can stitch all the chapters together.”

And an example where the reflex does the cheap part and the agent does the thinking:

“Monitor the Butler status page every 10 minutes. If there’s an active incident, wake an agent that scans the forum for related tickets and gives me a sentiment summary with the threads that need attention.”

The check runs as a reflex, so the nine times out of ten where nothing is wrong it costs almost nothing. The agent only runs when there’s something to think about.

Agents created before reflexes existed carry their own built-in trigger. They still run, but they’re frozen: they can’t be edited and a reflex can’t be attached to them.

If you want to change one of those, ask Alfred to build a replacement agent with a reflex and delete the old one.

A reflex runs code with nobody woken. When what you want is Alfred himself picking a conversation back up when something happens (“tell me when the last RSVP is in and we’ll pick a date”), that’s a watch.

Automation is not a replacement for critical monitoring. Runs can be delayed, paused after repeated failures, or limited by your plan and usage allowance. Treat reflexes and agents as helpful automation, not as guaranteed infrastructure.