Skip to main content

Nexus is a powerful and flexible Python package for managing AI agents and coordinating complex tasks using LLMs.

Project description

PrimisAI Nexus

arXiv PWC PWC

Tests Continuous Delivery PyPI - Version PyPI - Downloads Python Version from PEP 621 TOML GitHub License

PrimisAI Nexus is a powerful and flexible Python package for managing AI agents and coordinating complex tasks using LLMs. It provides a robust framework for creating, managing, and interacting with multiple specialized AI agents under the supervision of a central coordinator.

Features

  • AI Base Class: A foundational class for AI interactions.
  • Agent Class: Extends the AI base class with additional features for specialized tasks.
  • Supervisor Class: Manages multiple agents, coordinates tasks, and handles user interactions.
  • Hierarchical Supervision: Support for main and assistant supervisors enabling complex task hierarchies.
  • Persistent History: Built-in conversation history management with JSONL storage.
  • Integrated Logging: Organized logging system within workflow structure.
  • Debugger Utility: Integrated debugging capabilities for logging and troubleshooting.
  • Flexible Configuration: Easy-to-use configuration options for language models and agents.
  • Flexible LLM Parameters: Direct control over all language model parameters through configuration.
  • Interactive Sessions: Built-in support for interactive chat sessions with the AI system.
  • YAML Configuration: Define complex agent hierarchies using YAML files for easy setup and modification.

Installation

You can install PrimisAI Nexus directly from PyPI using pip:

pip install primisai

Building from Source

If you prefer to build the package from source, clone the repository and install it with pip:

git clone git@github.com:PrimisAI/nexus.git
cd nexus
pip install -e .

Quick Start

Here's a simple example to get you started with Nexus:

from primisai.nexus.core import AI, Agent, Supervisor
from primisai.nexus.utils.debugger import Debugger

# Configure your OpenAI API key
llm_config = {
    "api_key": "your-api-key-here",
    "model": "gpt-4o",
    "base_url": "https://api.openai.com/v1",
}

# Create a supervisor
supervisor = Supervisor("MainSupervisor", llm_config)

# Create and register agents
agent1 = Agent("Agent1", llm_config, system_message="You are a helpful assistant.")
agent2 = Agent("Agent2", llm_config, system_message="You are a creative writer.")

supervisor.register_agent(agent1)
supervisor.register_agent(agent2)

# Start an interactive session
supervisor.display_agent_graph()
supervisor.start_interactive_session()

YAML Configuration

PrimisAI Nexus supports defining complex agent hierarchies using YAML configuration files. This feature allows for easy setup and modification of agent structures without changing the Python code.

Example YAML Configuration

Here's a simple example of a YAML configuration file:

supervisor:
  name: TaskManager
  type: supervisor
  llm_config:
    model: ${LLM_MODEL}
    api_key: ${LLM_API_KEY}
    base_url: ${LLM_BASE_URL}
  system_message: "You are the task management supervisor."
  children:
    - name: TaskCreator
      type: agent
      llm_config:
        model: ${LLM_MODEL}
        api_key: ${LLM_API_KEY}
        base_url: ${LLM_BASE_URL}
      system_message: "You are responsible for creating new tasks."
      keep_history: true
      tools:
        - name: add_task
          type: function
          python_path: examples.task_management_with_yaml.task_tools.add_task

The keep_history parameter allows you to control whether an agent maintains conversation history between interactions. When set to False, the agent treats each query independently, useful for stateless operations. When True (default), the agent maintains context from previous interactions.

To use this YAML configuration:

from primisai.nexus.config import load_yaml_config, AgentFactory

# Load the YAML configuration
config = load_yaml_config('path/to/your/config.yaml')

# Create the agent structure
factory = AgentFactory()
task_manager = factory.create_from_config(config)

# Start an interactive session
task_manager.start_interactive_session()

For a more detailed example of YAML configuration, check out the task management example.

Benefits of YAML Configuration

  • Flexibility: Easily modify agent structures without changing Python code.
  • Readability: YAML configurations are human-readable and easy to understand.
  • Scalability: Define complex hierarchies of supervisors and agents in a clear, structured manner.
  • Separation of Concerns: Keep agent definitions separate from application logic.

Documentation

For detailed documentation on each module and class, please refer to the inline docstrings in the source code.

History and Logging

PrimisAI Nexus provides comprehensive history management and logging capabilities organized within workflow directories:

