You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to use RunContextWrapper with VoiceWorkflow #819
Have you read the docs?Agents SDK docs
Yes, I have read the docs and also gone through the examples in repo.
Have you searched for related issues? Others may have had similar requests
Yes, I have but couldn't find anything informational.
Question
Describe your question. Provide details if available.
I am building an agentic system for a store, I have already created the tools, context and all the agents that are required for the use case.
For text based agentic conversation, sending the context is straightforward, that is to pass the context as an argument in Runner.run function. It’s working correctly as well:
The place where I’m stuck at is, how to send the context when doing voice-based conversions. I can’t send the context object to voicepipeline.run method, I have thoroughly read the documentation and issue sections in github repository, but I cant find a possible way to use this.
result = await voice_pipeline.run(audio_input=audio_input) // no parameter to send context
Let me know if you require any other additional details.
Yes, I was able to fulfil the limitation. After digging into the implementation of SingleAgentVoiceWorkflow, I found that the key is to build a custom voice workflow that integrates your own logic, especially to support context.
Below is my enhanced implementation, which incorporates context into the workflow:
class SingleAgentVoiceWorkflowWithContext(VoiceWorkflowBase):
"""A simple voice workflow that runs a single agent. Each transcription and result is added to
the input history with context support.
"""
def __init__(self, agent: Agent[Any], context: RunContextWrapper[Any], callbacks: SingleAgentWorkflowCallbacks | None = None):
"""Create a new single agent voice workflow with context support.
Args:
agent: The agent to run.
context: The context to use for the agent.
callbacks: Optional callbacks to call during the workflow.
"""
self._input_history: list[TResponseInputItem] = []
self._current_agent = agent
self._callbacks = callbacks
self._context = context
async def run(self, transcription: str) -> AsyncIterator[str]:
if self._callbacks:
self._callbacks.on_run(self, transcription)
# Add the transcription to the input history
self._input_history.append(
{
"role": "user",
"content": transcription,
}
)
# Run the agent
result = Runner.run_streamed(self._current_agent, self._input_history, self._context)
# Stream the text from the result
async for chunk in VoiceWorkflowHelper.stream_text_from(result):
yield chunk
# Update the input history and current agent
self._input_history = result.to_input_list()
self._current_agent = result.last_agent
Now, you can use the workflow in your implementation like so:
Activity
github-actions commentedon Jun 15, 2025
This issue is stale because it has been open for 7 days with no activity.
serranoarevalo commentedon Jun 18, 2025
@T-Zaid Did you end up fixing this? How did you do it?
T-Zaid commentedon Jun 19, 2025
Yes, I was able to fulfil the limitation. After digging into the implementation of
SingleAgentVoiceWorkflow, I found that the key is to build a custom voice workflow that integrates your own logic, especially to support context.Below is my enhanced implementation, which incorporates context into the workflow:
Now, you can use the workflow in your implementation like so: