fix(voice): support context in single-agent workflow - #4636
Conversation
There was a problem hiding this comment.
Thanks for the contribution. The placement and lifetime look right: SingleAgentVoiceWorkflow owns the Runner invocation and conversation history, so storing one application context on the workflow and forwarding it to every turn is the narrowest coherent design.
Before merging, please update the constructor typing so the agent and context share TContext: use agent: Agent[TContext] and context: TContext | None, following Runner.run_streamed(), instead of erasing both to Any. This lets type checkers catch mismatched agent/context pairs and preserves the SDK's existing context contract. The implementation can continue forwarding the raw application object; no voice-specific wrapper or broader VoicePipeline API is needed. The existing two-turn tool test is sufficient for runtime forwarding.
|
Updated the constructor typing as requested so the agent and context share TContext, while leaving the runtime forwarding behaviour unchanged. |
Summary
This pull request adds first-class Runner context support to
SingleAgentVoiceWorkflow.SingleAgentVoiceWorkflownow accepts an optional keyword-onlycontextargument and forwards the same application context to each internalRunner.run_streamed()call. This lets the convenience voice workflow use context-dependent instructions, tools, handoffs, and enablement predicates without requiring users to copy the workflow into a customVoiceWorkflowBaseimplementation.The existing positional constructor contract is preserved:
agentremains first andcallbacksremains second. Custom workflows remain the supported path for broader per-turn Runner customization.Following review, the constructor now preserves the SDK's existing context type relationship by using
agent: Agent[TContext]andcontext: TContext | Nonerather than erasing both toAny.Test plan
uv run pytest -q tests/voice/test_workflow.py— passed on the pre-review implementationsrc/agents/voice/workflow.py— passed on the pre-review implementationaction_requiredand has not started jobs yet; it requires maintainer approval before the updated checks can run.The regression test executes a real context-aware function tool on two separate voice turns and verifies that the same context reaches both invocations.
Issue number
Closes #4635
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR