Hi all, I'm trying to implement a multi-agent con...
# agents
e
Hi all, I'm trying to implement a multi-agent conversational experience where the user can speak, but several agents may respond one after the other. The core agent logic is implemented in LangGraph. I created a custom adapter and I'm using it for the LLM node for a single LiveKit agent. I'm simulating this multi-AI experience by just using this single agent and I send custom events from LangGraph to LiveKit and then to the front end that allow me distinguish between speakers. However, one issue I have is that it seems there is no way to switch the TTS node dynamically when I switch between agents. So what I'm thinking is potentially having separate Agent objects to represent each agent in my LangGraph graph, each with their own TTS node with different voices. Their responses would come from the same LangGraph endpoint, but I'm thinking I can have custom LLM adapters for each agent that just subscribes to the graph, and just filter for the tokens for their corresponding agent. If I'm able to do this though, I would need to be able to queue up messages for each of the agents and hand off from one agent to another whenever each is done speaking. Is this possible in LiveKit? I don't see any signal or callback that I can use when an agent is done speaking to automatically hand off to another agent. TL;DR: Is there a way to automatically hand off from one agent to another once the first agent is done speaking?
It looks like the only way to hand off between agents is via tool calls. Since I implemented a custom LLM adapter for my LangGraph implementation, I think what I'll do is add "support" for tool calls as a way to pass in the ability to hand off between agents. That way, when I detect the change is speaker from LangGraph, I'll manually return the handoff tool call from the code. Would appreciate insight from anybody who has more experience using LangGraph for similar multi agent systems.
Somehow had not seen the
session.update_agent
function that can be used to switch between agents (good thing I implemented in Python because the docs say it's not available in Node.js). I ended up moving away from my previous implementation that only used one LiveKit Agent object. I instead instantiate an Agent object for each agent I have in LangGraph, each with their own TTS with different voices and I gave them each a custom LLM node adapter that gets tokens streamed from the same LangGraph graph. The way I implemented this is by having a LangGraph buffer class that handles the stream from the graph, adding chunks to a buffer and keeping track of when the speaker changes. Then I have simple wrapper LLM adapters that each pull from the LangGraph buffer class, treating it as if it were a plain LLM provider.
t
Do you have an example of implementing langraph with Livekit?