glamorous-kitchen-68628
08/16/2025, 12:49 PMUser(say): message to trigger handoff
Agent A(say): I think I need to handoff
Agent A(logic): handoff to Agent B, reason="not my domain"
Agent B(say): hi, User, I will help you
What I want is skip the response "Agent A(say): I think I need to handoff"tall-airline-16756
08/16/2025, 12:50 PMtall-airline-16756
08/16/2025, 12:50 PMskip_next_event_if()
to skip that last message from Agent A by checking for a message
event with the right role:
result.expect.skip_next_event_if(type="message", role="assistant") # Skips the last assistant message
• If you want to skip a few messages or other events, you can chain skip_next_event_if()
calls or simply use `skip_next()`:
result.expect.skip_next(2) # Skips the next two events
Feel free to reach out if you want me to walk you through this or if you have any other questions — I’m here to help!
"""glamorous-kitchen-68628
08/16/2025, 12:55 PMagent_a = AgentA()
agent_b = AgentB()
userdata.personas = {
"Agent A": agent_a,
"Agent B": agent_b
}
# Later when calling handoff
class AgentA(Agent):
async def _handoff:
return userdata.personas["Agent B"], "your call"
In this case, will the "agent_b" instance will have all chat history of "agent_a"?tall-airline-16756
08/16/2025, 12:56 PMfrom livekit.agents import ChatContext, function_tool, Agent
class AgentA(Agent):
@function_tool()
async def transfer_to_agent_b(self):
return AgentB(chat_ctx=self.session.chat_ctx)
class AgentB(Agent):
def __init__(self, chat_ctx: ChatContext):
super().__init__(chat_ctx=chat_ctx)
If you want me to walk you through this or help with anything else, just let me know! Sources: Workflows | LiveKit Docs | Workflows | LiveKit Docsglamorous-kitchen-68628
08/16/2025, 1:00 PMchat_ctx
during the on_enter
?
async def on_enter(self) -> None:
self.chat_ctx # I can access the chat_ctx here
tall-airline-16756
08/16/2025, 1:00 PMimport logging
from livekit.agents.llm import ChatContext
logger = logging.getLogger(__name__)
async def on_enter(self) -> None:
chat_ctx = self.chat_ctx.copy()
<http://logger.info|logger.info>(f"Chat context on enter: {chat_ctx.to_dict()}")
# Continue with your existing logic
await self.update_chat_ctx(chat_ctx)
### Steps: 1. Import Necessary Components: - Bring in logging so you can use the logger. - Import ChatContext from LiveKit’s LLM module. 2. Create Logger Instance: - Set up a logger instance with a name, usually name for the current module. 3. Access and Log Chat Context: - Grab the current chat context with self.chat_ctx. - Log it using logger.info(). Converting it to a dictionary with to_dict() makes it super readable. 4. Optional: If you want to log just certain parts of the chat context, you can tweak the logging like this:
<http://logger.info|logger.info>(f"Messages in chat context: {[msg.content for msg in chat_ctx.items if msg.type == 'message']}")
Feel free to reach out if you want me to walk you through any part of this or if you have any other questions!