Notebooks
T
Together
Parallel Agent Workflow

Parallel Agent Workflow

Author: Zain Hasan

Open In Colab

Introduction

In this notebook, we'll demonstrate how you can create an agent workflow that will execute multiple LLMs in parallel to solve the same task - proposing solutions which a final LLM aggregates into a response for the user.

This strategy, proposed in the Mixture of Agents paper, shows results far beyond the capabilities of individual contributing models.

This notebook covers:

  1. An architecture that enables multiple LLMs to solve a task in parallel and propose solutions
  2. An aggregator model that synthesizes individual proposals into one final answer

Parallel Agent Workflow - Mixture of Agents

In this parallel agent workflow, we demonstrate how you can orchestrate multiple LLMs to work simultaneously on the same task, with each model proposing its own solution. This approach leverages the collective intelligence of different models, with their responses being aggregated by a final LLM that synthesizes a comprehensive solution. Each model in the parallel workflow can have different capabilities or specialized knowledge, contributing unique perspectives to the task at hand.

The aggregator model then analyzes these various proposals to create an enhanced final response that builds upon the strengths of each individual contribution.

For our specific use case, the workflow breaks down as follows:

  1. Given a user prompt, multiple LLMs process the task in parallel, each generating their own proposed solution
  2. All individual responses are collected and passed to an aggregator LLM
  3. The aggregator LLM analyzes the collective proposals and synthesizes them into a final, improved response for the user

Now let's see the coded implementation of this workflow.

Setup and Utils

[ ]
[ ]
[ ]

Parallel Agent Implementation

