The capabilities of Multi-Agent Systems have evolved substantially due to the advancements and developments in large language models. This evolution is not just limited to automating tasks but also using near-human reasoning capabilities. The challenge with MAS architectures is that they rely on overcomplex code implementations, making reusability a big problem. Nexus, a lightweight Python framework, is designed to easily build and manage LLM-based MASs. Nexus supports hierarchical architectures, a supervised workflow design, and easy usage, which allows its usage without a high degree of complexity. This article explains Nexus and its usage capabilities in-depth.
Table of Contents
- Overview of Multi-Agent Systems
- Understanding Nexus Framework
- Evaluation Analysis and Results
- Hands-on Implementation of Nexus
Overview of Multi-Agent Systems
Multi-agent systems (MASs) are fundamental systems in distributed AI that enable the decomposition of tasks into manageable components that autonomous agents can further execute. These agents use historical knowledge, interactions with other agents, and the environment to make important decisions acting without any human intervention. This makes MASs different from traditional distributed problem-solving systems, enhancing their ability to operate effectively in dynamic and uncertain environments.
The agents in a MAS operate with a degree of autonomy and segregated agents to learn how to solve problems combined as one single cohesive unit. Key components in a MAS architecture include agents, environment, and interactions. Agents are described as the core actors with roles, capabilities, and knowledge models. The environment is the external world where the agents are, sensing and acting upon the information caught. The communication between the agents is referred to as interaction, which can be some form of coordination, negotiation, or based on the requirements of the system.
MAS architectures can be in different formats – Traditional, ReAct & LLM-based. Traditional MAS architecture consists of agents that interact with their environment through observations and actions. ReAct corresponds to reasoning and action, this agent architecture incorporates advanced reasoning capabilities. The LLM-based architecture employs the use of LLM-based agents for reasoning and decision-making tasks.
Critical challenges in MAS architecture include the coordination between multiple agents, task assignments, and scalability when large systems are concerned. To resolve these challenges, several types of research have been conducted, paving the way for different methodologies such as leader-follower hierarchies, wherein the leader agent defines the global objectives and delegates tasks while the middle-agent frameworks streamline service discovery and coordination among agents.
Recent progress in the field of large language models is improving the MAS architecture and its usage capabilities, such as near-human reasoning capabilities. LLMs can act as a central reasoning agent, enhancing adaptability, collaboration, and decision-making in dynamic environments when integrated into the MAS architecture. These advancements have also pushed MAS applications into the fields of multimodal reasoning, complex mathematical problem-solving, and autonomous navigation which were once beyond the scope of MAS approaches.
LLM-based MASs rely on two important principles: a task-specific architecture that maximizes the efficiency of LLMs, and methodologies for implementing domain-specific knowledge and its usage in the agents. However, integrating external knowledge based on LLM-based MAS can add to the overall complexity and contribute towards scalability issues as well, due to knowledge constraints and limited adaptability towards different domains. Also, developing and deploying an LLM-based MAS from scratch is difficult, especially for non-technical audiences.
Nexus is a novel open-source Python-based framework that allows users to design MAS architectures using low-code design criteria easily. Nexus is lightweight, scalable, and orthogonal to LLMs and application domains, enabling intelligent automation across different tasks and problems.
Understanding Nexus Framework
The Nexus framework is based on a modular design integrating a single root supervisor agent alongside multiple task supervisors and worker agents. These components are designed as per a hierarchical execution graph for efficient task delegation, scalability, and flexibility. The root supervisor arbitrates the communication between the user and the agents. Its primary responsibilities include task decomposition, agent selection, and result aggregation.
Task decomposition involves breaking up the high-level prompts into actionable subtasks. Agent selection refers to the delegation of tasks to the most appropriate worker agent based on agent specialization. Result aggregation, on the other hand, is the collection of outputs from delegated subtasks and blending them into a final response. Worker agents are specialized problem solvers who the supervisor assigns tasks to. Each worker operates in an isolated environment comprising a unique specialization defined by its system message, associated tools and functions, and environment data. The capabilities of worker agents include using dedicated tools(e.g., web search), or knowledge bases to perform domain-specific tasks, iteratively refining transitional results through interactions with tools or knowledge bases, and returning outputs to the supervisor upon completion of the designated task.
Nexus incorporates a global memory along with a set of external tools. The memory stores the partial results with instructions, guaranteeing that all the agents are up-to-date on the task progress. Memory in Nexus is a shared repository where the supervisor has global access, worker agents are confined to their event history and the task supervisor can access all memory locations related to the assigned agents. The external tools, on the other hand, allow the agents to operate in a specialized manner for a specific task, such as web searching or accessing external resources (cloud buckets, etc.).
Nexus introduces an iterative process for task decomposition and execution, categorized into three primary interaction loops –
Loop 1: User-Supervisor Interaction – In this loop, the user provides a high-level prompt to the supervisor. The supervisor interprets and outlines the task execution plan and continues to align the plan with user objectives. This exchange is iterative and continues until the supervisor is ready to delegate subtasks to other agents or finalize a solution.
Loop 2: Supervisor-Agent Coordination – In this loop, the supervisor assigns subtasks to worker agents based on their specialization. The worker agents then use the available tools and generate intermediate results.
Loop 3: Intra-Agent Operations – The final loop works within each worker agent’s internal environment. The worker refines the intermediate results based on the iterative usage of external tools and resources. Once the solution is achieved, it is relayed back to the supervisor for final synthesis.
These loops allow Nexus to support diverse interaction patterns among agents and their operating environments. It allows scalability, modularity, and robustness properties where the framework can incorporate new agents based on the increase in task complexity, worker agents can operate independently, and the hierarchical delegation with iterative feedback loops reduces the agent failure impact as the tasks can be reassigned or refined with ease.
Evaluation Analysis and Results
The performance of Nexus was evaluated based on the pass rate, which is the ratio between the number of samples that pass all checks and the total number of samples in the benchmark. In coding tasks, where the effectiveness of the Nexus framework was evaluated based on its efficiency in addressing programming-related tasks. The evaluation used HumanEval and VerilogEval-Human benchmarks.
HumanEval benchmark is based on a collection of 164 problems focused on Python code generation whereas the VerilogEval-Human comprises 156 challenges involving Verilog code generation and verification. The proposed Nexus-based MAS architecture for solving code-related tasks can be diagrammatically represented using the figure shown below.
Nexus-based MAS architecture for code-related tasks
The following table shows the effectiveness of the proposed workflow based on the ablation study on the pass rate.
The following table compares the performance of the proposed workflows based on Nexus versus relevant existing solutions.
The effectiveness of Nexus in solving mathematical problems was demonstrated using the MATH dataset. The workflow, shown below, was used where a supervisor, a mathematician agent, and a reviewer agent were used. They all were powered by Claude 3.5v2 LLM.
Nexus-based MAS architecture for math problems
Ablation study results on the MATH dataset
Hands-on Implementation of Nexus
Let’s implement Nexus based on MAS architecture for code review & refactoring.
Step 1: Install the required libraries –
!git clone https://github.com/PrimisAI/nexus.git
%cd nexus
!pip install -e .
Step 2: Import the library and set up the LLM configuration –
from primisai.nexus.core import Agent, Supervisor
from google.colab import userdata
import os
os.environ["OPENAI_API_KEY"] = userdata.get("OPENAI_API_KEY")
llm_config = {
"api_key": os.getenv("OPENAI_API_KEY"),
"model": "gpt-4o",
"base_url": "https://api.openai.com/v1"
}
Step 3: Creating three agents – Supervisor, CodeReviewer & CodeRefactor
coordinator = Supervisor("ProgrammingCoordinator", llm_config)
code_reviewer = Agent(
"CodeReviewer",
llm_config,
system_message = "You are a coding expert who specializes in code analysis. Your task is to review the code, identify bugs and recommend improvements."
)
code_refactor = Agent(
"CodeRefactor",
llm_config,
system_message = "You are a coding expert who specializes in code refactoring. Your objective is to enhance the code readability and efficiency."
)
Step 4: Registering the agents with the coordinator (supervisor) –
coordinator.register_agent(code_reviewer)
coordinator.register_agent(code_refactor)
Step 5: Displaying the agent hierarchy –
coordinator.display_agent_graph()
Step 6: Running the agent and providing a sample Python code for code review and refactoring –
coordinator.start_interactive_session()
Output –
We can see Nexus was able to review and refactor our Python code based on the MAS architecture and suggested a robust, efficient, and user-friendly version of it with proper documentation.
Final Words
Nexus is a lightweight Python framework that simplifies the development and management of LLM-based Multi-Agent systems. Nexus enables flexibility through a hierarchical methodology alongside YAML-based architecture and workflow definition. This facilitates impeccable integration, scalability, and extensibility through modular design. Nexus represents a significant advancement in the development of MASs, improving LLM-based problem-solving.