Skip to content

Add on_start support to VoiceWorkflowBase and VoicePipeline #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/agents/voice/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ async def _run_multi_turn(self, audio_input: StreamedAudioInput) -> StreamedAudi
self._get_tts_model(), self.config.tts_settings, self.config
)

try:
async for intro_text in self.workflow.on_start():
await output._add_text(intro_text)
except Exception as e:
logger.warning(f"on_start() failed: {e}")

transcription_session = await self._get_stt_model().create_session(
audio_input,
self.config.stt_settings,
Expand Down
8 changes: 8 additions & 0 deletions src/agents/voice/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ def run(self, transcription: str) -> AsyncIterator[str]:
"""
pass

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


class VoiceWorkflowHelper:
@classmethod
Expand Down