Skip to content

Commit f7874fe

Browse files
author
Murat Kaan Meral
committed
add bidi agent input type alias
1 parent 328b5dd commit f7874fe

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/strands/experimental/bidirectional_streaming/agent/agent.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
)
3535
from ..models.bidirectional_model import BidiModel
3636
from ..models.novasonic import BidiNovaSonicModel
37+
from ..types.agent import BidiAgentInput
3738
from ..types.events import BidiAudioInputEvent, BidiImageInputEvent, BidiTextInputEvent, BidiInputEvent, BidiOutputEvent
3839
from ..types import BidiIO
3940
from ....experimental.tools import ToolProvider
@@ -42,8 +43,6 @@
4243

4344
_DEFAULT_AGENT_NAME = "Strands Agents"
4445
_DEFAULT_AGENT_ID = "default"
45-
# Type alias for cleaner send() method signature
46-
BidirectionalInput = str | BidiAudioInputEvent | BidiImageInputEvent
4746

4847

4948
class BidiAgent:
@@ -256,7 +255,7 @@ async def start(self) -> None:
256255
logger.debug("Conversation start - initializing connection")
257256
self._agent_loop = await start_bidirectional_connection(self)
258257

259-
async def send(self, input_data: BidirectionalInput) -> None:
258+
async def send(self, input_data: BidiAgentInput) -> None:
260259
"""Send input to the model (text, audio, image, or event dict).
261260
262261
Unified method for sending text, audio, and image input to the model during
@@ -303,24 +302,24 @@ async def send(self, input_data: BidirectionalInput) -> None:
303302
if isinstance(input_data, dict) and "type" in input_data:
304303
event_type = input_data["type"]
305304
if event_type == "bidi_text_input":
306-
input_data = BidiTextInputEvent(text=input_data["text"], role=input_data["role"])
305+
input_event = BidiTextInputEvent(text=input_data["text"], role=input_data["role"])
307306
elif event_type == "bidi_audio_input":
308-
input_data = BidiAudioInputEvent(
307+
input_event = BidiAudioInputEvent(
309308
audio=input_data["audio"],
310309
format=input_data["format"],
311310
sample_rate=input_data["sample_rate"],
312311
channels=input_data["channels"]
313312
)
314313
elif event_type == "bidi_image_input":
315-
input_data = BidiImageInputEvent(
314+
input_event = BidiImageInputEvent(
316315
image=input_data["image"],
317316
mime_type=input_data["mime_type"]
318317
)
319318
else:
320319
raise ValueError(f"Unknown event type: {event_type}")
321320

322321
# Send the reconstructed TypedEvent
323-
await self._agent_loop.model.send(input_data)
322+
await self._agent_loop.model.send(input_event)
324323
return
325324

326325
# If we get here, input type is invalid

src/strands/experimental/bidirectional_streaming/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Type definitions for bidirectional streaming."""
22

3+
from .agent import BidiAgentInput
34
from .io import BidiIO
45
from .events import (
56
DEFAULT_CHANNELS,
@@ -27,6 +28,7 @@
2728

2829
__all__ = [
2930
"BidiIO",
31+
"BidiAgentInput",
3032
# Input Events
3133
"BidiTextInputEvent",
3234
"BidiAudioInputEvent",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Agent-related type definitions for bidirectional streaming.
2+
3+
This module defines the types used for BidiAgent.
4+
"""
5+
6+
from typing import TypeAlias
7+
8+
from .events import BidiAudioInputEvent, BidiImageInputEvent, BidiTextInputEvent
9+
10+
BidiAgentInput: TypeAlias = str | BidiTextInputEvent | BidiAudioInputEvent | BidiImageInputEvent

0 commit comments

Comments
 (0)