Errors
Errors
Error types and handling
AgentPackageCompatibilityError class
📍 src/portable/AgentPackage.ts:58
Constructor
constructor
constructor(message: string)
Parameters:
message:string
AIError class
📍 src/domain/errors/AIErrors.ts:5
Custom error classes for the AI library
Constructor
constructor
constructor(
message: string,
public readonly code: string,
public readonly statusCode?: number,
public readonly originalError?: Error
)
Parameters:
message:stringcode:stringstatusCode:number | undefined(optional)originalError:Error | undefined(optional)
ConnectorNotFoundError class
📍 src/domain/errors/AIErrors.ts:25
A connector could not be resolved in the current registry scope. Scoped registries use the same error for missing and hidden connectors so callers cannot distinguish their existence. Other lookup failures must retain their original type. Hosts decide whether absence permits a fallback; no HTTP status is assigned. Diagnostic messages must only list visible connectors.
Constructor
constructor
constructor(message = 'Connector not found in current scope.', originalError?: Error)
Parameters:
message:string(optional) (default:'Connector not found in current scope.')originalError:Error | undefined(optional)
ContextOverflowError class
📍 src/domain/errors/AIErrors.ts:426
Error thrown when context cannot be reduced to fit within limits after all graceful degradation levels have been exhausted.
Constructor
constructor
constructor(
message: string,
/** Detailed budget information for debugging */
public readonly budget: ContextOverflowBudget
)
Parameters:
message:stringbudget:ContextOverflowBudget
Methods
getDegradationSummary()
Get a formatted summary of what was tried
getDegradationSummary(): string
Returns: string
getTopConsumers()
Get the top token consumers
getTopConsumers(count = 5): Array<{ component: string; tokens: number }>
Parameters:
count:number(optional) (default:5)
Returns: { component: string; tokens: number; }[]
DependencyCycleError class
📍 src/domain/errors/AIErrors.ts:272
Error thrown when a dependency cycle is detected in a plan
Constructor
constructor
constructor(
/** Task IDs forming the cycle (e.g., ['A', 'B', 'C', 'A']) */
public readonly cycle: string[],
/** Plan ID where the cycle was detected */
public readonly planId?: string
)
Parameters:
cycle:string[]planId:string | undefined(optional)
ErrorHandler class
📍 src/core/ErrorHandler.ts:122
Centralized error handling for all agent types.
Features:
- Consistent error logging with context
- Automatic retry with exponential backoff
- Error classification (recoverable vs fatal)
- Metrics collection
- Event emission for monitoring
Example:
const errorHandler = new ErrorHandler({
maxRetries: 3,
logErrors: true,
});
// Handle an error
errorHandler.handle(error, {
agentType: 'agent',
operation: 'run',
});
// Execute with retry
const result = await errorHandler.executeWithRetry(
() => riskyOperation(),
{ agentType: 'agent', operation: 'riskyOperation' }
);
Constructor
constructor
constructor(config: ErrorHandlerConfig = {})
Parameters:
config:ErrorHandlerConfig(optional) (default:{})
Methods
handle()
Handle an error with context. Logs the error, emits events, and records metrics.
handle(error: Error, context: ErrorContext): void
Parameters:
error:Errorcontext:ErrorContext
Returns: void
executeWithRetry()
Execute a function with automatic retry on retryable errors.
async executeWithRetry<T>(
fn: () => Promise<T>,
context: ErrorContext
): Promise<T>
Parameters:
fn:() => Promise<T>context:ErrorContext
Returns: Promise<T>
wrap()
Wrap a function with error handling (no retry). Useful for wrapping methods that already have their own retry logic.
wrap<TArgs extends unknown[], TResult>(
fn: (...args: TArgs) => Promise<TResult>,
contextFactory: (...args: TArgs) => ErrorContext
): (...args: TArgs) => Promise<TResult>
Parameters:
fn:(...args: TArgs) => Promise<TResult>contextFactory:(...args: TArgs) => ErrorContext
Returns: (...args: TArgs) => Promise<TResult>
isRecoverable()
Check if an error is recoverable (can be retried or handled gracefully).
isRecoverable(error: Error): boolean
Parameters:
error:Error
Returns: boolean
isRetryable()
Check if an error should be retried.
isRetryable(error: Error): boolean
Parameters:
error:Error
Returns: boolean
addRetryablePattern()
Add a retryable pattern.
addRetryablePattern(pattern: string): void
Parameters:
pattern:string
Returns: void
removeRetryablePattern()
Remove a retryable pattern.
removeRetryablePattern(pattern: string): void
Parameters:
pattern:string
Returns: void
getConfig()
Get current configuration (read-only).
getConfig(): Readonly<Required<ErrorHandlerConfig>>
Returns: Readonly<Required<ErrorHandlerConfig>>
EvidenceError class
📍 src/core/evidence/validation.ts:5
Messages contain no source payloads, credentials, or backend exception text.
Constructor
constructor
constructor(readonly code: 'invalid' | 'capacity' | 'corrupt' | 'busy' | 'storage')
Parameters:
code:"invalid" | "capacity" | "corrupt" | "busy" | "storage"
FactSupersededError class
📍 src/memory/MemorySystem.ts:245
F1 — thrown by restoreFact when the target fact was superseded by a later
non-archived fact. Un-archiving the predecessor without first handling the
successor would leave two "current" values for the same predicate, breaking
ranking and the singleValued invariant. Callers handle this by (a) archiving
the successor first, or (b) using memory_forget on the successor.
Constructor
constructor
constructor(factId: FactId, supersededBy: FactId)
Parameters:
factId:stringsupersededBy:string
Properties
| Property | Type | Description |
|---|---|---|
factId |
factId: string |
- |
supersededBy |
supersededBy: string |
- |
HelperOutputError class
📍 src/core/model-execution/ModelExecutor.ts:58
Constructor
constructor
constructor(message: string)
Parameters:
message:string
InvalidConfigError class
📍 src/domain/errors/AIErrors.ts:224
Constructor
constructor
constructor(message: string)
Parameters:
message:string
JsonParseError class
Error thrown by {@link parseJsonPermissive} when every strategy fails. Carries the first 500 chars of the raw input for debugging.
Constructor
constructor
constructor(message: string, rawText: string)
Parameters:
message:stringrawText:string
Properties
| Property | Type | Description |
|---|---|---|
rawSnippet |
rawSnippet: string |
First 500 chars of the raw text that failed to parse. |
MCPConnectionError class
📍 src/domain/errors/MCPError.ts:27
Connection-related errors (failed to connect, disconnected unexpectedly)
Constructor
constructor
constructor(message: string, serverName?: string, cause?: Error)
Parameters:
message:stringserverName:string | undefined(optional)cause:Error | undefined(optional)
MCPError class
📍 src/domain/errors/MCPError.ts:10
MCP Error Classes
Error hierarchy for MCP-related failures.
Constructor
constructor
constructor(
message: string,
public readonly serverName?: string,
public readonly cause?: Error
)
Parameters:
message:stringserverName:string | undefined(optional)cause:Error | undefined(optional)
MCPProtocolError class
📍 src/domain/errors/MCPError.ts:52
Protocol-level errors (invalid message, unsupported capability)
Constructor
constructor
constructor(message: string, serverName?: string, cause?: Error)
Parameters:
message:stringserverName:string | undefined(optional)cause:Error | undefined(optional)
MCPResourceError class
📍 src/domain/errors/MCPError.ts:77
Resource-related errors (resource not found, subscription failed)
Constructor
constructor
constructor(
message: string,
public readonly resourceUri: string,
serverName?: string,
cause?: Error
)
Parameters:
message:stringresourceUri:stringserverName:string | undefined(optional)cause:Error | undefined(optional)
MCPTimeoutError class
📍 src/domain/errors/MCPError.ts:37
Timeout errors (request timeout, connection timeout)
Constructor
constructor
constructor(
message: string,
public readonly timeoutMs: number,
serverName?: string,
cause?: Error
)
Parameters:
message:stringtimeoutMs:numberserverName:string | undefined(optional)cause:Error | undefined(optional)
MongoOptimisticConcurrencyError class
📍 src/memory/adapters/mongo/MongoMemoryAdapter.ts:70
Constructor
constructor
constructor(message: string)
Parameters:
message:string
OptimisticConcurrencyError class
📍 src/memory/adapters/inmemory/InMemoryAdapter.ts:707
Constructor
constructor
constructor(message: string)
Parameters:
message:string
OwnerRequiredError class
📍 src/memory/AccessControl.ts:153
Thrown when a record would be created without an ownerId AND the calling
scope carries no userId either. Every record must have an owner — either
set explicitly by the caller (admin delegation) or inherited from
scope.userId.
Constructor
constructor
constructor(public readonly recordKind: 'entity' | 'fact')
Parameters:
recordKind:"entity" | "fact"
PermissionDeniedError class
📍 src/memory/AccessControl.ts:134
Thrown by MemorySystem when a caller attempts a mutation against a record whose effective permissions deny write access. Reads that are denied return empty results rather than throwing (storage filters them out).
Constructor
constructor
constructor(
public readonly recordId: string,
public readonly recordKind: 'entity' | 'fact',
public readonly operation: Permission,
)
Parameters:
recordId:stringrecordKind:"entity" | "fact"operation:Permission
ProfileGeneratorMissingError class
📍 src/memory/MemorySystem.ts:204
Constructor
constructor
constructor()
ProviderAmbiguousOperationError class
📍 src/domain/errors/AIErrors.ts:206
A paid/external submission may have succeeded even though no handle was received.
Constructor
constructor
constructor(
public readonly providerName: string,
public readonly operation: string,
public readonly recoveryMetadata?: Record<string, unknown>,
originalError?: Error,
)
Parameters:
providerName:stringoperation:stringrecoveryMetadata:Record<string, unknown> | undefined(optional)originalError:Error | undefined(optional)
ProviderAuthError class
📍 src/domain/errors/AIErrors.ts:45
Constructor
constructor
constructor(providerName: string, message: string = 'Authentication failed')
Parameters:
providerName:stringmessage:string(optional) (default:'Authentication failed')
ProviderCapabilityNotSupportedError class
📍 src/domain/errors/AIErrors.ts:189
Constructor
constructor
constructor(
public readonly providerName: string,
public readonly model: string,
public readonly capability: string,
)
Parameters:
providerName:stringmodel:stringcapability:string
ProviderContextLengthError class
📍 src/domain/errors/AIErrors.ts:95
Constructor
constructor
constructor(
providerName: string,
public readonly maxTokens: number,
public readonly requestedTokens?: number
)
Parameters:
providerName:stringmaxTokens:numberrequestedTokens:number | undefined(optional)
ProviderError class
📍 src/domain/errors/AIErrors.ts:249
Constructor
constructor
constructor(
public readonly providerName: string,
message: string,
statusCode?: number,
originalError?: Error
)
Parameters:
providerName:stringmessage:stringstatusCode:number | undefined(optional)originalError:Error | undefined(optional)
ProviderErrorMapper class
📍 src/infrastructure/providers/base/ProviderErrorMapper.ts:25
Maps provider-specific errors to our unified error types
Static Methods
static mapError()
Map any provider error to our standard error types
static mapError(error: any, context: ProviderErrorContext): AIError
Parameters:
error:anycontext:ProviderErrorContext
Returns: AIError
static extractErrorDetails()
Extract rich error details for logging. Captures status, code, type, cause, headers, and stack from SDK errors.
static extractErrorDetails(error: any): Record<string, unknown>
Parameters:
error:any
Returns: Record<string, unknown>
ProviderMisalignmentError class
📍 src/domain/errors/AIErrors.ts:58
OpenAI safety monitor stopped a request for a potential misalignment policy violation.
Constructor
constructor
constructor(
public readonly providerName: string,
message: string,
public readonly requestId?: string,
public readonly responseId?: string,
public readonly details?: unknown,
originalError?: Error,
)
Parameters:
providerName:stringmessage:stringrequestId:string | undefined(optional)responseId:string | undefined(optional)details:unknown(optional)originalError:Error | undefined(optional)
Properties
| Property | Type | Description |
|---|---|---|
providerCode |
providerCode: "misalignment_policy_violation" |
- |
ProviderNotFoundError class
📍 src/domain/errors/AIErrors.ts:33
Constructor
constructor
constructor(providerName: string)
Parameters:
providerName:string
ProviderRateLimitError class
📍 src/domain/errors/AIErrors.ts:80
Constructor
constructor
constructor(
providerName: string,
public readonly retryAfter?: number
)
Parameters:
providerName:stringretryAfter:number | undefined(optional)
ScopeInvariantError class
📍 src/memory/MemorySystem.ts:197
Constructor
constructor
constructor(message: string)
Parameters:
message:string
ScopeViolationError class
📍 src/memory/adapters/inmemory/InMemoryAdapter.ts:714
Constructor
constructor
constructor(message: string)
Parameters:
message:string
SemanticSearchUnavailableError class
📍 src/memory/MemorySystem.ts:211
Constructor
constructor
constructor(reason: string)
Parameters:
reason:string
StructuredOutputError class
📍 src/core/StructuredOutput.ts:79
Thrown when the model's output cannot be parsed as valid JSON after all repair attempts. Carries the raw output + requested format for debugging — never a silent failure.
Constructor
constructor
constructor(
message: string,
public readonly rawOutput: string,
public readonly format: ResponseFormat,
originalError?: Error,
)
Parameters:
message:stringrawOutput:stringformat:ResponseFormatoriginalError:Error | undefined(optional)
TelegramAPIError class
📍 src/tools/telegram/types.ts:59
Error from Telegram Bot API
Constructor
constructor
constructor(
public readonly statusCode: number,
public readonly errorCode: number | undefined,
public readonly telegramDescription: string
)
Parameters:
statusCode:numbererrorCode:number | undefinedtelegramDescription:string
TelegramConfigError class
📍 src/tools/telegram/types.ts:86
Error for missing Telegram configuration
Constructor
constructor
constructor(message: string)
Parameters:
message:string
TwilioAPIError class
📍 src/tools/twilio/types.ts:64
Error from Twilio API
Constructor
constructor
constructor(
public readonly statusCode: number,
public readonly twilioCode: number | undefined,
public readonly twilioMessage: string
)
Parameters:
statusCode:numbertwilioCode:number | undefinedtwilioMessage:string
TwilioConfigError class
📍 src/tools/twilio/types.ts:91
Error for missing Twilio configuration
Constructor
constructor
constructor(message: string)
Parameters:
message:string
ContextOverflowBudget interface
📍 src/domain/errors/AIErrors.ts:414
Detailed budget information for context overflow diagnosis
Properties
| Property | Type | Description |
|---|---|---|
actualTokens |
actualTokens: number; |
- |
maxTokens |
maxTokens: number; |
- |
overageTokens |
overageTokens: number; |
- |
breakdown |
breakdown: Record<string, number>; |
- |
degradationLog |
degradationLog: string[]; |
- |
ErrorContext interface
Context information for error handling
Properties
| Property | Type | Description |
|---|---|---|
agentType |
`agentType: 'agent' | 'task-agent' |
agentId? |
agentId?: string; |
Optional agent identifier |
operation |
operation: string; |
Operation that failed |
input? |
input?: unknown; |
Input that caused the error (optional, for debugging) |
metadata? |
metadata?: Record<string, unknown>; |
Additional metadata |
ErrorHandlerConfig interface
Configuration for ErrorHandler
Properties
| Property | Type | Description |
|---|---|---|
logErrors? |
logErrors?: boolean; |
Log errors to console/logger. Default: true |
includeStackTrace? |
includeStackTrace?: boolean; |
Include stack traces in logs. Default: true in development, false in production |
transformError? |
transformError?: (error: Error, context: ErrorContext) => Error; |
Custom error transformer |
retryablePatterns? |
retryablePatterns?: string[]; |
Error codes/messages that should be retried |
maxRetries? |
maxRetries?: number; |
Maximum retry attempts. Default: 3 |
baseRetryDelayMs? |
baseRetryDelayMs?: number; |
Base delay for exponential backoff in ms. Default: 100 |
maxRetryDelayMs? |
maxRetryDelayMs?: number; |
Maximum retry delay in ms. Default: 5000 |
ErrorHandlerEvents interface
Events emitted by ErrorHandler
Properties
| Property | Type | Description |
|---|---|---|
error |
error: { error: Error; context: ErrorContext; recoverable: boolean }; |
Emitted when an error is handled |
'error:retrying' |
'error:retrying': { error: Error; context: ErrorContext; attempt: number; delayMs: number }; |
Emitted when retrying after an error |
'error:fatal' |
'error:fatal': { error: Error; context: ErrorContext }; |
Emitted when an error is fatal (no recovery possible) |
IngestionError interface
📍 src/memory/integration/ExtractionResolver.ts:217
Properties
| Property | Type | Description |
|---|---|---|
where |
where: string; |
Which mention label / fact index failed. |
reason |
reason: string; |
- |
StepErrorStrategy type
📍 src/domain/entities/Routine.ts:40
Error handling strategy for deterministic steps.
- 'fail': Abort the routine on step failure (default for preSteps)
- 'continue': Log the error and continue to next step (default for postSteps)
- 'skip-remaining': Stop executing remaining steps but don't fail the routine
type StepErrorStrategy = 'fail' | 'continue' | 'skip-remaining'