Autonomous Multi-Agent Architecture | OpenAGI 0.2.9.4 release

Autonomous Multi-Agent Architecture | OpenAGI 0.2.9.4 release

Aug 14, 2024

Aug 14, 2024

Agents are the hottest buzz in tech right now, with developers eager to automate workflows effortlessly using agentic frameworks.

You’ve probably heard the chatter — can LLMs really plan or reason independently? According to multiple research papers, the answer is no. But don’t get me wrong, this doesn’t mean they’re useless in an agentic workflow. What LLMs can do, and do very well:

Is help you design plans in an incredibly structured and detailed way.

And here’s where it gets exciting: We’re thrilled to announce a major release of OpenAGI. This update takes things up a notch by enabling the autonomous creation of multi-agent architectures.

Yes, you heard that right — let’s dive in! ⚡️

Its important to understand two terminology before we jump deeper:

  • Planner: The Planner in the OpenAGI contains essential modules and components that handle task planning and decomposition. These components are designed to work together to break down complex tasks into manageable sub-tasks, which are then executed by Admin.

  • Worker: Workers are special type of classes, responsible for carrying out the tasks assigned by the class “Admin”. They utilize tools such as internet search engines, LLMs, and document writers to perform their tasks. Additionally, they can determine which tools to use from a predefined set. This is where Agents go brr… with REACT PROMPTING.

Key Highlights:

1. Autonomous Multi-Agent Architecture: This addition helps to automatically define a Worker i.e., LLM automatically picks role, instructions and other descriptions to define a worker.

2. Chat History feedback for Human Intervention in Task Planning: Task Planner creates the tasks. This helps the Agentic workflow to involve human in a loop to clarify the task created by the Planner.

3. Custom Tool Integration cookbook: We included a cookbook on how one can build their own custom tool and build Agentic workflow using OpenAGI.

4. Benchmarking- HotpotQA: We also added a benchmarking script to evaluate the Agentic Workflow as per the research paper. This metric calculates F1 Score and Accuracy score for few set of internet questions.

Now its time for Magic 🪄

Autonomous Multi-Agent Architecture

This release brings a groundbreaking feature: an Autonomous Multi-Agent architecture that automates the creation and assignment of workers, removing the need for manual setup. Additionally, we’ve empowered the planner to autonomously design multiple workers, each with specialized roles and strict instructions to follow.

Just as a large task like writing a blog is broken down into smaller steps — researching, drafting, and publishing — the planner can now autonomously take a user query and description, decompose it into smaller, manageable tasks, and assign them to the appropriate workers.

To utilize this feature, set the TaskPlanner to autonomous=True.

Installation


Example Usage

Let’s build a Cricket Update Multi-Agent architecture by integrating the required modules, utilizing the Tavily Search API, and leveraging the Gemini 1.5 Flash LLM. Here’s how we can get started:


Save API keys in the environment variable.

Save the API keys in environment variables. Both Tavily and Gemini require API keys for access — Tavily assists with browsing and context retrieval, while Gemini handles long-context response generation.

import os
from getpass import getpass

# setup Gemini and Tavily API Key
os.environ['TAVILY_API_KEY'] = getpass("Enter Tavily API key:")
os.environ['GOOGLE_API_KEY'] = getpass("Enter your Gemini API key:")
os.environ['Gemini_MODEL'] = "gemini-1.5-flash"
os.environ['Gemini_TEMP']

Define the Planner and Configure LLM

Load the configuration files from the environment and pass them to the model parameters. Notice that the autonomous setting is enabled (autonomous=True).


Define and Run Admin

An Agentic workflow depends on: LLM, planning, Action and Memory (optional). Define each of them inside Admin and run the workflow by providing query and description.

