The Art of Concluding Multi-Agent Interactions with Autogen and Gemini

Published On Wed Oct 09 2024
The Art of Concluding Multi-Agent Interactions with Autogen and Gemini

Tutorial : Multi-Agent interactions with Autogen and Gemini — Part 2 Terminating Conversations

This part is a continuation of exploring the basics of getting Multi-Agent conversations going with Autogen framework. The series:

In the first part of the series, we setup a Multi-Agent Scenario that had two agents, a CFP Writer and a CFP Reviwer. Both of them collaborated with each other to improve a Call for Proposals/Paper (CFP) iteratively. The CFP Reviewer will review the proposal and offer suggestions to improve. The CFP Writer will then look at those suggestions and do its best to incorporate that. Behind the scenes in the Autogen framework, we employed Google Gemini models.

Announcing A New Manning Book — Multi-Agent Systems with AutoGen ...

The key thing to note in this interaction is in the last line of the main file (multi-agent-interaction.py. I reproduce the key snippet of code over here:

Notice the parameter max_turns, which has a value of 2. This means that the back and forth conversation will continue for a maximum of 2 turns, before it all ends. Do we need to have it for few more turns? We don’t know that. Should it continue indefinitely or to put that better, for a lot of turns? That’s not a good idea either, since the costs could add up and not provide too much of an improvement incrementally.

Terminating the Conversation

What if we could terminate the conversation based on some feedback from the CFP Reviewer? If the CFP Reviewer mentions that there is not much to improve and puts in some text in its response, for e.g. Looks good, that could be a trigger to the framework executor to stop the conversation.

Termination Date: What it is, How it Works

It turns out that the framework designers have given this some good thought and there are various ways to do that as documented over here: microsoft.github.io. In fact, by using the max_turns parameter, we were indeed one of the ways to terminating the conversation i.e. after a certain number of tries. We are now going to look at another mechanism is_termination_msg in one of the agents i.e. CFP Writer, so that if the Agent sees that message in the response received from the CFP Reviewer, then it can terminate the conversation.

Multi-agent Conversation Framework | AutoGen

Implementation

The first change that we are going to do is to add the is_termination_msg condition to the CFP Writer, so that if the Agent sees the text Looks good in the response from the CFP Reviewer, then it can exit the conversation and there shall be no more turns. The modified code for instantiating the CFP Writer is shown below:

The key thing to highlight here is the code given below, which checks for the text looks good in the response from the CFP Reviewer.

2 posts tagged with "RAG" | AutoGen

Now, that we have modified the CFP Writer, we also need to mention in the System Message for the CFP Reviewer, that if there are no significant improvements, then it should mention looks good. So that’s the next change in the code, where we tweak the System Message, as shown below:

The final change is to drop the max_turns parameter that we had set to “2” in the previous iteration. In other words, we are letting the conversation continue till the CFP Reviewer is going to mention a “looks good”.

Note: It may not be a good idea to let the conversation continue till the text “looks good” is there in the response from the CFP Reviewer. There could be a significant number of conversations going back and forth at times, which might result in a cost too. So look at multiple strategies and/or a combination of both of these to achieve some sort of an optimal result after a certain number of iterations.

Conclusion

If you would like to check out the repository, here you go: github.com

Hope this part builds upon the previous one and shows a different way of terminating a conversation between two agents in the Autogen framework. In the next part of the series, we will look at how we can design a Human Agent in the loop, such that the Human Agent (us) can interact with various other Autonomous Agents, possibly review their work, ask them to do it again and more. Stay tuned.