Skip to main content

Module error

Module error 

Source
Expand description

§Error Handling for the Agents SDK

This module defines the centralized error handling system for the SDK. It provides a unified Result type and a comprehensive AgentsError enum that covers all potential issues that can arise during an agent’s execution.

§The AgentsError Enum

The AgentsError enum is the primary error type used throughout the SDK. It encapsulates a wide range of possible failures, from API-level errors to internal logic issues like guardrail violations or tool execution failures. The use of thiserror allows for clean and descriptive error messages.

§The Result Type Alias

For convenience, this module provides a Result<T> type alias, which is a shorthand for std::result::Result<T, AgentsError>. This simplifies function signatures throughout the codebase and ensures consistent error handling.

§Example: Using the Custom Result Type

use tower_llm::error::{Result, AgentsError};

fn check_input(input: &str) -> Result<()> {
    if input.is_empty() {
        Err(AgentsError::UserError {
            message: "Input cannot be empty.".to_string(),
        })
    } else {
        Ok(())
    }
}

assert!(check_input("Hello").is_ok());
let error = check_input("").unwrap_err();
assert_eq!(error.to_string(), "User error: Input cannot be empty.");

Error types for the Agents SDK

Enums§

AgentsError
The main error enum for the Agents SDK.

Type Aliases§

Result
A specialized Result type for the Agents SDK.