Skip to content

Test framework issues when updating agent from tool #6658

Description

@Kedaqusa1604

Bug Description

Hi, I'm trying to test a multi-agent application but I'm facing issues when trying to test it following this guide:

https://docs.livekit.io/agents/start/testing/test-framework/#overview

The app starts at "Agent 1" which uses a tool that updates the session agent inside it in the following way:

#Agent 1

@function_tool
async def tool(ctx: RunContext):
     await ctx.update("")
     forward_agent = Agent2()
     async with ctx.foreground():
        session = ctx.session
        session.update_agent(forward_agent)
     
     return None

class Agent2(Agent):
   async def on_enter(self):
      await self.session.generate_reply("Tell a joke")

and the test script is something like this:

#test_script.py 

result.expect.next_event().is_function_call(
    name = "tool",
    arguments = ...
)

result.expect.next_event().is_function_call_output(
    output = ""
)

await result.expect.next_event().is_message(role = "assistant").judge(
    llm,
    intent = ...
)

But when I run the test script, I'm getting the following error:

Image

Debugging the test, I noticed that the tool invocation only emits these two events:

FunctionCallEvent
FunctionCallOutputEvent

The MessageEvent generated by Agent2 never reaches the test framework, even though the application behaves correctly outside the testing environment.

In production, after session.update_agent(forward_agent) is called, Agent2.on_enter() is executed, generate_reply() is called, and the assistant responds as expected.

My questions are:

  • Is there a supported way to continue listening for events emitted by the new agent after update_agent()?0
  • Or is there a different recommended way to test multi-agent handoffs where the second agent immediately generates a reply?

Any guidance would be greatly appreciated.

Expected Behavior

Reproduction Steps

1. 
2.
3.
...
- Sample code snippet, or a GitHub Gist link -

Operating System

Linux

Models Used

Gemini-3.5-flash-lire

Package Versions

livekit==1.1.13
livekit-agents==1.6.5
livekit-api<2

Session/Room/Call IDs

No response

Proposed Solution

Additional Context

No response

Screenshots and Recordings

No response

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