Skip to content
Reference

Errors

Every exception Agentling defines, which ones the loop retries, and which ones reach your code.

On this page

agentling.errors defines the exceptions Agentling raises and the ModelError classes adapters raise. Import them from agentling. For handling failures in a running agent, see Handle failures.

The hierarchy#

AgentlingError
├── AgentRunError                 reserved, not raised yet
├── ModelError
│   ├── ModelConnectionError
│   ├── ModelRateLimitError
│   ├── ModelServerError
│   ├── ModelTimeoutError
│   ├── ModelAuthError
│   ├── ModelBadRequestError
│   ├── ModelContextLengthError
│   ├── ModelOutputError
│   └── ModelOutputTruncatedError
├── ToolCallError                 shown to the model, never raised from a run
├── ToolExecutionError            reserved, not raised yet
│   └── ToolTimeoutError          words the timeout result the model sees
├── MemoryLoadError
└── SkillLoadError                reserved, not raised yet

Other exceptions can still reach you: ValueError and TypeError for bad configuration, and any non-ModelError exception an adapter raises, unchanged, because that is a bug in the adapter.

ModelError#

ModelError(message: str = "", *, retryable: bool | None = None,
           retry_after: float | None = None, status: int | None = None)
AttributeDefaultMeaning
retryablethe class's default_retryableWhether the same request might succeed if sent again.
retry_afterNoneSeconds the backend asked the caller to wait, if it said.
statusNoneThe HTTP status, when there was one.
default_retryableFalseClass attribute; subclasses set their own.

The loop retries a turn only when it raised a ModelError with retryable=True before yielding anything, under the agent's RetryPolicy. Every other ModelError ends the run and is raised from run() or resume().

ClassRaise it whenRetryable by default
ModelConnectionErrorThe backend can't be reached: DNS, a refused or dropped connection.yes
ModelRateLimitErrorHTTP 429. Pass the Retry-After value as retry_after.yes
ModelServerErrorHTTP 5xx, or the backend reports an overload.yes
ModelTimeoutErrorThe request timed out. The loop also raises it when a chunk takes longer than model_timeout.yes
ModelAuthErrorHTTP 401 or 403, or the backend's own "bad key" error.no
ModelBadRequestErrorThe backend rejected the request itself: an unknown model, a bad field, another 4xx.no
ModelContextLengthErrorThe conversation no longer fits the context window.no
ModelOutputErrorThe output can't be used. The loop raises it when provider_data isn't JSON-serialisable.no
ModelOutputTruncatedErrorRaised by the loop when the output limit cuts a tool call short. Adapters don't raise it.no

When a turn's tool calls can't be parsed (a missing name, arguments that aren't a JSON object), the loop doesn't raise straight away. It tells the model what was wrong and asks again, up to twice in a row, then raises a plain ModelError whose message says how many turns failed. If the turn also stopped at the output limit, it raises ModelOutputTruncatedError at once instead.

Other classes#

ClassRaised byMeaning
AgentlingErrornever directlyBase class for every Agentling error.
ToolCallErrorargument validation, or your toolA tool call had bad arguments. The model sees the message and can fix the call. See Tools.
ToolTimeoutErrornobodyA tool ran past its timeout. The loop uses it only to word the error result the model sees.
MemoryLoadErrorMemory.from_dict, Memory.load_jsonSaved memory has an unknown version, an unknown step type or a missing field. See Memory.
AgentRunError, ToolExecutionError, SkillLoadErrornobody yetReserved and exported so code can catch them once they are raised. A bad SKILL.md raises ValueError or yaml.YAMLError today.

What the model sees instead#

A tool that raises doesn't end the run. Its exception becomes the tool's result, marked as an error, with a hint: "Fix the arguments and try again" for a ToolCallError, "Consider a different approach or tool" for anything else, a timeout, or an unknown tool name. With redact_errors=True the message of an unexpected exception is logged instead of shown; ToolCallError messages are always shown.

Example#

from agentling import Agent, ChatMessage, ModelAuthError, ModelServerError, RetryPolicy
from agentling.testing import ScriptedModel
 
for name, cls in [("server", ModelServerError), ("auth", ModelAuthError)]:
    print(name, "retryable:", cls.default_retryable)
 
model = ScriptedModel([ModelServerError("overloaded"), ChatMessage("assistant", "ok")])
agent = Agent(model=model, retry=RetryPolicy(base_delay=0, jitter=0))
print(await agent.run("hi"), len(model.calls))
 
agent = Agent(model=ScriptedModel([ModelAuthError("bad key", status=401)]))
try:
    await agent.run("hi")
except ModelAuthError as exc:
    print(type(exc).__name__, exc.status, exc.retryable)

Output:

server retryable: True
auth retryable: False
ok 2
ModelAuthError 401 False
Was this page helpful?