Skip to content

Commit 5c30596

Browse files
authored
Merge pull request #28 from mehtarac/rename_agent
Rename bidirectional components
2 parents 3f0a527 + b815706 commit 5c30596

15 files changed

Lines changed: 81 additions & 81 deletions

File tree

src/strands/experimental/bidirectional_streaming/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
"""Bidirectional streaming package."""
22

33
# Main components - Primary user interface
4-
from .agent.agent import BidirectionalAgent
4+
from .agent.agent import BidiAgent
55

66
# IO channels - Hardware abstraction
77
from .io.audio import AudioIO
88

99
# Model interface (for custom implementations)
10-
from .models.bidirectional_model import BidirectionalModel
10+
from .models.bidirectional_model import BidiModel
1111

1212
# Model providers - What users need to create models
13-
from .models.gemini_live import GeminiLiveModel
14-
from .models.novasonic import NovaSonicModel
15-
from .models.openai import OpenAIRealtimeModel
13+
from .models.gemini_live import BidiGeminiLiveModel
14+
from .models.novasonic import BidiNovaSonicModel
15+
from .models.openai import BidiOpenAIRealtimeModel
1616

1717
# Event types - For type hints and event handling
1818
from .types.bidirectional_streaming import (
@@ -29,13 +29,13 @@
2929

3030
__all__ = [
3131
# Main interface
32-
"BidirectionalAgent",
32+
"BidiAgent",
3333
# IO channels
3434
"AudioIO",
3535
# Model providers
36-
"GeminiLiveModel",
37-
"NovaSonicModel",
38-
"OpenAIRealtimeModel",
36+
"BidiGeminiLiveModel",
37+
"BidiNovaSonicModel",
38+
"BidiOpenAIRealtimeModel",
3939

4040
# Event types
4141
"AudioInputEvent",
@@ -48,5 +48,5 @@
4848
"VoiceActivityEvent",
4949
"UsageMetricsEvent",
5050
# Model interface
51-
"BidirectionalModel",
51+
"BidiModel",
5252
]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Bidirectional agent for real-time streaming conversations."""
22

3-
from .agent import BidirectionalAgent
3+
from .agent import BidiAgent
44

5-
__all__ = ["BidirectionalAgent"]
5+
__all__ = ["BidiAgent"]

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
from ....types.content import Message, Messages
2828
from ....types.tools import ToolResult, ToolUse, AgentTool
2929

30-
from ..event_loop.bidirectional_event_loop import BidirectionalAgentLoop
31-
from ..models.bidirectional_model import BidirectionalModel
32-
from ..models.novasonic import NovaSonicModel
30+
from ..event_loop.bidirectional_event_loop import BidiAgentLoop
31+
from ..models.bidirectional_model import BidiModel
32+
from ..models.novasonic import BidiNovaSonicModel
3333
from ..types.bidirectional_streaming import AudioInputEvent, BidirectionalStreamEvent, ImageInputEvent
3434
from ..types import BidiIO
3535
from ....experimental.tools import ToolProvider
@@ -42,7 +42,7 @@
4242
BidirectionalInput = str | AudioInputEvent | ImageInputEvent
4343

4444

45-
class BidirectionalAgent:
45+
class BidiAgent:
4646
"""Agent for bidirectional streaming conversations.
4747
4848
Enables real-time audio and text interaction with AI models through persistent
@@ -51,7 +51,7 @@ class BidirectionalAgent:
5151

5252
def __init__(
5353
self,
54-
model: BidirectionalModel| str | None = None,
54+
model: BidiModel| str | None = None,
5555
tools: list[str| AgentTool| ToolProvider]| None = None,
5656
system_prompt: str | None = None,
5757
messages: Messages | None = None,
@@ -66,7 +66,7 @@ def __init__(
6666
"""Initialize bidirectional agent.
6767
6868
Args:
69-
model: BidirectionalModel instance, string model_id, or None for default detection.
69+
model: BidiModel instance, string model_id, or None for default detection.
7070
tools: Optional list of tools with flexible format support.
7171
system_prompt: Optional system prompt for conversations.
7272
messages: Optional conversation history to initialize with.
@@ -83,9 +83,9 @@ def __init__(
8383
TypeError: If model type is unsupported.
8484
"""
8585
self.model = (
86-
NovaSonicModel()
86+
BidiNovaSonicModel()
8787
if not model
88-
else NovaSonicModel(model_id=model)
88+
else BidiNovaSonicModel(model_id=model)
8989
if isinstance(model, str)
9090
else model
9191
)
@@ -121,7 +121,7 @@ def __init__(
121121
self._tool_caller = _ToolCaller(self)
122122

123123
# connection management
124-
self._agent_loop: "BidirectionalAgentLoop" | None = None
124+
self._agent_loop: "BidiAgentLoop" | None = None
125125
self._output_queue = asyncio.Queue()
126126
self._current_adapters = [] # Track adapters for cleanup
127127

@@ -134,7 +134,7 @@ def tool(self) -> _ToolCaller:
134134
135135
Example:
136136
```
137-
agent = BidirectionalAgent(model=model, tools=[calculator])
137+
agent = BidiAgent(model=model, tools=[calculator])
138138
agent.tool.calculator(expression="2+2")
139139
```
140140
"""
@@ -252,11 +252,11 @@ async def start(self) -> None:
252252
logger.debug("Conversation start - initializing connection")
253253

254254
# Create model session and event loop directly
255-
await self.model.connect(
255+
await self.model.start(
256256
system_prompt=self.system_prompt, tools=self.tool_registry.get_all_tool_specs(), messages=self.messages
257257
)
258258

259-
self._agent_loop = BidirectionalAgentLoop(model=self.model, agent=self)
259+
self._agent_loop = BidiAgentLoop(model=self.model, agent=self)
260260
await self._agent_loop.start()
261261

262262
logger.debug("Conversation ready")
@@ -306,7 +306,7 @@ async def receive(self) -> AsyncIterable[BidirectionalStreamEvent]:
306306
except asyncio.TimeoutError:
307307
continue
308308

309-
async def end(self) -> None:
309+
async def stop(self) -> None:
310310
"""End the conversation connection and cleanup all resources.
311311
312312
Terminates the streaming connection, cancels background tasks, and
@@ -316,7 +316,7 @@ async def end(self) -> None:
316316
await self._agent_loop.stop()
317317
self._agent_loop = None
318318

319-
async def __aenter__(self) -> "BidirectionalAgent":
319+
async def __aenter__(self) -> "BidiAgent":
320320
"""Async context manager entry point.
321321
322322
Automatically starts the bidirectional connection when entering the context.
@@ -350,7 +350,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
350350
for adapter in self._current_adapters:
351351
if hasattr(adapter, "cleanup"):
352352
try:
353-
adapter.end()
353+
adapter.stop()
354354
logger.debug(f"Cleaned up adapter: {type(adapter).__name__}")
355355
except Exception as adapter_error:
356356
logger.warning(f"Error cleaning up adapter: {adapter_error}")
@@ -359,7 +359,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
359359
self._current_adapters = []
360360

361361
# Cleanup agent connection
362-
await self.end()
362+
await self.stop()
363363

364364
except Exception as cleanup_error:
365365
if exc_type is None:
@@ -393,7 +393,7 @@ async def run(self, io_channels: list[BidiIO | tuple[Callable, Callable]]) -> No
393393
```python
394394
# With IO channel
395395
audio_io = AudioIO(audio_config={"input_sample_rate": 16000})
396-
agent = BidirectionalAgent(model=model, tools=[calculator])
396+
agent = BidiAgent(model=model, tools=[calculator])
397397
await agent.run(io_channels=[audio_io])
398398
399399
# With tuple (backward compatibility)

src/strands/experimental/bidirectional_streaming/event_loop/bidirectional_event_loop.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from ....types._events import ToolResultEvent, ToolStreamEvent
2222
from ....types.content import Message
2323
from ....types.tools import ToolResult, ToolUse
24-
from ..models.bidirectional_model import BidirectionalModel
24+
from ..models.bidirectional_model import BidiModel
2525

2626
logger = logging.getLogger(__name__)
2727

@@ -37,12 +37,12 @@ class BidirectionalConnection:
3737
handling while providing a simple interface for agent interactions.
3838
"""
3939

40-
def __init__(self, model: BidirectionalModel, agent: "BidirectionalAgent") -> None:
40+
def __init__(self, model: BidiModel, agent: "BidiAgent") -> None:
4141
"""Initialize connection with model and agent reference.
4242
4343
Args:
4444
model: Bidirectional model instance.
45-
agent: BidirectionalAgent instance for tool registry access.
45+
agent: BidiAgent instance for tool registry access.
4646
"""
4747
self.model = model
4848
self.agent = agent
@@ -64,22 +64,22 @@ def __init__(self, model: BidirectionalModel, agent: "BidirectionalAgent") -> No
6464
self.tool_count = 0
6565

6666

67-
async def start_bidirectional_connection(agent: "BidirectionalAgent") -> BidirectionalConnection:
67+
async def start_bidirectional_connection(agent: "BidiAgent") -> BidirectionalConnection:
6868
"""Initialize bidirectional session with conycurrent background tasks.
6969
7070
Creates a model-specific session and starts background tasks for processing
7171
model events, executing tools, and managing the session lifecycle.
7272
7373
Args:
74-
agent: BidirectionalAgent instance.
74+
agent: BidiAgent instance.
7575
7676
Returns:
7777
BidirectionalConnection: Active session with background tasks running.
7878
"""
7979
logger.debug("Starting bidirectional session - initializing model connection")
8080

8181
# Connect to model
82-
await agent.model.connect(
82+
await agent.model.start(
8383
system_prompt=agent.system_prompt, tools=agent.tool_registry.get_all_tool_specs(), messages=agent.messages
8484
)
8585

@@ -136,7 +136,7 @@ async def stop_bidirectional_connection(session: BidirectionalConnection) -> Non
136136
await asyncio.gather(*all_tasks, return_exceptions=True)
137137

138138
# Close model connection
139-
await session.model.close()
139+
await session.model.stop()
140140
logger.debug("Connection closed")
141141

142142

src/strands/experimental/bidirectional_streaming/io/audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async def receive(self, event: dict) -> None:
176176
elif role.upper() == "USER":
177177
print(f"User: {text}")
178178

179-
def end(self) -> None:
179+
def stop(self) -> None:
180180
"""Clean up IO channel resources."""
181181
try:
182182
if self.input_stream:
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""Bidirectional model interfaces and implementations."""
22

3-
from .bidirectional_model import BidirectionalModel
4-
from .gemini_live import GeminiLiveModel
5-
from .novasonic import NovaSonicModel
6-
from .openai import OpenAIRealtimeModel
3+
from .bidirectional_model import BidiModel
4+
from .gemini_live import BidiGeminiLiveModel
5+
from .novasonic import BidiNovaSonicModel
6+
from .openai import BidiOpenAIRealtimeModel
77

88
__all__ = [
9-
"BidirectionalModel",
10-
"GeminiLiveModel",
11-
"NovaSonicModel",
12-
"OpenAIRealtimeModel",
9+
"BidiModel",
10+
"BidiGeminiLiveModel",
11+
"BidiNovaSonicModel",
12+
"BidiOpenAIRealtimeModel",
1313
]

src/strands/experimental/bidirectional_streaming/models/bidirectional_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
logger = logging.getLogger(__name__)
2828

2929

30-
class BidirectionalModel(Protocol):
30+
class BidiModel(Protocol):
3131
"""Protocol for bidirectional streaming models.
3232
3333
This interface defines the contract for models that support persistent streaming
3434
connections with real-time audio and text communication. Implementations handle
3535
provider-specific protocols while exposing a standardized event-based API.
3636
"""
3737

38-
async def connect(
38+
async def start(
3939
self,
4040
system_prompt: str | None = None,
4141
tools: list[ToolSpec] | None = None,
@@ -56,12 +56,12 @@ async def connect(
5656
"""
5757
...
5858

59-
async def close(self) -> None:
59+
async def stop(self) -> None:
6060
"""Close the streaming connection and release resources.
6161
6262
Terminates the active bidirectional connection and cleans up any associated
6363
resources such as network connections, buffers, or background tasks. After
64-
calling close(), the model instance cannot be used until connect() is called again.
64+
calling close(), the model instance cannot be used until start() is called again.
6565
"""
6666
...
6767

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Gemini Live API bidirectional model provider using official Google GenAI SDK.
22
3-
Implements the BidirectionalModel interface for Google's Gemini Live API using the
3+
Implements the BidiModel interface for Google's Gemini Live API using the
44
official Google GenAI SDK for simplified and robust WebSocket communication.
55
66
Key improvements over custom WebSocket implementation:
@@ -34,7 +34,7 @@
3434
TextOutputEvent,
3535
TranscriptEvent,
3636
)
37-
from .bidirectional_model import BidirectionalModel
37+
from .bidirectional_model import BidiModel
3838

3939
logger = logging.getLogger(__name__)
4040

@@ -44,7 +44,7 @@
4444
GEMINI_CHANNELS = 1
4545

4646

47-
class GeminiLiveModel(BidirectionalModel):
47+
class BidiGeminiLiveModel(BidiModel):
4848
"""Gemini Live API implementation using official Google GenAI SDK.
4949
5050
Combines model configuration and connection state in a single class.
@@ -82,13 +82,13 @@ def __init__(
8282

8383
self.client = genai.Client(**client_kwargs)
8484

85-
# Connection state (initialized in connect())
85+
# Connection state (initialized in start())
8686
self.live_session = None
8787
self.live_session_context_manager = None
8888
self.session_id = None
8989
self._active = False
9090

91-
async def connect(
91+
async def start(
9292
self,
9393
system_prompt: Optional[str] = None,
9494
tools: Optional[List[ToolSpec]] = None,
@@ -404,7 +404,7 @@ async def _send_tool_result(self, tool_result: ToolResult) -> None:
404404
except Exception as e:
405405
logger.error("Error sending tool result: %s", e)
406406

407-
async def close(self) -> None:
407+
async def stop(self) -> None:
408408
"""Close Gemini Live API connection."""
409409
if not self._active:
410410
return
@@ -435,7 +435,7 @@ def _build_live_config(
435435
if self.live_config:
436436
config_dict.update(self.live_config)
437437

438-
# Override with any kwargs from connect()
438+
# Override with any kwargs from start()
439439
config_dict.update(kwargs)
440440

441441
# Add system instruction if provided

0 commit comments

Comments
 (0)