admin = Admin(
    actions = [TavilyWebSearchQA]

Output

### India vs Sri Lanka 2024 ODI Series Overview
#### Match Details:
**2nd ODI:**
- **Date:** August 4, 2024
- **Venue:** R Premadasa Stadium, Colombo
- **Result:** Sri Lanka won by 32 runs
- **Man of the Match:** Jeffrey Vandersay, with an impressive performance of 6 wickets for 33 runs.
**3rd ODI:**
- **Date:** August 7, 2024
- **Venue:** Colombo
- **Result:** Sri Lanka won by 110 runs
- **Top Performer:** Avishka Fernando scored 96 runs. However, the Man of the Match was not specified in the data provided.
**Note:**

Well the First Match was Tied, my Agent isn’t wrong😉

Lets jumpt to next feature/improvements we made.

Chat History for Human Intervention in Task Planning

We can’t let AI operate without guidance. Just like humans improve through feedback and clarification, the same principles apply to LLMs within an agentic workflow. To ensure effective planning, we use human_intervene to ask clarifying questions, allowing the Planner to propose and create well-organized, decomposed tasks.

In our previous release, we improved the human intervention feature but restricted the model by setting a threshold without retaining its previous history. This led to repeated questions, which we observed could be pruned with better context management. Maintaining chat history helps avoid repetitive queries and enhances task execution accuracy by ensuring that relevant information is always accessible.

To implement this feature, initialize the TaskPlanner with human_intervene=True. The human intervention will stop once the task is fully clarified by the LLM. If you encounter multiple clarification questions, show reluctance and instruct the model to generate the plan using the already answered questions.

Well, lets add human intervene to same above example i.e., our Cricket Update Agent.

Only change is:

The other part of code remains the same.

from openagi.planner.task_decomposer import TaskPlanner
from openagi.actions.tools.tavilyqasearch import TavilyWebSearchQA
from openagi.agent import Admin
from openagi.llms.gemini import GeminiModel

import os
from getpass import getpass
# setup Gemini and Tavily API Key
os.environ['TAVILY_API_KEY'] = getpass("Enter Tavily API key:")
os.environ['GOOGLE_API_KEY'] = getpass("Enter your Gemini API key:")
os.environ['Gemini_MODEL'] = "gemini-1.5-flash"
os.environ['Gemini_TEMP'] = "0.7"
gemini_config = GeminiModel.load_from_env_config()
llm = GeminiModel(config=gemini_config)
# define the planner
plan = TaskPlanner(autonomous=True,human_intervene=True)
admin = Admin(
    actions = [TavilyWebSearchQA]

Human Intervene

Custom Action Tool Integration

OpenAGI makes integrating custom tools a breeze, letting you pull context from your preferred APIs or functions with ease.

But why would you need a custom action tool in the first place?

Sure, OpenAGI already supports a decent range of tools — think DuckDuckGo, Tavily, YouTube, GitHub — but let’s face it, there’s a vast landscape of tools out there just waiting to be tapped into. Say you want to integrate a new tool, like a Lyrics Finder, for instance.

With OpenAGI, you can whip that up with just a single class and method. Simple as that!

Syntax


Note: Docstring is must. This helps the Planner and Worker to get the context when to trigger that tool.

Example

We will use Serper API key for finding the Lyrics. So write our tool now.


Well there you go, the custom tool is built.

We don’t want you to get bored, so for more details, check out our documentation page:

📝Introduction | OpenAGI

Conclusion

In addition to these exciting features, we’ve also addressed several bugs, including improvements to the JSON Decode Error exception handling. Most importantly we have added the script on our repo to benchmark the Agentic workflow, don’t miss it out:

https://github.com/aiplanethub/openagi/blob/main/src/benchmark.py

This release marks a significant step forward in making OpenAGI a robust platform for developing autonomous agents capable of complex task execution.

We invite developers and researchers to explore these new features and contribute to the OpenAGI project. For more details, visit our GitHub repository and check out the documentation for additional examples and use cases.

Many efforts have went though this release, do ⭐️ the repo and support the project. We are still open for the contributions, the merged PRs will get the AI Planet T-shirts.