-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
351 lines (265 loc) · 11.2 KB
/
Copy patherrors.go
File metadata and controls
351 lines (265 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package sdk
import "errors"
// SDK error types provide typed errors for better error handling and debugging.
// Use errors.Is() to check for specific error types.
// Agent-related errors.
var (
// ErrAgentNil is returned when a nil agent is provided.
ErrAgentNil = errors.New("agent is nil")
// ErrAgentIDRequired is returned when an agent ID is required but not provided.
ErrAgentIDRequired = errors.New("agent ID is required")
// ErrAgentNotFound is returned when an agent is not found in the registry.
ErrAgentNotFound = errors.New("agent not found")
// ErrAgentAlreadyRegistered is returned when trying to register an agent that already exists.
ErrAgentAlreadyRegistered = errors.New("agent already registered")
// ErrNoAgentsAvailable is returned when no agents are available for routing.
ErrNoAgentsAvailable = errors.New("no agents available")
)
// Tool-related errors.
var (
// ErrToolNil is returned when a nil tool is provided.
ErrToolNil = errors.New("tool is nil")
// ErrToolNotFound is returned when a tool is not found.
ErrToolNotFound = errors.New("tool not found")
// ErrToolAlreadyRegistered is returned when trying to register a tool that already exists.
ErrToolAlreadyRegistered = errors.New("tool already registered")
// ErrInvalidToolName is returned when an invalid tool name is provided.
ErrInvalidToolName = errors.New("invalid tool name")
// ErrToolExecutionFailed is returned when a tool execution fails.
ErrToolExecutionFailed = errors.New("tool execution failed")
// ErrToolTimeout is returned when a tool execution times out.
ErrToolTimeout = errors.New("tool execution timed out")
)
// Handoff-related errors.
var (
// ErrInvalidHandoffTarget is returned when an invalid handoff target is specified.
ErrInvalidHandoffTarget = errors.New("invalid handoff target")
// ErrEmptyHandoffChain is returned when an empty handoff chain is provided.
ErrEmptyHandoffChain = errors.New("empty handoff chain")
// ErrHandoffChainTooLong is returned when a handoff chain exceeds the maximum depth.
ErrHandoffChainTooLong = errors.New("handoff chain exceeds maximum depth")
// ErrHandoffFailed is returned when a handoff operation fails.
ErrHandoffFailed = errors.New("handoff failed")
// ErrCircularHandoff is returned when a circular handoff is detected.
ErrCircularHandoff = errors.New("circular handoff detected")
)
// Workflow-related errors.
var (
// ErrWorkflowNil is returned when a nil workflow is provided.
ErrWorkflowNil = errors.New("workflow is nil")
// ErrWorkflowNotFound is returned when a workflow is not found.
ErrWorkflowNotFound = errors.New("workflow not found")
// ErrWorkflowCycleDetected is returned when a cycle is detected in a workflow.
ErrWorkflowCycleDetected = errors.New("workflow cycle detected")
// ErrWorkflowNodeNotFound is returned when a workflow node is not found.
ErrWorkflowNodeNotFound = errors.New("workflow node not found")
// ErrWorkflowNoEntryPoint is returned when a workflow has no entry point.
ErrWorkflowNoEntryPoint = errors.New("workflow has no entry point")
// ErrWorkflowAlreadyRunning is returned when trying to start a workflow that's already running.
ErrWorkflowAlreadyRunning = errors.New("workflow is already running")
// ErrWorkflowNotRunning is returned when trying to operate on a workflow that's not running.
ErrWorkflowNotRunning = errors.New("workflow is not running")
// ErrWorkflowExecutionFailed is returned when workflow execution fails.
ErrWorkflowExecutionFailed = errors.New("workflow execution failed")
)
// Generation-related errors.
var (
// ErrGenerationFailed is returned when text generation fails.
ErrGenerationFailed = errors.New("generation failed")
// ErrGenerationTimeout is returned when generation times out.
ErrGenerationTimeout = errors.New("generation timed out")
// ErrPromptRequired is returned when a prompt is required but not provided.
ErrPromptRequired = errors.New("prompt is required")
// ErrPromptTooLong is returned when a prompt exceeds the maximum length.
ErrPromptTooLong = errors.New("prompt exceeds maximum length")
// ErrInvalidPromptTemplate is returned when a prompt template is invalid.
ErrInvalidPromptTemplate = errors.New("invalid prompt template")
// ErrPromptRenderFailed is returned when prompt template rendering fails.
ErrPromptRenderFailed = errors.New("prompt template rendering failed")
)
// Streaming-related errors.
var (
// ErrStreamingNotSupported is returned when streaming is not supported.
ErrStreamingNotSupported = errors.New("streaming not supported")
// ErrStreamClosed is returned when operating on a closed stream.
ErrStreamClosed = errors.New("stream is closed")
// ErrStreamTimeout is returned when streaming times out.
ErrStreamTimeout = errors.New("stream timed out")
)
// Memory-related errors.
var (
// ErrMemoryNotFound is returned when a memory entry is not found.
ErrMemoryNotFound = errors.New("memory not found")
// ErrMemoryStoreFailed is returned when storing memory fails.
ErrMemoryStoreFailed = errors.New("failed to store memory")
// ErrMemoryRetrieveFailed is returned when retrieving memory fails.
ErrMemoryRetrieveFailed = errors.New("failed to retrieve memory")
)
// RAG-related errors.
var (
// ErrRAGIndexFailed is returned when RAG indexing fails.
ErrRAGIndexFailed = errors.New("RAG indexing failed")
// ErrRAGRetrievalFailed is returned when RAG retrieval fails.
ErrRAGRetrievalFailed = errors.New("RAG retrieval failed")
// ErrRAGNoResults is returned when RAG retrieval returns no results.
ErrRAGNoResults = errors.New("no RAG results found")
// ErrDocumentTooLarge is returned when a document exceeds the maximum size.
ErrDocumentTooLarge = errors.New("document exceeds maximum size")
)
// Guardrail-related errors.
var (
// ErrGuardrailViolation is returned when a guardrail is violated.
ErrGuardrailViolation = errors.New("guardrail violation")
// ErrInputBlocked is returned when input is blocked by guardrails.
ErrInputBlocked = errors.New("input blocked by guardrails")
// ErrOutputBlocked is returned when output is blocked by guardrails.
ErrOutputBlocked = errors.New("output blocked by guardrails")
)
// State-related errors.
var (
// ErrStateNotFound is returned when agent state is not found.
ErrStateNotFound = errors.New("state not found")
// ErrStateSaveFailed is returned when saving state fails.
ErrStateSaveFailed = errors.New("failed to save state")
// ErrStateLoadFailed is returned when loading state fails.
ErrStateLoadFailed = errors.New("failed to load state")
// ErrInvalidState is returned when state is invalid.
ErrInvalidState = errors.New("invalid state")
)
// Cache-related errors.
var (
// ErrCacheMiss is returned when a cache lookup misses.
ErrCacheMiss = errors.New("cache miss")
// ErrCacheStoreFailed is returned when storing in cache fails.
ErrCacheStoreFailed = errors.New("failed to store in cache")
)
// Cost-related errors.
var (
// ErrBudgetExceeded is returned when the cost budget is exceeded.
ErrBudgetExceeded = errors.New("budget exceeded")
// ErrCostTrackingFailed is returned when cost tracking fails.
ErrCostTrackingFailed = errors.New("cost tracking failed")
)
// Plugin-related errors.
var (
// ErrPluginNotFound is returned when a plugin is not found.
ErrPluginNotFound = errors.New("plugin not found")
// ErrPluginLoadFailed is returned when loading a plugin fails.
ErrPluginLoadFailed = errors.New("failed to load plugin")
// ErrPluginInitFailed is returned when plugin initialization fails.
ErrPluginInitFailed = errors.New("plugin initialization failed")
)
// Configuration-related errors.
var (
// ErrInvalidConfig is returned when configuration is invalid.
ErrInvalidConfig = errors.New("invalid configuration")
// ErrMissingConfig is returned when required configuration is missing.
ErrMissingConfig = errors.New("missing required configuration")
)
// LLM-related errors.
var (
// ErrLLMNotAvailable is returned when the LLM is not available.
ErrLLMNotAvailable = errors.New("LLM not available")
// ErrLLMRequestFailed is returned when an LLM request fails.
ErrLLMRequestFailed = errors.New("LLM request failed")
// ErrProviderNotFound is returned when an LLM provider is not found.
ErrProviderNotFound = errors.New("provider not found")
// ErrModelNotSupported is returned when a model is not supported.
ErrModelNotSupported = errors.New("model not supported")
// ErrRateLimited is returned when rate limited by the LLM provider.
ErrRateLimited = errors.New("rate limited")
// ErrContextLengthExceeded is returned when context length is exceeded.
ErrContextLengthExceeded = errors.New("context length exceeded")
)
// Multimodal-related errors.
var (
// ErrUnsupportedContentType is returned when a content type is not supported.
ErrUnsupportedContentType = errors.New("unsupported content type")
// ErrInvalidImageFormat is returned when an image format is invalid.
ErrInvalidImageFormat = errors.New("invalid image format")
// ErrInvalidAudioFormat is returned when an audio format is invalid.
ErrInvalidAudioFormat = errors.New("invalid audio format")
// ErrContentTooLarge is returned when content exceeds size limits.
ErrContentTooLarge = errors.New("content too large")
)
// Batch-related errors.
var (
// ErrBatchEmpty is returned when a batch is empty.
ErrBatchEmpty = errors.New("batch is empty")
// ErrBatchTooLarge is returned when a batch exceeds size limits.
ErrBatchTooLarge = errors.New("batch too large")
// ErrBatchProcessingFailed is returned when batch processing fails.
ErrBatchProcessingFailed = errors.New("batch processing failed")
)
// Resilience-related errors.
var (
// ErrCircuitOpen is returned when a circuit breaker is open.
ErrCircuitOpen = errors.New("circuit breaker is open")
// ErrMaxRetriesExceeded is returned when maximum retries are exceeded.
ErrMaxRetriesExceeded = errors.New("maximum retries exceeded")
// ErrAllFallbacksFailed is returned when all fallbacks fail.
ErrAllFallbacksFailed = errors.New("all fallbacks failed")
)
// IsRetryable returns true if the error is retryable.
func IsRetryable(err error) bool {
if err == nil {
return false
}
retryableErrors := []error{
ErrLLMRequestFailed,
ErrRateLimited,
ErrStreamTimeout,
ErrGenerationTimeout,
ErrToolTimeout,
}
for _, retryable := range retryableErrors {
if errors.Is(err, retryable) {
return true
}
}
return false
}
// IsUserError returns true if the error is caused by invalid user input.
func IsUserError(err error) bool {
if err == nil {
return false
}
userErrors := []error{
ErrPromptRequired,
ErrPromptTooLong,
ErrInvalidPromptTemplate,
ErrGuardrailViolation,
ErrInputBlocked,
ErrInvalidConfig,
ErrMissingConfig,
ErrUnsupportedContentType,
ErrInvalidImageFormat,
ErrInvalidAudioFormat,
ErrContentTooLarge,
}
for _, userErr := range userErrors {
if errors.Is(err, userErr) {
return true
}
}
return false
}
// IsResourceError returns true if the error is related to resource limits.
func IsResourceError(err error) bool {
if err == nil {
return false
}
resourceErrors := []error{
ErrBudgetExceeded,
ErrRateLimited,
ErrContextLengthExceeded,
ErrDocumentTooLarge,
ErrBatchTooLarge,
}
for _, resourceErr := range resourceErrors {
if errors.Is(err, resourceErr) {
return true
}
}
return false
}