Workflow
VoiceWorkflowBase
Bases: ABC
A base class for a voice workflow. You must implement the run method. A "workflow" is any
code you want, that receives a transcription and yields text that will be turned into speech
by a text-to-speech model.
In most cases, you'll create Agents and use Runner.run_streamed() to run them, returning
some or all of the text events from the stream. You can use the VoiceWorkflowHelper class to
help with extracting text events from the stream.
If you have a simple workflow that has a single starting agent and no custom logic, you can
use SingleAgentVoiceWorkflow directly.
ソースコード位置: src/agents/voice/workflow.py
run
abstractmethod
Run the voice workflow. You will receive an input transcription, and must yield text that
will be spoken to the user. You can run whatever logic you want here. In most cases, the
final logic will involve calling Runner.run_streamed() and yielding any text events from
the stream.
ソースコード位置: src/agents/voice/workflow.py
on_start
async
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.
VoiceWorkflowHelper
ソースコード位置: src/agents/voice/workflow.py
stream_text_from
async
classmethod
stream_text_from(
result: RunResultStreaming,
) -> AsyncIterator[str]
Wraps a RunResultStreaming object and yields text events from the stream.
ソースコード位置: src/agents/voice/workflow.py
SingleAgentWorkflowCallbacks
ソースコード位置: src/agents/voice/workflow.py
on_run
on_run(
workflow: SingleAgentVoiceWorkflow, transcription: str
) -> None
SingleAgentVoiceWorkflow
Bases: VoiceWorkflowBase
A simple voice workflow that runs a single agent. Each transcription and result is added to
the input history.
For more complex workflows (e.g. multiple Runner calls, custom message history, custom logic,
custom configs), subclass VoiceWorkflowBase and implement your own logic.
ソースコード位置: src/agents/voice/workflow.py
__init__
__init__(
agent: Agent[Any],
callbacks: SingleAgentWorkflowCallbacks | None = None,
)
Create a new single agent voice workflow.
引数:
| 名前 | タイプ | デスクリプション | デフォルト |
|---|---|---|---|
agent
|
Agent[Any]
|
The agent to run. |
必須 |
callbacks
|
SingleAgentWorkflowCallbacks | None
|
Optional callbacks to call during the workflow. |
None
|
ソースコード位置: src/agents/voice/workflow.py
on_start
async
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.