Errors
The errors the SDK raises, with their bases. except agents.AgentsError catches every failure a stable call raises, from the SDK or from where the agent runs. Argument errors stay ValueError or TypeError, and a cancelled call raises asyncio.CancelledError.
Reusing an idempotency_key= with other options raises SessionIdempotencyConflictError. Sending to a subagent's session raises an agents.UnsupportedSessionProcedureError.
| Name | What it is |
|---|---|
AgentsError | The base of the errors the SDK raises. |
SdkError | A call the SDK refuses, such as one with a wrong argument value or one on a local runtime that has closed. |
SessionNotFoundError | A call named a session that does not exist, or that you cannot read. |
TurnNotFoundError | A turn handle named a turn its session does not have. |
InvalidCursorError | after= is not a position of the session it reads. |
ObservationLost | The session's events, or the open callbacks of its subagents, could not be read again after the connection was lost, or the events' stream ended. |
OutcomeUnknownError | The SDK could not confirm in time whether the session started or the request applied. |
SessionStartupTimeoutError | The session was created, but it was not ready before the deadline. |
SessionBusyError | The session cannot take the message now, and nothing was applied. |
SessionConfigMismatchError | The agent that continues a saved local session is not the agent that started it. |
SessionInUseError | Another process has this saved local session open, so this one cannot continue it. |
SessionTerminatedError | The session is closed or has ended, and takes no more calls. |
SessionIdempotencyConflictError | An idempotency key was reused for a different request, or the requests cannot be compared. |
LegacySessionError | This session was created by an older version of the platform, and this SDK cannot open it. |
RemoteAgentDeploymentNotFoundError | The deployed agent behind this handle no longer exists, for example after a shutdown. |
APIStatusError | Mistral answered an HTTP request with an error status. |
AuthenticationError | Mistral refused the API key: HTTP 401. |
PermissionDeniedError | The API key may not do this: HTTP 403. |
RateLimitError | Too many requests: HTTP 429. |
InternalServerError | Mistral failed: HTTP 500 or above. |
APIConnectionError | An HTTP request got no answer: the connection failed, or the network dropped it. |
APITimeoutError | An HTTP request timed out. |
UnsupportedAgentFeatureError | Where the agent runs does not support this Agents SDK feature. |
UnsupportedSessionProcedureError | Where the session runs does not support this call, and nothing was sent. |
ClientToolAnswerError | A client tool answer ran, but sending it to the session failed. |
MistralConnectorNotFoundError | A connector name that matches no connector the user who runs the session can see. |
AgentsErrorAgentsError
class AgentsError(Exception)The base of the errors the SDK raises.
except agents.AgentsError catches a failed session or turn call for local and deployed sessions, including an
HTTP error (APIStatusError), a connection error (APIConnectionError) or an error the
session reported, such as SessionBusyError. Argument errors stay ValueError or
TypeError, and a cancelled call raises asyncio.CancelledError.
SdkErrorSdkError
class SdkError(AgentsError, ValueError)A call the SDK refuses, such as one with a wrong argument value or one on a local runtime that has closed.
Sessions and turns
SessionNotFoundErrorSessionNotFoundError
class SessionNotFoundError(AgentsError, LookupError)A call named a session that does not exist, or that you cannot read.
For a deployed agent, either no session has this ID, or the API key in use belongs to a
workspace that cannot read it. For a local session, no session with this ID ran in this
process, or an agents.local_runtime() block freed it and the event loop no longer remembers
it: each loop remembers the newest 10,000. In both cases, scope="tree" of list_sessions
also raises it for a subagent as the root.
| Attribute | Type | Description |
|---|---|---|
session_id | str | The ID the call named. |
TurnNotFoundErrorTurnNotFoundError
class TurnNotFoundError(AgentsError, LookupError)A turn handle named a turn its session does not have.
| Attribute | Type | Description |
|---|---|---|
session_id | str | The ID of the session. |
turn_id | str | The ID the handle named. |
InvalidCursorErrorInvalidCursorError
class InvalidCursorError(SdkError)after= is not a position of the session it reads.
The cursor is not one the session gave, or it is a cursor or a record of another session. A
record or a cursor of another session raises before any read, on iter_events() too. A cursor
the session never gave raises when the session reads it: at the first iteration of
iter_events(), or while the turn runs for result(). cursor is the cursor passed, a
record's cursor for a record. A cursor saved by SDK 1.0 is accepted; the error shows it with
this session's ID.
A program that stores cursors can catch it and read again without one:
try:
state = await turn.result(after=stored_cursor)
except agents.InvalidCursorError:
state = await turn.result()| Attribute | Type | Description |
|---|---|---|
cursor | str | None | The cursor passed, or a record's cursor for a record. |
ObservationLostObservationLost
class ObservationLost(AgentsError, RuntimeError)The session's events, or the open callbacks of its subagents, could not be read again after the connection was lost, or the events' stream ended.
Nothing was stopped: the session keeps running. cursor is the position up to which the events were given,
or None when none was; continue reading after it: no event is missed.
| Attribute | Type | Description |
|---|---|---|
session_id | str | The ID of the session. |
cursor | str | None | The position up to which the events were given, or None when none was. |
OutcomeUnknownErrorOutcomeUnknownError
class OutcomeUnknownError(AgentsError, RuntimeError)The SDK could not confirm in time whether the session started or the request applied.
idempotency_key is the key to retry with, including one the SDK generated, or the
callback ID for a callback answer. It is None for an operation without a key, and for a
start_turn that found another turn running on an agent deployed with an older SDK: that
key would be refused again. Start again with idempotency_key=None, and the SDK makes a new
key.
| Attribute | Type | Description |
|---|---|---|
idempotency_key | str | None | The key to retry with, or the callback ID for a callback answer. None when the operation has no key, or when retrying with the key would be refused again. |
SessionStartupTimeoutErrorSessionStartupTimeoutError
class SessionStartupTimeoutError(OutcomeUnknownError)The session was created, but it was not ready before the deadline.
The session is not cancelled. Use agent.session(session_id) (or
Agent.load_from(agent_name=...).session(session_id) elsewhere) to attach again
without starting another session.
| Attribute | Type | Description |
|---|---|---|
session_id | str | The ID of the created session, to attach again with agent.session(session_id). |
timeout_seconds | float | How long the SDK waited for the session to be ready. |
SessionBusyErrorSessionBusyError
class SessionBusyError(AgentsError, RuntimeError)The session cannot take the message now, and nothing was applied.
It is raised after the request was retried for a while. Retry the same request later.
| Attribute | Type | Description |
|---|---|---|
retry_after | float | None | Seconds to wait before you retry, when the server said; else None. |
SessionConfigMismatchErrorSessionConfigMismatchError
class SessionConfigMismatchError(AgentsError, RuntimeError)The agent that continues a saved local session is not the agent that started it.
A saved session continues only with the same model, instructions, tools and other settings it was saved with. Continue it with that agent, or start a new session.
| Attribute | Type | Description |
|---|---|---|
session_id | str | The ID of the saved session. |
SessionInUseErrorSessionInUseError
class SessionInUseError(AgentsError, RuntimeError)Another process has this saved local session open, so this one cannot continue it.
Saved local sessions (journal_factory= of agents.local_runtime()) take a lock on
their journal while a process has them open. Retry once the other process has left its
agents.local_runtime() block or exited.
| Attribute | Type | Description |
|---|---|---|
session_id | str | The ID of the saved session. |
SessionTerminatedErrorSessionTerminatedError
class SessionTerminatedError(AgentsError, RuntimeError)The session is closed or has ended, and takes no more calls.
SessionIdempotencyConflictErrorSessionIdempotencyConflictError
class SessionIdempotencyConflictError(AgentsError, RuntimeError)An idempotency key was reused for a different request, or the requests cannot be compared.
They cannot be compared when the first request is too old, or when a local call was cancelled after it applied the message but before it recorded the key. In both cases the key's first request was applied, so do not send that message again with a new key. This call applied nothing. Use a new key for a new request.
| Attribute | Type | Description |
|---|---|---|
idempotency_key | str | The key that was reused. |
LegacySessionErrorLegacySessionError
class LegacySessionError(UnsupportedAgentFeatureError)This session was created by an older version of the platform, and this SDK cannot open it.
Every session that agents.Agent starts can be opened. This SDK cannot read, follow or send
to an older one: start a new session.
| Attribute | Type | Description |
|---|---|---|
session_id | str | The ID of the session. |
feature | str | Always "legacy task protocol", the value that marks a session an older version of the platform created. |
reason | str | Why this SDK cannot open the session. |
RemoteAgentDeploymentNotFoundErrorRemoteAgentDeploymentNotFoundError
class RemoteAgentDeploymentNotFoundError(AgentsError, RuntimeError)The deployed agent behind this handle no longer exists, for example after a shutdown.
HTTP errors
APIStatusErrorAPIStatusError
class APIStatusError(AgentsError, httpx.HTTPStatusError)Mistral answered an HTTP request with an error status.
| Attribute | Type | Description |
|---|---|---|
response | httpx.Response | The HTTP response, with its status, headers and body. |
status_code | int | The HTTP status of the response. |
AuthenticationErrorAuthenticationError
class AuthenticationError(APIStatusError)Mistral refused the API key: HTTP 401.
PermissionDeniedErrorPermissionDeniedError
class PermissionDeniedError(APIStatusError)The API key may not do this: HTTP 403.
RateLimitErrorRateLimitError
class RateLimitError(APIStatusError)Too many requests: HTTP 429. The same request may succeed later.
retry_after is the wait in seconds the server named, or None when it named none, for example
for a concurrent session limit. A session start already waits out a Retry-After that ends
within 30 seconds of the start before it raises this error.
| Attribute | Type | Description |
|---|---|---|
retry_after | float | None | Seconds to wait before you retry, when the server said; else None. |
InternalServerErrorInternalServerError
class InternalServerError(APIStatusError)Mistral failed: HTTP 500 or above.
APIConnectionErrorAPIConnectionError
class APIConnectionError(AgentsError, httpx.TransportError)An HTTP request got no answer: the connection failed, or the network dropped it.
It is also an instance of the httpx class that failed, such as httpx.ConnectError. It is
not a builtin ConnectionError.
APITimeoutErrorAPITimeoutError
class APITimeoutError(APIConnectionError, httpx.TimeoutException)An HTTP request timed out. It is not a builtin TimeoutError.
Unsupported features
UnsupportedAgentFeatureErrorUnsupportedAgentFeatureError
class UnsupportedAgentFeatureError(SdkError, RuntimeError)Where the agent runs does not support this Agents SDK feature.
| Attribute | Type | Description |
|---|---|---|
feature | str | The feature that is not supported. |
reason | str | Why it is not supported. |
UnsupportedSessionProcedureErrorUnsupportedSessionProcedureError
class UnsupportedSessionProcedureError(AgentsError, RuntimeError)Where the session runs does not support this call, and nothing was sent.
| Attribute | Type | Description |
|---|---|---|
method | str | The call that is not supported. |
backend | str | An internal name for where the session runs, for logs. |
reason | str | Why the call is not supported. |
Tools and connectors
ClientToolAnswerErrorClientToolAnswerError
class ClientToolAnswerError(AgentsError, RuntimeError)A client tool answer ran, but sending it to the session failed.
callback_id, session_id and turn_id name the call: a subagent's call has the
subagent's session and turn. The send error is the __cause__. The turn keeps running, and the
call fails at its callback timeout: the model gets a tool error. To follow the turn, use
agent.session(session_id).turn(turn_id).
| Attribute | Type | Description |
|---|---|---|
callback_id | str | The ID of the client tool call. |
session_id | str | The ID of the session the call is in: a subagent's for a subagent's call. |
turn_id | str | The ID of the turn the call is in. |
MistralConnectorNotFoundErrorMistralConnectorNotFoundError
class MistralConnectorNotFoundError(AgentsError, LookupError)A connector name that matches no connector the user who runs the session can see.
No name in connectors= raises it: the session starts without that connector and sends an
agents.Notice, whose details["connector"] is the name and details["reason"] names the
close matches. connector_name is the name, and close_matches the names of visible
connectors close to it.
| Attribute | Type | Description |
|---|---|---|
connector_name | str | The authored connector name. |
close_matches | Sequence[str] | The names of visible connectors close to it, if any. |