Skip to content

Commit 0aaf10d

Browse files
committed
remove exception chain
1 parent f9a093a commit 0aaf10d

File tree

15 files changed

+38
-67
lines changed

15 files changed

+38
-67
lines changed

src/strands/experimental/bidi/_async/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from typing import Awaitable, Callable
44

5-
from ..errors import BidiExceptionChain
65
from ._task_group import _TaskGroup
76
from ._task_pool import _TaskPool
87

@@ -18,14 +17,14 @@ async def stop_all(*funcs: Callable[..., Awaitable[None]]) -> None:
1817
funcs: Stop functions to call in sequence.
1918
2019
Raises:
21-
BidiExceptionChain: If any stop function raises an exception.
20+
RuntimeError: If any stop function raises an exception.
2221
"""
2322
exceptions = []
2423
for func in funcs:
2524
try:
2625
await func()
2726
except Exception as exception:
28-
exceptions.append(exception)
27+
exceptions.append({"func_name": func.__name__, "exception": repr(exception)})
2928

3029
if exceptions:
31-
raise BidiExceptionChain("failed stop sequence", exceptions)
30+
raise RuntimeError(f"exceptions={exceptions} | failed stop sequence")

src/strands/experimental/bidi/agent/loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
BidiInterruptionEvent as BidiInterruptionHookEvent,
2121
)
2222
from .._async import _TaskPool, stop_all
23-
from ..errors import BidiModelTimeoutError
23+
from ..models import BidiModelTimeoutError
2424
from ..types.events import (
2525
BidiConnectionCloseEvent,
2626
BidiConnectionRestartEvent,

src/strands/experimental/bidi/errors.py

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Bidirectional model interfaces and implementations."""
22

3-
from .model import BidiModel
3+
from .model import BidiModel, BidiModelTimeoutError
44
from .nova_sonic import BidiNovaSonicModel
55

66
__all__ = [
77
"BidiModel",
8+
"BidiModelTimeoutError",
89
"BidiNovaSonicModel",
910
]

src/strands/experimental/bidi/models/gemini_live.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from ....types.content import Messages
2626
from ....types.tools import ToolResult, ToolSpec, ToolUse
2727
from .._async import stop_all
28-
from ..errors import BidiModelTimeoutError
2928
from ..types.events import (
3029
AudioChannel,
3130
AudioSampleRate,
@@ -42,7 +41,7 @@
4241
ModalityUsage,
4342
)
4443
from ..types.model import AudioConfig
45-
from .model import BidiModel
44+
from .model import BidiModel, BidiModelTimeoutError
4645

4746
logger = logging.getLogger(__name__)
4847

src/strands/experimental/bidi/models/model.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,23 @@ async def send(
112112
```
113113
"""
114114
...
115+
116+
117+
class BidiModelTimeoutError(Exception):
118+
"""Model timeout error.
119+
120+
Bidirectional models are often configured with a connection time limit. Nova sonic for example keeps the connection
121+
open for 8 minutes max. Upon receiving a timeout, the agent loop is configured to restart the model connection so as
122+
to create a seamless, uninterrupted experience for the user.
123+
"""
124+
125+
def __init__(self, message: str, **restart_config: Any) -> None:
126+
"""Initialize error.
127+
128+
Args:
129+
message: Timeout message from model.
130+
**restart_config: Configure restart specific behaviors in the call to model start.
131+
"""
132+
super().__init__(self, message)
133+
134+
self.restart_config = restart_config

src/strands/experimental/bidi/models/nova_sonic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from ....types.content import Messages
3838
from ....types.tools import ToolResult, ToolSpec, ToolUse
3939
from .._async import stop_all
40-
from ..errors import BidiModelTimeoutError
4140
from ..types.events import (
4241
AudioChannel,
4342
AudioSampleRate,
@@ -54,7 +53,7 @@
5453
BidiUsageEvent,
5554
)
5655
from ..types.model import AudioConfig
57-
from .model import BidiModel
56+
from .model import BidiModel, BidiModelTimeoutError
5857

5958
logger = logging.getLogger(__name__)
6059

src/strands/experimental/bidi/models/openai_realtime.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from ....types.content import Messages
2020
from ....types.tools import ToolResult, ToolSpec, ToolUse
2121
from .._async import stop_all
22-
from ..errors import BidiModelTimeoutError
2322
from ..types.events import (
2423
AudioSampleRate,
2524
BidiAudioInputEvent,
@@ -38,7 +37,7 @@
3837
StopReason,
3938
)
4039
from ..types.model import AudioConfig
41-
from .model import BidiModel
40+
from .model import BidiModel, BidiModelTimeoutError
4241

4342
logger = logging.getLogger(__name__)
4443

src/strands/experimental/bidi/types/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from ....types.streaming import ContentBlockDelta
2828

2929
if TYPE_CHECKING:
30-
from ..errors import BidiModelTimeoutError
30+
from ..models import BidiModelTimeoutError
3131

3232
AudioChannel = Literal[1, 2]
3333
"""Number of audio channels.

src/strands/experimental/hooks/events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
if TYPE_CHECKING:
1616
from ..bidi.agent.agent import BidiAgent
17-
from ..bidi.errors import BidiModelTimeoutError
17+
from ..bidi.models import BidiModelTimeoutError
1818

1919
warnings.warn(
2020
"BeforeModelCallEvent, AfterModelCallEvent, BeforeToolCallEvent, and AfterToolCallEvent are no longer experimental."

0 commit comments

Comments
 (0)