Fields
messagestringThe error's message.
codestringIts code, when it has one — context_too_large, turn_failed, unauthorized.
What is not an error event
| Situation | Reported as |
|---|---|
| A tool threw | tool_end with ok: false — the loop continues |
| A tool was refused | tool_end with refused: true |
| A turn failed and is being retried | retry |
| A model gave up and the next is used | fallback |
| A ceiling was reached | done with stopReason |
An error event means the loop itself could not continue — the turn failed on every model after every retry, the context will not fit, the session is not authorised. Each of those is a condition your code has to react to, not one the agent can work around.
Handling it
import { IaGenifyError, NotEnoughCredits } from "iagenify";
try {
await agent.run({ inputs, onEvent });
} catch (err) {
if (err instanceof NotEnoughCredits) {
// Never retried, on any model. Top up.
} else if (err instanceof IaGenifyError && err.code === "context_too_large") {
await agent.compact();
} else {
throw err;
}
}from iagenify import IaGenifyError, NotEnoughCredits
try:
agent.run(inputs=inputs, on_event=on_event)
except NotEnoughCredits:
pass # Never retried, on any model. Top up.
except IaGenifyError as error:
if error.code != "context_too_large":
raise
agent.compact()The event and the rejection carry the same thing — the event exists so an interface can show it without waiting for the promise to unwind.
A subagent that fails does not fail the run
Its failure is emitted as an error carrying parentId, and the task call ends with ok: false. The parent carries on with that as the tool's result — a delegate that could not do its job is information, not a crash.