# User\_state stuck in speaking during the agent handoff

**URL:** <https://community.livekit.io/t/user-state-stuck-in-speaking-during-the-agent-handoff/685>\
**Category:** Agents\
**Tags:** agent-development, agent-sdk-python, turn-detection\
**Created:** [March 26, 2026, 6:51am UTC](https://community.livekit.io/t/user-state-stuck-in-speaking-during-the-agent-handoff/685 "2026-03-26T06:51:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuva\_Prabhu](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/yuva_prabhu/32/506_2.png) [@Yuva\_Prabhu](https://community.livekit.io/u/Yuva_Prabhu)\
**Post date:** [March 26, 2026, 6:51am UTC](https://community.livekit.io/t/user-state-stuck-in-speaking-during-the-agent-handoff/685/1 "2026-03-26T06:51:02Z")

</div>

We are using livekit workflow multi-agent framework.

We noticed that during the agent transfer, if the user is speaking the state is stuck in speaking.  
it never changes to listening after user silence or after agent handoff.

Attaching the transfer\_to\_agent fn definition,

@function\_tool  
async def transfer\_to\_agent(self, target\_agent\_id: str, run\_ctx: RunContext):  
“”"  
Transfer to another agent.  
“”"

```auto
# Disable interruptions during transfer
run_ctx.disallow_interruptions()

# Create new chat context (optional)
new_chat_ctx = self.chat_ctx.copy() if self.chat_ctx else None

# Create next agent
factory = self.agents_map[target_agent_id]
next_agent = await factory({"source_agent_id": self._agent_id})

# Apply chat context
if new_chat_ctx:
    await next_agent.update_chat_ctx(
        new_chat_ctx,
        exclude_invalid_function_calls=False
    )

# Pause current activity scheduling to avoid race conditions
if (
    self.agent_session
    and hasattr(self.agent_session, "_activity")
    and self.agent_session._activity
):
    self.agent_session._activity._scheduling_paused = True

return next_agent, None

```

livekit-agents = {version = "1.3.9” }

---

<div class="post-metadata">

**Author:** ![darryncampbell](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/darryncampbell/32/20_2.png) [@darryncampbell](https://community.livekit.io/u/darryncampbell)\
**Post date:** [March 26, 2026, 10:41am UTC](https://community.livekit.io/t/user-state-stuck-in-speaking-during-the-agent-handoff/685/2 "2026-03-26T10:41:57Z")

</div>

During a handoff, agent and user states are driven by VAD and the active `AgentSession`. If you call `run_ctx.disallow_interruptions()` and manually pause `_activity._scheduling_paused`, you can prevent the session from completing the current turn cycle, which blocks transitions like `speaking → listening`.

Instead of pausing internal `_activity` (and I would discourage accessing any internal objects, denoted by the `_`), let the framework manage the lifecycle and use the built‑in handoff flow.

> _# Pause current activity scheduling to avoid race conditions_

Clearly this code is working around some other issue, I think fixing the race condition that prompted you to add this line is probably the best way forward.

---

<div class="post-metadata">

**Author:** ![Yuva\_Prabhu](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/yuva_prabhu/32/506_2.png) [@Yuva\_Prabhu](https://community.livekit.io/u/Yuva_Prabhu)\
**Post date:** [March 27, 2026, 11:38am UTC](https://community.livekit.io/t/user-state-stuck-in-speaking-during-the-agent-handoff/685/3 "2026-03-27T11:38:16Z")

</div>

`self.agent_session._activity._scheduling_paused = True` this was added to solve the below problem -LLM emitted { message , tool } in same turn, the tool was transfer\_to\_agent tool.  
Thought the function\_tool is shown success in langfuse, the user interrupted while the “message“ was being spoken.

The current agent activity drained but the new agent activity didn’t come up.  
So by adding this line, it solved that problem.

---

<div class="post-metadata">

**Author:** ![Yuva\_Prabhu](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/yuva_prabhu/32/506_2.png) [@Yuva\_Prabhu](https://community.livekit.io/u/Yuva_Prabhu)\
**Post date:** [May 26, 2026, 11:27am UTC](https://community.livekit.io/t/user-state-stuck-in-speaking-during-the-agent-handoff/685/4 "2026-05-26T11:27:27Z")

</div>

any update @darryncampbell

---

<div class="post-metadata">

**Author:** ![darryncampbell](https://sea1.discourse-cdn.com/flex001/user_avatar/community.livekit.io/darryncampbell/32/20_2.png) [@darryncampbell](https://community.livekit.io/u/darryncampbell)\
**Post date:** [May 26, 2026, 3:30pm UTC](https://community.livekit.io/t/user-state-stuck-in-speaking-during-the-agent-handoff/685/5 "2026-05-26T15:30:45Z")

</div>

My recommendation hasn’t changed from my original answer. I did also check the `Ask AI` feature (blue button, above), which is newly added since you asked the original question, but it provides a similar answer.
