-
Notifications
You must be signed in to change notification settings - Fork 912
Expand file tree
/
Copy pathexceptions.py
More file actions
145 lines (96 loc) · 4.92 KB
/
Copy pathexceptions.py
File metadata and controls
145 lines (96 loc) · 4.92 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
"""Exception-related type definitions for the SDK."""
from typing import Any
class EventLoopException(Exception):
"""Exception raised by the event loop."""
def __init__(self, original_exception: Exception, request_state: Any = None) -> None:
"""Initialize exception.
Args:
original_exception: The original exception that was raised.
request_state: The state of the request at the time of the exception.
"""
self.original_exception = original_exception
self.request_state = request_state if request_state is not None else {}
super().__init__(str(original_exception))
class MaxTokensReachedException(Exception):
"""Exception raised when the model reaches its maximum token generation limit.
This exception is raised when the model stops generating tokens because it has reached the maximum number of
tokens allowed for output generation. This can occur when the model's max_tokens parameter is set too low for
the complexity of the response, or when the model naturally reaches its configured output limit during generation.
"""
def __init__(self, message: str):
"""Initialize the exception with an error message and the incomplete message object.
Args:
message: The error message describing the token limit issue
"""
super().__init__(message)
class MaxIterationsReachedException(Exception):
"""Exception raised when the agent reaches its configured ``max_iterations`` limit.
The event loop tracks the number of "model turn -> tool call -> tool result" cycles executed during a single
agent invocation. When this counter exceeds the limit configured on the agent, the loop is terminated
and this exception is raised so callers can handle the situation gracefully (e.g. return a partial response,
surface a timeout to the user, or apply a retry policy with a different strategy).
"""
def __init__(self, message: str, *, iterations: int | None = None, max_iterations: int | None = None) -> None:
"""Initialize the exception.
Args:
message: The error message describing the iteration limit.
iterations: Number of cycles that were executed before the limit was hit.
max_iterations: The configured maximum iteration limit.
"""
self.iterations = iterations
self.max_iterations = max_iterations
super().__init__(message)
class ContextWindowOverflowException(Exception):
"""Exception raised when the context window is exceeded.
This exception is raised when the input to a model exceeds the maximum context window size that the model can
handle. This typically occurs when the combined length of the conversation history, system prompt, and current
message is too large for the model to process.
"""
pass
class MCPClientInitializationError(Exception):
"""Raised when the MCP server fails to initialize properly."""
pass
class ModelThrottledException(Exception):
"""Exception raised when the model is throttled.
This exception is raised when the model is throttled by the service. This typically occurs when the service is
throttling the requests from the client.
"""
def __init__(self, message: str) -> None:
"""Initialize exception.
Args:
message: The message from the service that describes the throttling.
"""
self.message = message
super().__init__(message)
pass
class SessionException(Exception):
"""Exception raised when session operations fail."""
pass
class SnapshotException(Exception):
"""Exception raised when snapshot operations fail (e.g., unsupported schema version)."""
pass
class ProviderTokenCountError(Exception):
"""Thrown when a model provider's native token counting API fails.
This error is used as internal control flow within provider ``count_tokens()`` overrides.
When caught, the provider falls back to the base class heuristic estimation.
"""
pass
class ToolProviderException(Exception):
"""Exception raised when a tool provider fails to load or cleanup tools."""
pass
class StructuredOutputException(Exception):
"""Exception raised when structured output validation fails after maximum retry attempts."""
def __init__(self, message: str):
"""Initialize the exception with details about the failure.
Args:
message: The error message describing the structured output failure
"""
self.message = message
super().__init__(message)
class ConcurrencyException(Exception):
"""Exception raised when concurrent invocations are attempted on an agent instance.
Agent instances maintain internal state that cannot be safely accessed concurrently.
This exception is raised when an invocation is attempted while another invocation
is already in progress on the same agent instance.
"""
pass