#[non_exhaustive]pub enum Error {
Show 17 variants
AgentInitialization(String),
AgentExecution(String),
Serialization(String),
Content(String),
Tool(String),
ToolRejected(String),
Service(String),
ServiceStatus {
status: u16,
message: String,
retry_after: Option<f64>,
},
ServiceInvalidAuth {
message: String,
},
ServiceInvalidRequest {
message: String,
},
ServiceContentFilter {
message: String,
detail: Option<Box<ContentFilterDetail>>,
},
MiddlewareFailure(String),
Workflow(String),
AdditionItemMismatch(String),
Configuration(String),
Json(Error),
Other(String),
}Expand description
The primary error type for the agent framework.
This mirrors the exception hierarchy used by the Python
agent_framework.exceptions module while remaining idiomatic Rust.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
AgentInitialization(String)
An error occurred while initializing an agent.
AgentExecution(String)
An error occurred while executing an agent run.
Serialization(String)
An error occurred while (de)serializing a value.
Content(String)
A content item could not be parsed or was of an unknown type.
Tool(String)
A tool/function invocation failed.
ToolRejected(String)
A function middleware rejected a tool call (or rewrote its failure) with a message written for the model.
The function-invocation loop absorbs it like any other tool error: the
call’s result is an error result and counts toward
max_consecutive_errors_per_request. Unlike other errors, its message
always reaches the model verbatim, even with include_detailed_errors
off: that setting hides tool-internal diagnostics, while this message
is one the middleware deliberately addressed to the model (a policy
gate’s “call blocked” notice, say). Put nothing in it the model must
not see.
Service(String)
A chat client / service returned an error.
Used for non-HTTP service failures (transport errors, stream-decode
errors, in-body error payloads on an otherwise-successful response). For
a non-success HTTP status, prefer Error::ServiceStatus, which also
carries the status code and any Retry-After.
ServiceStatus
A chat client / service returned a non-success HTTP status.
Distinct from Error::Service so a retry layer can inspect the
numeric status code and any server-advised Retry-After delay (in
seconds). Displays like Error::Service (a service error: ...
message), with the status code folded into the message.
This is the fallback classification for a non-success status that
isn’t one of the more specific variants below (notably 408/429/
5xx, which a retry layer treats as transient) — see
Error::ServiceInvalidAuth, Error::ServiceInvalidRequest, and
Error::ServiceContentFilter for statuses a provider client can
classify more precisely.
Fields
ServiceInvalidAuth
The service rejected the request due to missing or invalid
credentials (typically HTTP 401/403).
Mirrors upstream’s ServiceInvalidAuthError. Like Error::Service,
this carries no status code of its own (the numeric status, when
known, is folded into the message by the provider client) — it exists
so callers, and the default retry policy, can treat authentication /
authorization failures as definitively non-transient without
inspecting a status code themselves. Never retried by
RetryOn::Default.
ServiceInvalidRequest
The service rejected the request as malformed or otherwise invalid
(typically HTTP 400/404/422) for a reason other than content
filtering.
Mirrors upstream’s ServiceInvalidRequestError. See
Error::ServiceContentFilter for the content-filter-specific case.
Never retried by RetryOn::Default
— a request that was rejected as invalid will be rejected again
unchanged.
ServiceContentFilter
The service refused the request (or part of a response) because it tripped a content filter / moderation policy.
Mirrors upstream’s ServiceContentFilterException
(OpenAIContentFilterException for OpenAI/Azure OpenAI specifically).
Never retried by RetryOn::Default
— the content, not the service, is the problem.
Fields
detail: Option<Box<ContentFilterDetail>>The provider’s structured breakdown of why, when the body
carried one. See ContentFilterDetail.
Boxed so the common None costs one pointer rather than the
whole map — this variant sits in an enum every fallible call
returns.
MiddlewareFailure(String)
Function middleware signalled an unrecoverable failure: the run must stop rather than continue with a tool-error result.
The function-invocation loop absorbs every other error a tool or its
middleware produces into a FunctionResultContent { exception, .. },
hands it back to the model, and keeps looping — the right default for
an ordinary tool failure the model can recover from or route around.
An enforcement layer (a guardrail, a policy check, an authorization
gate) needs the opposite: when it refuses a call, the run must fail
closed, not hand the model an error string and let it try again.
Middleware returning this variant gets that fail-closed escape. It is
the only error the loop propagates instead of absorbing; when one of a
parallel batch of calls raises it, the batch’s in-flight siblings are
dropped (cancelled) and the failure surfaces from the run. Mirrors
upstream’s MiddlewareFailure exception (Python #7562).
The signal is carried by the error type, not by who produced it, so a
tool executor that returns this variant is propagated the same way.
Middleware that wants the ordinary absorb-and-continue contract should
keep returning any other variant — Error::Tool is the usual choice.
Workflow(String)
A workflow validation or execution error.
AdditionItemMismatch(String)
Two streamed content items could not be merged (mismatched ids).
Configuration(String)
A required configuration value was missing or invalid.
Json(Error)
An underlying JSON error.
Other(String)
Any other error, wrapping a boxed source.
Implementations§
Source§impl Error
impl Error
Sourcepub fn other(msg: impl Display) -> Error
pub fn other(msg: impl Display) -> Error
Create an Error::Other from anything displayable.
Sourcepub fn service(msg: impl Display) -> Error
pub fn service(msg: impl Display) -> Error
Create an Error::Service from anything displayable.
Sourcepub fn service_status(
status: u16,
msg: impl Display,
retry_after: Option<f64>,
) -> Error
pub fn service_status( status: u16, msg: impl Display, retry_after: Option<f64>, ) -> Error
Create an Error::ServiceStatus from an HTTP status code, a message,
and an optional Retry-After delay (in seconds).
Sourcepub fn service_invalid_auth(msg: impl Display) -> Error
pub fn service_invalid_auth(msg: impl Display) -> Error
Create an Error::ServiceInvalidAuth from anything displayable.
Sourcepub fn service_invalid_request(msg: impl Display) -> Error
pub fn service_invalid_request(msg: impl Display) -> Error
Create an Error::ServiceInvalidRequest from anything displayable.
Sourcepub fn service_content_filter(msg: impl Display) -> Error
pub fn service_content_filter(msg: impl Display) -> Error
Create an Error::ServiceContentFilter from anything displayable.
Sourcepub fn service_content_filter_with_detail(
msg: impl Display,
detail: ContentFilterDetail,
) -> Error
pub fn service_content_filter_with_detail( msg: impl Display, detail: ContentFilterDetail, ) -> Error
As Self::service_content_filter, carrying the provider’s
structured breakdown of which categories tripped.
Sourcepub fn content_filter_detail(&self) -> Option<&ContentFilterDetail>
pub fn content_filter_detail(&self) -> Option<&ContentFilterDetail>
The content-filter breakdown, when this is an
Error::ServiceContentFilter that carried one.
Sourcepub fn status(&self) -> Option<u16>
pub fn status(&self) -> Option<u16>
The HTTP status code carried by this error, if it is an
Error::ServiceStatus.
Sourcepub fn retry_after(&self) -> Option<f64>
pub fn retry_after(&self) -> Option<f64>
The server-advised retry delay in seconds, if this is an
Error::ServiceStatus that carried a Retry-After header.
Sourcepub fn tool(msg: impl Display) -> Error
pub fn tool(msg: impl Display) -> Error
Create an Error::Tool from anything displayable.
Sourcepub fn tool_rejected(msg: impl Display) -> Error
pub fn tool_rejected(msg: impl Display) -> Error
Create an Error::ToolRejected from anything displayable: a tool
error whose message the model sees verbatim.
Sourcepub fn middleware_failure(msg: impl Display) -> Error
pub fn middleware_failure(msg: impl Display) -> Error
Create an Error::MiddlewareFailure from anything displayable: the
fail-closed signal function middleware returns to stop a run outright
instead of having its error absorbed into a tool-error result.
Sourcepub fn is_middleware_failure(&self) -> bool
pub fn is_middleware_failure(&self) -> bool
Whether this error is the Error::MiddlewareFailure fail-closed
signal, which the function-invocation loop propagates rather than
absorbing into a tool-error result.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()