| 78 | self._callbacks = callbacks |
| 79 | |
| 80 | async def run(self, transcription: str) -> AsyncIterator[str]: |
| 81 | if self._callbacks: |
| 82 | self._callbacks.on_run(self, transcription) |
| 83 | |
| 84 | # Add the transcription to the input history |
| 85 | self._input_history.append( |
| 86 | { |
| 87 | "role": "user", |
| 88 | "content": transcription, |
| 89 | } |
| 90 | ) |
| 91 | |
| 92 | # Run the agent |
| 93 | result = Runner.run_streamed(self._current_agent, self._input_history) |
| 94 | |
| 95 | # Stream the text from the result |
| 96 | async for chunk in VoiceWorkflowHelper.stream_text_from(result): |
| 97 | yield chunk |
| 98 | |
| 99 | # Update the input history and current agent |
| 100 | self._input_history = result.to_input_list() |
| 101 | self._current_agent = result.last_agent |