Hey guys Is there any way to silently transfer to ...
# ask-ai
b
Hey guys Is there any way to silently transfer to another agent in on_enter from an agent. No function tool calling. nothing.
t
Thanks for reaching out, G. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
If you want to quietly transfer to another agent in
on_enter
without using function tools, you can handle it right inside the
on_enter
method of your current agent. Here’s a simple way to do it: 1. Define the Target Agent: Set up the agent you want to transfer to, making sure it’s ready with any needed parameters like instructions or plugins. 2. Perform Transfer in `on_enter`: Inside the
on_enter
method of your current agent, just call
self.session.update_agent()
with the new agent instance. 3. Suppress Initial Reply: To keep things quiet, override the target agent’s
on_enter
method so it doesn’t send an initial reply by skipping
generate_reply()
. Here’s a quick example to make it clearer:
Copy code
class CurrentAgent(Agent):
    async def on_enter(self) -> None:
        # Initialize the target agent
        next_agent = NextAgent()
        # Transfer control to the next agent silently
        self.session.update_agent(next_agent)

class NextAgent(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are the next agent in the workflow.",
            tools=[]  # Optional: Disable tool processing for a silent transfer
        )
    
    async def on_enter(self) -> None:
        # Override to prevent generating an initial reply
        pass
And that’s it! This way, the transfer happens smoothly and quietly, so the user won’t even notice it.