Package com.tnsai.exceptions
package com.tnsai.exceptions
Custom exceptions for the TnsAI framework.
This package contains exception classes that represent various error conditions specific to agent operations and framework functionality.
Exception Hierarchy
RuntimeException
│
└── TnsAIException (base exception)
│
├── AgentException
│ ├── AgentInitializationException
│ └── AgentExecutionException
│
├── LLMException
│ ├── LLMConnectionException
│ ├── LLMRateLimitException
│ └── LLMResponseException
│
├── ActionException
│ ├── ActionNotFoundException
│ └── ActionExecutionException
│
└── ConfigurationException
Common Exceptions
| Exception | Cause | Recovery |
|---|---|---|
| LLMRateLimitException | API rate limit hit | Retry with backoff |
| LLMConnectionException | Network issues | Check connectivity |
| ActionNotFoundException | Unknown tool called | Check action registration |
| ConfigurationException | Missing/invalid config | Check env vars |
Usage Example
try {
String response = agent.run("Hello");
} catch (LLMRateLimitException e) {
// Automatic retry is built-in, but if exhausted:
log.warn("Rate limit exceeded after retries", e);
// Implement fallback logic
} catch (LLMConnectionException e) {
log.error("Cannot connect to LLM provider", e);
// Alert ops, use fallback
} catch (ActionExecutionException e) {
log.error("Tool execution failed: {}", e.getActionName(), e);
// Return error to user or retry
} catch (TnsAIException e) {
log.error("Agent error", e);
// Generic handling
}
Design Principles
- Unchecked: All exceptions extend RuntimeException for cleaner code
- Informative: Include context about what failed and why
- Hierarchical: Catch specific or general as needed
- Recoverable: Indicate if recovery is possible
-
ClassDescriptionException thrown when action execution fails.Error categories for action execution failures.Exception thrown when an action requires human approval before execution.Thin
RuntimeExceptionthat wraps a non-TnsAIExceptionthrowable so itsEventContextis preserved at the catch site.Thrown when a configuredWHEN_CONFIGUREDsource is not ready before a run: its file is missing, it holds no unit, or it cannot be read.Why a source is not ready.Exception thrown when an LLM model lacks a required capability.Exception for LLM-related errors (model errors, invalid responses, etc.).Exception for network-related errors (connection failures, DNS issues, etc.).Native error details surfaced from an upstream LLM (or external) provider.Exception for rate limit errors (HTTP 429, quota exceeded).Signals that a task has been completed and the agent loop should terminate.Helper for the catch-side of framework boundaries.Exception for operation timeout errors.Base exception for all TnsAI framework exceptions.Exception thrown when tools are sent to an LLM model that does not support function/tool calling.Thrown when an action violates pre/post conditions or parameter contracts.