nexus_workflows/
├── workflow_123/              # Workflow specific directory   ├── history.jsonl         # Conversation history   └── logs/                 # Workflow logs       ├── MainSupervisor.log
│       ├── AssistantSupervisor.log
│       └── Agent1.log
└── standalone_logs/          # Logs for agents not in workflows
    └── StandaloneAgent.log

Advanced Usage

PrimisAI Nexus allows for complex interactions between multiple agents. You can create specialized agents for different tasks, register them with a supervisor, and let the supervisor manage the flow of information and task delegation.

# Example of creating a specialized agent with tools
tools = [
    {
        "metadata": {
            "name": "search_tool",
            "description": "Searches the internet for information"
        },
        "tool": some_search_function
    }
]

research_agent = Agent("Researcher", llm_config, tools=tools, system_message="You are a research assistant.", use_tools=True)
supervisor.register_agent(research_agent)

Hierarchical Supervisor Structure

PrimisAI Nexus supports a hierarchical supervisor structure with two types of supervisors:

  1. Main Supervisor: The root supervisor that manages the overall workflow

  2. Assistant Supervisor: Specialized supervisors that handle specific task domains

Here's how to create and use different types of supervisors:

# Create a main supervisor with a specific workflow ID
main_supervisor = Supervisor(
    name="MainSupervisor",
    llm_config=llm_config,
    workflow_id="custom_workflow_123"
)

# Create an assistant supervisor
assistant_supervisor = Supervisor(
    name="AnalysisManager",
    llm_config=llm_config,
    is_assistant=True,
    system_message="You manage data analysis tasks."
)

# Create agents
data_agent = Agent("DataAnalyst", llm_config, system_message="You analyze data.")
viz_agent = Agent("Visualizer", llm_config, system_message="You create visualizations.")

# Register assistant supervisor with main supervisor
main_supervisor.register_agent(assistant_supervisor)

# Register agents with assistant supervisor
assistant_supervisor.register_agent(data_agent)
assistant_supervisor.register_agent(viz_agent)

# Display the complete hierarchy
main_supervisor.display_agent_graph()

The above code creates a hierarchical structure where:

  • Main Supervisor manages the overall workflow
  • Assistant Supervisor handles specialized tasks
  • Agents perform specific operations

The display_agent_graph() output will show:

Main Supervisor: MainSupervisor
│
└── Assistant Supervisor: AnalysisManager
    │
    ├── Agent: DataAnalyst
    │   └── No tools available
    │
    └── Agent: Visualizer
        └── No tools available

Each workflow is automatically assigned a unique ID and maintains its conversation history in a dedicated directory structure:

custom_workflow_123/
├── history.jsonl
└── logs
    ├── AnalysisManager.log
    ├── DataAnalyst.log
    ├── MainSupervisor.log
    └── Visualizer.log

All interactions, delegations, and tool usage are automatically logged and stored in the workflow directory, providing complete visibility into the decision-making process and execution flow.

Citation

If you find Nexus useful, please consider citing our preprint.

@article{sami2025nexus,
  title={Nexus: A Lightweight and Scalable Multi-Agent Framework for Complex Tasks Automation},
  author={Sami, Humza and ul Islam, Mubashir and Charas, Samy and Gandhi, Asav and Gaillardon, Pierre-Emmanuel and Tenace, Valerio},
  journal={arXiv preprint arXiv:2502.19091},
  year={2025}
}

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

primisai-0.5.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

primisai-0.5.0-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

Details for the file primisai-0.5.0.tar.gz.

File metadata

  • Download URL: primisai-0.5.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for primisai-0.5.0.tar.gz
Algorithm Hash digest
SHA256 195ea85285cdff9b1f96960738d315b071f0786ab9f1bd5d91a53b9f11b4770b
MD5 cd47f9bd673b71d0a3d7d4312646b7e0
BLAKE2b-256 1cadcb6287bb1cfe0b5990d97ae3a4988200f73edee1dfa050686e9388337829

See more details on using hashes here.

File details

Details for the file primisai-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: primisai-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 39.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for primisai-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53dc6c4d8f28b29573247d1a66424ead8eb0c2bee98711480e81c885da2da10e
MD5 676ab159a9f241e1a848da217092f7a1
BLAKE2b-256 96ed510e4b65932b88c669609307466347ad784d2ecba503e24fbfc0017d2b7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page