:information_source: <https://livekit-users.slack....
# agents
p
r
What is your usecase you are trying to solve for?
p
@refined-appointment-81829 I have state in userdata that is relevant to my agent. When the agent starts (
on_enter
), I check if the state (userdata) has been updated: 1. If so, I call
generate_reply
with instructions + the state (ie. Caller Name), then I need to transition straight to the next agent. 2. If not, I call
generate_reply
with instructions (without the state), and let it proceed to the function_tool naturally (based on the agent's system prompt (instructions). _Note: When the function_tool is invoked (2), it collects some data from the user, updates the state/userdata, and transitions to the next agent._
One alternative would be to create a function_tool (ie.
transition_to_next_agent
) and try to influence the agent to invoke it when needed (with system prompt or
generate_reply
- although I'm not really sure if this is possible from
generate_reply
, is it?); but this would reduce my chances of success (ie. the agent might not call the function_tool), breaking my state machine.
r
Have you looked at the triage agent example? Doesn't it do something like that?
👀 1
p
It transitions based on input from the user. I'd like to transition based on state injected into the agent outside the conversation.
As in: 1. If state A, then transition 2. If state B, continue (ie. talk to user, call function_tools, etc)
r
ok, I wil have to try it. I am not sure off hand the constraints
🙏 1
p
Today, the only way (AFAIK) to transition to another agent, is by returning another agent as a response to a function_tool. But my branching logic lives in
on_enter
r
You are using realtime right?
p
STT, TTS, LLM (Cartesia + openai/gpt-4o)
👍đŸŧ 1
Hey @refined-appointment-81829 did you get any luck with this?
ah. I wonder if this is the answer:
session.update_agent(MyOtherAgent())
let me give it a go...
r
No, I've not had a chance to try it yet. This is on the list of things to look into.
e
@proud-lawyer-39815 Did you ever figure this out? I have a similar situation where I want to switch to the next agent immediately after the current one finishes speaking. I am getting a single stream from LangGraph which I am storing in a buffer. That single stream can contain tokens from multiple agents if they switch within LangGraph. If I detect a change in speaker, I end the stream for the current agent, and I want to switch to the other agent, which would then read their tokens from the buffer. I'm trying to figure out how to switch to the next agent once the first is done speaking. I see the
session.update_agent
function, but I'm having issues when calling it. I'm trying to call it from conversation_item_added handler
p
Hey Jorge. Yeah, update_agent from on_enter did the trick for me
🙏 1
e
Thanks, I appreciate the response!
p
@echoing-oil-67421 what issues are you facing with converstion_item_added? Can you share the logs?