Skip to content

Room closes after another participant joins if the agent leaves with ctx.shutdown(reason="Session ended") after a short time #3597

@Andhs-eff

Description

@Andhs-eff

In our scenario, we connect another human participant to the room via an outbound call and disconnect the agent (as per this). If the agent disconnects immediately or after a short time (even 60 seconds), the call ends just as the agent disconnects.

Example code:

async def entrypoint(ctx: agents.JobContext):
    await ctx.connect()

    session = AgentSession(
        stt=deepgram.STT(),
        llm=openai.LLM(model="gpt-4o-mini"),
        tts=openai.TTS(),
        vad=silero.VAD.load(),
    )

    await session.start(
        room=ctx.room,
        agent=Agent(instructions="You are a helpful voice AI assistant. Your replies are relevant but brief."),
    )

    # Instruct the agent to speak first
    await session.generate_reply()

    # Add another human to replace the agent
    request = CreateSIPParticipantRequest(
        sip_trunk_id = "XXXXXXX",
        sip_call_to = "+XXXXXXX",
        room_name = ctx.room.name,
        participant_identity = "another-human",
        participant_name = "Another Human",
        play_dialtone = True,
        krisp_enabled = True,
        dtmf = "XXXXXXX", 
        wait_until_answered = True
    )

    await ctx.api.sip.create_sip_participant(request)

    await session.say("Thank you for using our service.", allow_interruptions=False, add_to_chat_ctx=False)

    await asyncio.sleep(20)

    ctx.shutdown(reason="Session ended")

In the agent's web console, we see the message could not createOffer with closed peer connection.

Strangely, if we set a sufficiently long time (await asyncio.sleep(120)), the call continues normally with human participants and without the agent.

How can it be that call retention depends on the time it takes for the agent to disconnect? Normally the call should be retained even if the agent disconnects immediately.

P.S. If there is only one participant in the room (the second participant is not added) and the agent disconnects, the room is retained.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions