Description
The Context
I've been trying to implement the agent swarm architecture mentioned here as my desire is that once handed off to, the new Agent carries on the conversation and then when a new topic comes up, that Agent can handoff to a more specific Agent for the topic (in any order)
The Setup
Right now I'm just messing around trying to implement a very simple chatbot that consists of multiple agents relevant for booking some dummy trip:
- FlightAgent
- HotelAgent
and a TriageAgent as the initial point of contact.
When someone gives an initial prompt, the TriageAgent completes a handoff to the Agent that is best positioned to help the customer (depending on if the question has to do with weather or flights).
The Scenario
- Say someone asks about booking a flight
- TriageAgent hands-off to the FlightAgent
- Conversation continues until the flight details are ironed out with the FlightAgent
- Now, the customer asks about a hotel...
The desire now is to be able to handoff to the HotelAgent to have a conversation about the hotel booking
(or vice versa if the conversation started on the HotelAgent and the customer then asks about a flight).
The Current Issue
Using handoffs in the current implementation results in (very understandably) circular dependency issues since the handoff
property requires instantiated Agent objects. (i.e. FlightAgent must have handoffs: [HotelAgent]
and HotelAgent must have handoffs: [FlightAgent]
)
The goal
This whole thing can definitely be done if the TriageAgent is ALWAYS the first point of contact, but I suppose it seems like I could have more token/time savings if I already know the current conversation is with (await run(triageAgent, messages)).lastAgent
and I just start the next message with that agent
Potential Solutions?
If my scenario above isn't best practice please let me know, I'm just tinkering around trying things out.
It seems langgraph gets around this by executing handoffs based on the agent name? suggesting maybe a more central store of agents. So maybe adding just an array of strings in the handoff
array and in the run function having a mapping of agent names to agents to facilitate handoff.