Skip to main content

Error hierarchy

All Agent Sentinel errors inherit from AgentSentinelError:

Error structure

Every error includes:
  • Message: Human-readable description
  • Error code: Machine-readable identifier
  • Details: Additional context (dict)
  • Recoverable flag: Whether the operation can be retried

BudgetExceededError

Raised when cost limits are exceeded:

Details

  • spent (float): Current spend amount
  • limit (float): Budget limit
  • budget_type (str): “session”, “run”, or “action”
  • Recoverable: False (budget is truly exceeded)

PolicyViolationError

Raised when an action violates policy rules:

Details

  • policy_rule (str): Which rule was violated (“denied_action”, “allowlist”, “rate_limit”)
  • action_name (str): Name of the blocked action
  • Recoverable: False (policy is enforced)

ReplayDivergenceError

Raised when replay mode detects non-deterministic behavior:

Details

  • action_name (str): Action where divergence occurred
  • expected (any): Expected value from recording
  • actual (any): Actual value from replay
  • Recoverable: False (indicates non-determinism)

NetworkError

Raised on HTTP/network failures when communicating with platform:

Details

  • status_code (int): HTTP status code
  • endpoint (str): API endpoint that failed
  • Recoverable: True for 5xx (server errors), False for 4xx (client errors)

SyncError

Raised when background sync fails to upload telemetry:

Details

  • batch_size (int): Number of records that failed to sync
  • retry_count (int): Current retry attempt
  • Recoverable: True (sync will be retried automatically)

TimeoutError

Raised when an operation exceeds timeout:

Details

  • timeout_seconds (int): Timeout duration
  • operation (str): What timed out (e.g., “approval”, “policy_sync”)
  • Recoverable: True (can retry with longer timeout)

ConfigurationError

Raised on invalid configuration:

Details

  • config_key (str): Configuration parameter that’s invalid
  • value (any): Invalid value (if applicable)
  • Recoverable: False (must fix configuration)

Handling errors gracefully

Pattern: Graceful degradation

Pattern: Retry with backoff

Pattern: Error monitoring

Best practices

Always handle BudgetExceededError: Implement graceful degradation (cheaper models, reduced scope) rather than crashing.
Log PolicyViolationError as security events: These indicate attempted policy violations and should be monitored.
Don’t retry non-recoverable errors: Check error.recoverable before retrying. Configuration errors and policy violations won’t succeed on retry.
Use error details for context: Error details contain rich context - use them for debugging, alerting, and graceful degradation logic.

See also