brave-author-62043
08/09/2025, 8:46 AMtall-airline-16756
08/09/2025, 8:46 AMtall-airline-16756
08/09/2025, 8:46 AMon_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:
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.