Skip to main content

What is Together MoA?

Mixture of Agents (MoA) is a novel approach that leverages the collective strengths of multiple LLMs to enhance performance, achieving state-of-the-art results. By employing a layered architecture where each layer comprises several LLM agents, MoA significantly outperforms GPT-4 Omni’s 57.5% on AlpacaEval 2.0 with a score of 65.1%, using only open-source models! The way Together MoA works is that given a prompt, like tell me the best things to do in SF, it sends it to four different OSS LLMs. It then combines results from all four, sends it to a final LLM, and asks it to combine all four responses into an ideal response. That’s it! It’s the idea of combining the results of four different LLMs to produce a better final output. It’s slower than using a single LLM, but it can be great for use cases where latency doesn’t matter as much, like synthetic data generation. For a quick summary and three-minute demo on how to implement MoA with code, watch the video below:

Together MoA in 50 lines of code

To get started with using MoA in your own apps, you’ll need to install the Together Python library, get your Together API key, and run the code below which uses our chat completions API to interact with OSS models.
  1. Install the Together Python library.
Shell
  1. Get your Together API key and export it.
Shell
  1. Run the code below, which interacts with our chat completions API.
This implementation of MoA uses two layers and four LLMs. We’ll define our four initial LLMs and our aggregator LLM, along with our prompt. We’ll also add in a prompt to send to the aggregator to combine responses effectively. Now that we have this, we’ll send the prompt to the four LLMs and compute all results simultaneously. Finally, we’ll send the results from the four LLMs to our final LLM, along with a system prompt instructing it to combine them into a final answer, and we’ll stream results back.
Python

Advanced MoA example

In the previous example, we went over how to implement MoA with two layers (four LLMs answering and one LLM aggregating). However, one strength of MoA is being able to go through several layers to get an even better response. In this example, we’ll go through how to run MoA with 3+ layers.
Python

Resources