Skip to main content
Version: 0.0.x

Multi Agent Switching

Multi agent switching allows you to break a complex workflow into multiple specialized agents, each responsible for a specific domain or task. Instead of relying on a single agent to manage every tool and decision, you can coordinate smaller agents that operate independently.

Context Inheritance​

When switching agents, you can control whether the new agent should be aware of the previous conversation using the inherit_context flag.

  • inherit_context=True: The new agent receives the full chat context. This is ideal for maintaining continuity, so the user doesn't have to repeat information.
  • inherit_context=False (Default): The new agent starts with a fresh state. This is useful when switching to a completely unrelated task.

How It Works​

  • The primary VideoSDK agent identifies whether specialized assistance is needed based on the users intent.
  • It invokes a function tool to switch to the appropriate specialized agent.
  • Control automatically shifts to the new agent and has access to the previous chat context as inherit_context=True was passed.
  • The specialized agent handles the user’s request, and complete the interaction.

Implementation​

main.py
from videosdk.agents import Agent, function_tool, 

class TravelAgent(Agent):
def __init__(self):
super().__init__(
instructions="""You are a travel assistant. Help users with general travel inquiries and guide them to booking when needed.""",
)

async def on_enter(self) -> None:
await self.session.reply(instructions="Greet the user and ask how you can help with their travel plans.")

async def on_exit(self) -> None:
await self.session.say("Safe travels!")

@function_tool()
async def transfer_to_booking(self) -> Agent:
"""Transfer the user to a booking specialist for reservations and scheduling."""
return BookingAgent(inherit_context=True)

class BookingAgent(Agent):
def __init__(self, inherit_context: bool = False):
super().__init__(
instructions="""You are a booking specialist. Help users book or modify flights, hotels, and travel reservations.""",
inherit_context=inherit_context
)

async def on_enter(self) -> None:
await self.session.say("I'm a booking specialist. What would you like to book or modify today?")

async def on_exit(self) -> None:
await self.session.say("Your booking request is complete. Have a great trip!")

Example - Try It Yourself​

Got a Question? Ask us on discord