Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5ba91b

Browse files
authored
Add on_start support to VoiceWorkflowBase and VoicePipeline (openai#922)
I added an optional `on_start()` method to `VoiceWorkflowBase`, allowing voice workflows to emit an initial TTS message before any user input. This aligns with the usage pattern suggested in openai#488 The `VoicePipeline._run_multi_turn()` method was updated to call this hook and stream any yielded messages via TTS before transcription begins. No changes are required to existing workflows, as the method defaults to returning an empty `AsyncIterator[str]`. Resolves openai#488 and thus improves UX for voice agents that need to greet or instruct users proactively. All tests pass under Python 3.12. Let me know if you'd like an example workflow or docs added in a follow-up!
1 parent d1d2ecc commit e5ba91b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/agents/voice/pipeline.py

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

128+
try:
129+
async for intro_text in self.workflow.on_start():
130+
await output._add_text(intro_text)
131+
except Exception as e:
132+
logger.warning(f"on_start() failed: {e}")
133+
128134
transcription_session = await self._get_stt_model().create_session(
129135
audio_input,
130136
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)