Skip to content

Error processing output: BaseEventLoop.create_connection() got an unexpected keyword argument ‘additional_headers’ #303

@jianming

Description

@jianming

We are integrating Agent SDK + Voice Pipeline into Twilio websocket, here is our basic logic, but we are getting this weird error:
openai.agents stream: Error processing output: BaseEventLoop.create_connection() got an unexpected keyword argument ‘additional_headers’

It seems throws after this line of code:
result = await self.voice_pipeline.run(self.streamed_audio_input)

We are using the latest openai-agents, openai lib
the websockets = 15.0.1
We are using django channels=4.2.0
python=3.10.12

Below are our code to create the agent, pipeline, voicestreaminput. what might be the cause?

 async def _initialize_voice_agent(self):
        """
        Initialize the voice agent components with the correct flow.
        """
        try:
            # Create the agent to handle LLM processing
            # Add system instructions
            system_message = """
            You are a helpful voice assistant that answers phone calls.
            Your job is to be helpful, friendly, and concise in your responses.
            If you don't know something, be honest about it.
            Keep your responses brief since this is a phone conversation.
            """
            self.agent = Agent(
                name="twilio_agent",
                model="gpt-4o-mini",
                instructions=system_message
            )
            # Create a voice workflow with default stt and tts models
            voice_workflow = SingleAgentVoiceWorkflow(
                agent=self.agent,
            )

            # Create the voice pipeline with the workflow
            self.voice_pipeline = VoicePipeline(workflow=voice_workflow)

            # Create the streamed audio input
            self.streamed_audio_input = StreamedAudioInput()

            logger.info("Voice agent components initialized successfully")
        except Exception as e:
            logger.error(f"Error initializing voice agent: {e}")


    async def receive(self, text_data=None, bytes_data=None):
        """Handle incoming messages from Twilio."""
        if text_data:
            # Process JSON control messages
                data = json.loads(text_data)
                event = data.get("event")
    
                if event == "start":
                    # Start the voice processing task
                    self.processing_task = asyncio.create_task(self._process_voice_conversation())
               elif event == "media":
                  # Handle media data
                    media = data.get("media", {})
                    if media.get("track") == "inbound":
                        payload = media.get("payload")
                        if payload and self.streamed_audio_input:
                             await self.streamed_audio_input.add_audio(payload)


    async def _process_voice_conversation(self):
        """
        Process the voice conversation using the correct flow:
        Twilio audio → STT → Agent/LLM → TTS → Twilio audio
        """
        logger.info(">>>>>Starting voice processing task")
        try:
            # Run the voice pipeline with the streamed audio input [This line seems throwing that error]
            result = await self.voice_pipeline.run(self.streamed_audio_input)

            logger.info(">>>> pipeline is running....")
            # Process streaming events from the pipeline
            async for event in result.stream():
                      #handle the event
    ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions