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

ExceptionCauseRecovery
LLMRateLimitExceptionAPI rate limit hitRetry with backoff
LLMConnectionExceptionNetwork issuesCheck connectivity
ActionNotFoundExceptionUnknown tool calledCheck action registration
ConfigurationExceptionMissing/invalid configCheck 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