[4]
[7]
<>:10: SyntaxWarning: invalid escape sequence '\%'
/var/folders/yd/r39kvy_94lvg2n0_11qz3pf00000gn/T/ipykernel_94920/1089907714.py:10: SyntaxWarning: invalid escape sequence '\%'
  user_prompt = """Tim wants to invest some money in a bank which compounds quarterly
[ ]

Next we'll aggregate the intermediate responses using anohter LLM:

[10]
You have been provided with a set of responses from various open-source models to the latest user query.
Your task is to synthesize these responses into a single, high-quality response. It is crucial to critically evaluate the information
provided in these responses, recognizing that some of it may be biased or incorrect. Your response should not simply replicate the
given answers but should offer a refined, accurate, and comprehensive reply to the instruction. Ensure your response is well-structured,
coherent, and adheres to the highest standards of accuracy and reliability.

Responses from models:
1.  Let's think step by step.To solve this problem, we will use the formula for compound interest, which is given by:

\[ A = P \left(1 + \frac{r}{n}\right)^{nt} \]

where:
- \( A \) is the amount of money accumulated after \( n \) years, including interest.
- \( P \) is the principal amount (the initial amount of money).
- \( r \) is the annual interest rate (in decimal form).
- \( n \) is the number of times that interest is compounded per year.
- \( t \) is the time the money is invested for, in years.

Given:
- The final amount \( A \) that Tim wants is $60,000.
- The annual interest rate \( r \) is 7%, which we convert to a decimal by dividing by 100, so \( r = 0.07 \).
- The interest is compounded quarterly, which means \( n = 4 \) times per year.
- The time \( t \) is 5 years.

We need to find the principal \( P \) that Tim should invest.

Rearranging the compound interest formula to solve for \( P \), we get:

\[ P = \frac{A}{\left(1 + \frac{r}{n}\right)^{nt}} \]

Now, let's plug in the values:

\[ P = \frac{60,\!000}{\left(1 + \frac{0.07}{4}\right)^{4 \cdot 5}} \]

\[ P = \frac{60,\!000}{\left(1 + 0.0175\right)^{20}} \]

\[ P = \frac{60,\!000}{\left(1.0175\right)^{20}} \]

Now we calculate the value inside the parentheses:

\[ \left(1.0175\right)^{20} \approx 1.3899 \]

Now we divide the target amount by this value to find the initial investment \( P \):

\[ P = \frac{60,\!000}{1.3899} \]

\[ P \approx 43,\!163.77 \]

Since we want the answer to the nearest dollar, we round \( P \) to the nearest whole number:

\[ P \approx 43,\!164 \]

Therefore, Tim should invest approximately $43,164 to have $60,000 at the end of 5 years, with the interest compounded quarterly at an annual rate of 7%.

The final answer is \boxed{43164}.

The answer is: 43164.
2. To determine how much Tim should invest to have $60,000 at the end of 5 years with a bank that compounds interest quarterly at an annual rate of 7%, we can use the formula for compound interest:

\[
A = P \left(1 + \frac{r}{n}\right)^{nt}
\]

where:
- \( A \) is the amount of money accumulated after \( t \) years, including interest.
- \( P \) is the principal amount (the initial amount of money).
- \( r \) is the annual interest rate (decimal).
- \( n \) is the number of times interest is compounded per year.
- \( t \) is the time the money is invested for in years.

Given:
- \( A = 60,000 \)
- \( r = 0.07 \)
- \( n = 4 \) (since the interest is compounded quarterly)
- \( t = 5 \)

We need to solve for \( P \). Plugging in the known values, we get:

\[
60,000 = P \left(1 + \frac{0.07}{4}\right)^{4 \times 5}
\]

First, calculate the interest rate per quarter:

\[
\frac{0.07}{4} = 0.0175
\]

Next, calculate the total number of compounding periods:

\[
4 \times 5 = 20
\]

Now, substitute these values into the formula:

\[
60,000 = P \left(1 + 0.0175\right)^{20}
\]

Calculate \( 1 + 0.0175 \):

\[
1 + 0.0175 = 1.0175
\]

Raise 1.0175 to the power of 20:

\[
1.0175^{20} \approx 1.414778
\]

Now, solve for \( P \):

\[
60,000 = P \times 1.414778
\]

\[
P = \frac{60,000}{1.414778}
\]

\[
P \approx 42,413.79
\]

Rounding to the nearest dollar:

\[
P \approx 42,414
\]

Therefore, Tim should invest \(\boxed{42,414}\) dollars to have $60,000 at the end of 5 years.
3. Here's how to solve this problem:

**Understanding Compound Interest**

Compound interest means that interest is calculated not only on the principal amount but also on the accumulated interest from previous periods. This leads to exponential growth.

**Formula**

The formula for compound interest is:

A = P(1 + r/n)^(nt)

Where:

* A = the future value of the investment/loan, including interest
* P = the principal investment amount (the initial deposit or loan amount)
* r = the annual interest rate (as a decimal)
* n = the number of times that interest is compounded per year
* t = the number of years the money is invested or borrowed for

**Let's plug in the given values:**

* A = $60,000
* r = 7% = 0.07 (convert percentage to decimal)
* n = 4 (compounded quarterly)
* t = 5 years

We need to solve for P (the principal investment).

**Rearranging the formula:**

P = A / (1 + r/n)^(nt)

**Calculation:**

P = $60,000 / (1 + 0.07/4)^(4*5)
P = $60,000 / (1.0175)^20
P ≈ $43,757

**Answer:**

To the nearest dollar, Tim should invest approximately **$43,757**.
4. ## Step 1: Understand the problem
We are given that Tim wants to invest some money in a bank with a $7\%$ annual interest rate compounded quarterly. The goal is to find out how much he should invest in order to have a total of $\$60,000$ at the end of $5$ years.

## Step 2: Identify the formula for compound interest
The formula for compound interest is $A = P\left(1 + \frac{r}{n}\right)^{nt}$, where $A$ is the amount of money accumulated after $n$ years, including interest, $P$ is the principal amount (initial investment), $r$ is the annual interest rate (in decimal), $n$ is the number of times that interest is compounded per year, and $t$ is the time the money is invested for in years.

## Step 3: Plug in the given values into the compound interest formula
We know that $A = \$60,000$, $r = 0.07$, $n = 4$ (since the interest is compounded quarterly), and $t = 5$. We need to solve for $P$.

## Step 4: Substitute the given values into the formula and solve for P
$60,000 = P\left(1 + \frac{0.07}{4}\right)^{4 \cdot 5}$
$60,000 = P\left(1 + 0.0175\right)^{20}$
$60,000 = P\left(1.0175\right)^{20}$
$P = \frac{60,000}{\left(1.0175\right)^{20}}$

## Step 5: Calculate the value of P
$P = \frac{60,000}{\left(1.0175\right)^{20}} \approx \frac{60,000}{1.419067227}$
$P \approx 42,409.47466$

## Step 6: Round the result to the nearest dollar
Rounded to the nearest dollar, $P \approx \$42,409$.

The final answer is: $\boxed{42409}$
[11]
To determine how much Tim should invest to have \$60,000 at the end of 5 years with an annual interest rate of 7% compounded quarterly, we can use the **compound interest formula**:

\[
A = P \left(1 + \frac{r}{n}\right)^{nt}
\]

Where:
- \( A \) is the future value (\$60,000),
- \( P \) is the principal amount (the initial investment we need to find),
- \( r \) is the annual interest rate (7% or 0.07),
- \( n \) is the number of times interest is compounded per year (quarterly means \( n = 4 \)),
- \( t \) is the number of years (5).

We rearrange the formula to solve for \( P \):

\[
P = \frac{A}{\left(1 + \frac{r}{n}\right)^{nt}}
\]

Now, substitute the given values:

\[
P = \frac{60,\!000}{\left(1 + \frac{0.07}{4}\right)^{4 \cdot 5}}
\]

Simplify the terms inside the parentheses:

\[
1 + \frac{0.07}{4} = 1.0175
\]

Calculate the exponent:

\[
4 \cdot 5 = 20
\]

Now, compute \( (1.0175)^{20} \):

\[
(1.0175)^{20} \approx 1.414778
\]

Finally, solve for \( P \):

\[
P = \frac{60,\!000}{1.414778} \approx 42,\!413.79
\]

Rounding to the nearest dollar:

\[
P \approx 42,\!414
\]

**Answer:** Tim should invest approximately \(\boxed{42,\!414}\) dollars to have \$60,000 at the end of 5 years.

Generic Implementation

Now we will create a succint function that you can use to try out different combinations of proposers

[12]
[13]
[14]
Final Answer: To determine the total number of apples Jenna and her mother picked together, follow these steps:

1. **Jenna's Apples:**  
   Jenna picked half as many apples as her mother. Since her mother picked 20 apples, Jenna picked:  
   \[
   \frac{1}{2} \times 20 = 10 \text{ apples}
   \]

2. **Total Apples:**  
   To find the total number of apples they both picked, add the number of apples Jenna's mother picked to the number of apples Jenna picked:  
   \[
   20 \text{ (mother's apples)} + 10 \text{ (Jenna's apples)} = 30 \text{ apples}
   \]

**Final Answer:**  
Jenna and her mother together picked **30 apples**.