Failure Handler
Start another agent automatically whenever an execution of an agent fails, with the failed run's input and the reason it failed.
A failure handler is an agent that Airia starts automatically whenever an execution of another agent fails. Use it to react to failures without watching the executions feed: open a ticket, post to a channel, email the owner, or retry the work a different way.
The failure handler runs however the failed execution was started: from chat, the API, a schedule, a trigger, an email or a batch job.
Failure Handler or Backup Agent
Both are set on the same tab of Agent Settings, but they do different jobs.
| Backup Agent | Failure Handler | |
|---|---|---|
| What it does | Answers instead of the failed agent | Runs after the failed agent, as a separate execution |
| What the caller gets | The backup agent's answer, as if the main agent had succeeded | The failure. The failure handler's result is not returned to the caller. |
| Typical use | Still return an answer when a model or tool is down | Notify someone, record the failure, or start follow-up work |
An agent can have both.
Set a failure handler
To change Agent Settings you need a role with Manage selected under Studio - Agents.
- On the agents list, open the ⋯ menu of the agent and select Agent settings.
- Select the Backup Agent tab.
- Under Failure Handler, pick the agent to start. The list shows the agents in the same project. Select No failure handler to turn it off.
- Save your changes.
The failure handler runs its active (published) version. An agent with no published version can't be started.
The failure handler must be in the same project as the agent it handles. An agent from another project is never started.
When the failure handler runs
The failure handler starts once the failed execution has finished and its status is recorded. It does not start for:
- Cancelled executions, including runs stopped by a user or by an execution stop
- Guardrail blocks: an execution blocked by a guardrail
- Budget refusals: an execution refused because a budget limit was reached
- Sub-agent runs: when an agent fails while running as a sub-agent of another agent, the failure belongs to the calling agent, so only the calling agent's failure handler can start
- Playground runs: test runs from Agent Studio
- Failure handler runs: a failure handler that fails does not start another failure handler, so failures can't chain
The failure handler is started at most once per failed execution. If the platform is interrupted at the moment an execution fails, the failure handler may not start.
What the failure handler receives
The failure handler runs with what the failed execution was given:
- the user input
- the files and images attached to the run
- the run's variables, as they stood when it failed, including values written by Set Variable or Python steps during the run
- prompt variables, and the data source files and folders selected for the run
It also receives four variables that describe the failure:
| Variable | Reference as | Contents |
|---|---|---|
failure_execution_id | {{Variables.failure_execution_id}} | ID of the execution that failed |
failure_agent_id | {{Variables.failure_agent_id}} | ID of the agent that failed |
failure_agent_name | {{Variables.failure_agent_name}} | Name of the agent that failed |
failure_reason | {{Variables.failure_reason}} | The error message of the failure, up to 2,000 characters. When the run recorded no message, it reads The agent execution failed. |
These variables don't need to be declared on the failure handler's Input step. In a Python step, read them as client_data["variables"]["failure_reason"]. See Variables for the expression syntax.
failure_reason is often the message of the step that failed, such as An exception occurred for step …. To give the person you notify more context, include failure_agent_name and failure_execution_id so they can find the failed run in the executions feed.
Example: notify the agent's owner
A minimal failure handler is an Input step followed by an action step that sends a message, such as Slack or Microsoft Outlook. Build the message from the failure variables, for example:
Agent {{Variables.failure_agent_name}} failed.
Execution: {{Variables.failure_execution_id}}
Reason: {{Variables.failure_reason}}Who the failure handler runs as
The failure handler acts as the caller of the failed execution. It runs with the same user and, for an API call, the same API key, so it can open the files it was handed and its run is attributed to that caller. It does not gain any access the failed execution didn't have.
Its execution appears in the executions feed as an execution of the failure handler agent.