Handle every outcome
A well-behaved agent does one of four things with a result: use it, fix the request, wait, or stop and tell its user. This page says which, for every status and code.
The rule that matters most
Section titled “The rule that matters most”Never submit an action again with a new key unless you know the first attempt did not take effect. If a call times out, retry with the same key. Sefra returns the original result and does not repeat the action.
Read status before code. If the status is needs_intervention or resolved_manually, do not resubmit, even if the error says retryable: true. Part of the action may have taken effect.
By execution status
Section titled “By execution status”| Status | Final | What the agent should do |
|---|---|---|
succeeded |
Yes | Use steps[].output |
pending_approval |
No | Tell the user who must approve. Poll every poll_after_s seconds, or cancel if no longer needed |
executing |
No | Poll every poll_after_s seconds |
compensating |
No | Poll. Earlier steps are being undone |
rejected |
Yes | Read error. Fix the request if the code allows it, otherwise tell the user |
failed |
Yes | Nothing took effect. Read error and decide whether to try again later with a new key |
rolled_back |
Yes | Every completed step was undone. Tell the user why |
needs_intervention |
No | Stop. Do not resubmit. Tell the user an operator is handling it. Poll slowly |
resolved_manually |
Yes | An operator closed it by hand. Do not resubmit without asking the user |
By error code
Section titled “By error code”“Retry” means the same input may succeed later. If the request was refused before it was accepted, its key is still free. If it was accepted and ended as failed, use a new key. The advice below applies only when the status is rejected or failed.
Fix the request
Section titled “Fix the request”| Code | Meaning | What to do |
|---|---|---|
SCHEMA_VIOLATION |
The input does not match the schema | Correct each field listed in violations |
PLAN_INVALID |
Too many steps, a bad reference, a duplicate step id, or an irreversible step that is not last | Correct the plan |
IDEMPOTENCY_KEY_MISSING |
A write has no key, or a malformed one | Send a key of 16 to 128 letters, digits, - or _ |
IDEMPOTENCY_KEY_REUSED |
This key was used with different input | Use a new key if this really is a new action |
POLICY_DENIED |
A rule refused the request | Read violations[].hint. Change the request, or tell the user. Do not retry it unchanged |
Wait and retry
Section titled “Wait and retry”| Code | Meaning | What to do |
|---|---|---|
RATE_LIMITED |
Too many calls | Wait retry_after_s seconds |
FACT_UNAVAILABLE |
Sefra could not read data it needs to decide | Retry later with backoff |
DOWNSTREAM_UNAVAILABLE |
Your system stayed unavailable through all retries | If the status is failed, retry later with a new key |
PAUSED |
An operator paused all execution | Tell the user, and retry later |
INTENT_DISABLED |
An operator disabled this action | Tell the user, and retry later |
LICENSE_EXPIRED |
This Sefra deployment runs on a trial or pilot licence that has ended | Tell the user. An operator must install a licence |
Stop and tell the user
Section titled “Stop and tell the user”| Code | Meaning | What to do |
|---|---|---|
PRINCIPAL_SUSPENDED |
This agent is suspended, by an operator or after repeated refusals | Stop all work and tell the user |
UNKNOWN_INTENT |
The intent does not exist, or this agent has no grant for it | Do not guess another. Ask for access |
POLICY_ERROR |
The policy failed to evaluate, so Sefra refused | Tell the user. An operator must fix the policy |
APPROVAL_DENIED |
A person refused | Do not resubmit. Read the outcome to the user |
APPROVAL_EXPIRED |
Nobody decided in time | Ask the user whether it is still needed |
APPROVAL_SCOPE_EXCEEDED |
A step needed an approval that the plan’s approval did not cover | Tell the user. Submit it again only if they ask |
CANCELLED |
The agent or an operator cancelled it | Do not resubmit without being asked |
DOWNSTREAM_REJECTED |
Your system refused the call | Tell the user what it said. Retry only with changed input |
DOWNSTREAM_OUTCOME_UNKNOWN |
The call may or may not have taken effect | Do not resubmit. An operator will settle it |
Reading an execution
Section titled “Reading an execution”| Code | Meaning | What to do |
|---|---|---|
UNKNOWN_EXECUTION |
The id does not exist or belongs to another principal | Check the id you stored |
NOT_CANCELLABLE |
The execution is no longer awaiting approval | Read its current status |
A prompt you can give your agent
Section titled “A prompt you can give your agent”Tool descriptions already tell a model how to poll. To make the rest explicit, add this to your agent’s instructions:
When a Sefra tool returns a result:
- If status is pending_approval, tell the user who must approve, then poll with
sefra-get_execution after poll_after_s seconds.
- If the error has violations, use their hint to correct the request. Never repeat
a refused request unchanged.
- If status is needs_intervention or resolved_manually, or the code is
DOWNSTREAM_OUTCOME_UNKNOWN, stop. Do not submit the action again, even if the
error says it is retryable. Tell the user an operator is handling it.
- When retrying after a timeout, reuse the same idempotency_key.