Workflow
VoiceWorkflowBase
Bases:ABC
A base class for a voice workflow. You must implement therun method. A "workflow" is anycode you want, that receives a transcription and yields text that will be turned into speechby a text-to-speech model.In most cases, you'll createAgents and useRunner.run_streamed() to run them, returningsome or all of the text events from the stream. You can use theVoiceWorkflowHelper class tohelp with extracting text events from the stream.If you have a simple workflow that has a single starting agent and no custom logic, you canuseSingleAgentVoiceWorkflow directly.
Source code insrc/agents/voice/workflow.py
runabstractmethod
Run the voice workflow. You will receive an input transcription, and must yield text thatwill be spoken to the user. You can run whatever logic you want here. In most cases, thefinal logic will involve callingRunner.run_streamed() and yielding any text events fromthe stream.
Source code insrc/agents/voice/workflow.py
on_startasync
Optional method that runs before any user input is received. Can be usedto deliver a greeting or instruction via TTS. Defaults to doing nothing.
VoiceWorkflowHelper
Source code insrc/agents/voice/workflow.py
stream_text_fromasyncclassmethod
stream_text_from(result:RunResultStreaming,)->AsyncIterator[str]Wraps aRunResultStreaming object and yields text events from the stream.
Source code insrc/agents/voice/workflow.py
SingleAgentWorkflowCallbacks
Source code insrc/agents/voice/workflow.py
on_run
on_run(workflow:SingleAgentVoiceWorkflow,transcription:str)->NoneSingleAgentVoiceWorkflow
Bases:VoiceWorkflowBase
A simple voice workflow that runs a single agent. Each transcription and result is added tothe input history.For more complex workflows (e.g. multiple Runner calls, custom message history, custom logic,custom configs), subclassVoiceWorkflowBase and implement your own logic.
Source code insrc/agents/voice/workflow.py
__init__
__init__(agent:Agent[Any],callbacks:SingleAgentWorkflowCallbacks|None=None,)Create a new single agent voice workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent | Agent[Any] | The agent to run. | required |
callbacks | SingleAgentWorkflowCallbacks | None | Optional callbacks to call during the workflow. | None |
Source code insrc/agents/voice/workflow.py
on_startasync
Optional method that runs before any user input is received. Can be usedto deliver a greeting or instruction via TTS. Defaults to doing nothing.