Skip to content

Commit e94d576

Browse files
committed
Add on_start support to VoiceWorkflowBase and VoicePipeline
1 parent 91c62c1 commit e94d576

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/agents/voice/pipeline.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ async def _run_multi_turn(self, audio_input: StreamedAudioInput) -> StreamedAudi
125125
self._get_tts_model(), self.config.tts_settings, self.config
126126
)
127127

128+
if hasattr(self.workflow, "on_start"):
129+
try:
130+
async for intro_text in self.workflow.on_start():
131+
await output._add_text(intro_text)
132+
except Exception as e:
133+
logger.warning(f"on_start() failed: {e}")
134+
128135
transcription_session = await self._get_stt_model().create_session(
129136
audio_input,
130137
self.config.stt_settings,

src/agents/voice/workflow.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ def run(self, transcription: str) -> AsyncIterator[str]:
3232
"""
3333
pass
3434

35+
async def on_start(self) -> AsyncIterator[str]:
36+
"""
37+
Optional method that runs before any user input is received. Can be used
38+
to deliver a greeting or instruction via TTS. Defaults to doing nothing.
39+
"""
40+
return
41+
yield
42+
3543

3644
class VoiceWorkflowHelper:
3745
@classmethod

0 commit comments

Comments
 (0)