Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
ModelBehaviorError,
OutputGuardrailTripwireTriggered,
RunErrorDetails,
SessionError,
SessionNotFoundError,
SessionSerializationError,
ToolInputGuardrailTripwireTriggered,
ToolOutputGuardrailTripwireTriggered,
UserError,
Expand Down Expand Up @@ -255,6 +258,9 @@ def enable_verbose_stdout_logging():
"MaxTurnsExceeded",
"ModelBehaviorError",
"UserError",
"SessionError",
"SessionNotFoundError",
"SessionSerializationError",
"InputGuardrail",
"InputGuardrailResult",
"OutputGuardrail",
Expand Down
42 changes: 42 additions & 0 deletions src/agents/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,45 @@ def __init__(self, guardrail: ToolOutputGuardrail[Any], output: ToolGuardrailFun
self.guardrail = guardrail
self.output = output
super().__init__(f"Tool output guardrail {guardrail.__class__.__name__} triggered tripwire")


class SessionError(AgentsException):
"""Exception raised when a session operation fails.

This is the base class for all session-related exceptions, providing
consistent error handling for session storage, retrieval, and manipulation.
"""

session_id: str | None
"""The ID of the session that caused the error, if available."""

def __init__(self, message: str, session_id: str | None = None):
self.session_id = session_id
self.message = message
if session_id:
super().__init__(f"Session '{session_id}': {message}")
else:
super().__init__(message)


class SessionNotFoundError(SessionError):
"""Exception raised when a session cannot be found.

This exception is raised when attempting to retrieve or manipulate
a session that does not exist in the storage backend.
"""

def __init__(self, session_id: str):
super().__init__(f"Session not found", session_id=session_id)


class SessionSerializationError(SessionError):
"""Exception raised when session data cannot be serialized or deserialized.

This exception is raised when session items contain data that cannot
be properly converted to/from the storage format.
"""

def __init__(self, message: str, session_id: str | None = None):
super().__init__(f"Serialization error: {message}", session_id=session_id)

Loading
Loading