Skip to main content

Multiagent Framework

Project description

MASLibPy: Multi-Agent System Library

maslibpy is a lightweight, modular Python library designed to facilitate the creation and management of multi-agent systems. It provides a structured framework for building agents, defining their communication protocols, and integrating them with various Large Language Models (LLMs).

Features

  • Modular design for agent creation and management.
  • Built-in support for system, user, and assistant message flows.
  • Seamless integration with multiple LLM providers (e.g., OpenAI, Together, Groq, Replicate).
  • Easy-to-use APIs for invoking and orchestrating agent interactions.
  • Dynamic crew management for multi-agent collaborations.

Installation

git clone https://github.com/bayeslabs/maslibpy.git
cd maslibpy
pip install poetry
poetry install

Directory Structure

maslibpy/
├── agent/
│   ├── baseagent.py
│   ├── agent.py
│   └── agent_prompt.py
├── messages/
│   ├── base.py
│   ├── system.py
│   ├── user.py
│   └── assistant.py
├── pattern/
│   └── sequential.py
├── llm/
│   ├── llm.py
│   └── constants.py

File Descriptions

Agent:

  • baseagent.py: Contains the base agent class BaseAgent with core properties like id, name, role, and goal. Also includes integration with LLMs.
  • agent.py: Implements the Agent class, extending BaseAgent. It defines the agent's behavior, including how queries are handled and responses are generated.
  • agent_prompt.py: Provides the template prompt used by agents for structured reasoning and interaction.

Message:

  • base.py: Defines the foundational BaseMessage class for managing the message flow within the system.
  • system.py: Implements the SystemMessage class for system-level communication.
  • user.py: Implements the UserMessage class for user-initiated communication.
  • assistant.py: Implements the AIMessage class for assistant responses.

Pattern:

  • sequential.py: Implements the Crew class, which manages a group of agents and orchestrates their collaborative tasks using an LLM backend in a sequantial manner.

LLM:

  • llm.py: Manages LLM integration, including provider validation, model invocation, and environment variable checks for API keys.
  • constants.py: Defines environment variables, supported LLM providers, and available model configurations.

Example Usage

Note: pattern/sequential.py was previsously crew/crew.py

from maslibpy.agent.agent import Agent
from maslibpy.crew.crew import Crew
from maslibpy.llm.llm import LLM

symptom_collector_agent=Agent(
    name="Symptom Collector Agent",
    role="Gather user-provided symptoms and health details.",
    goal="Ensure accurate and complete collection of symptoms to aid in diagnosis",
    backstory=" A meticulous assistant trained in identifying and documenting symptoms for medical evaluations.",
    llm=LLM(provider="groq",model_name="groq/llama-3.1-8b-instant")
)

diagnosis_agent=Agent(
    name="Diagnosis Agent",
    role="Analyze symptoms to hypothesize potential diagnoses.",
    goal=" Provide an accurate and reasoned diagnosis based on the input symptoms",
    backstory="A seasoned diagnostician trained on vast medical data to recognize patterns in health issues.",
    llm=LLM(provider="groq",model_name="groq/llama-3.1-8b-instant")
)

treatment_recommender_agent=Agent(
    name="Treatment Recommender Agent",
    role="Suggest treatments or next steps based on diagnosis.",
    goal=" Recommend the most effective and feasible treatment options.",
    backstory="A caring guide with expertise in medical treatments, always prioritizing patient well-being.",
    llm=LLM(provider="groq",model_name="groq/llama-3.1-8b-instant")
)

sys_prompt="""
You are an assistant helping in healthcare diagnosis.  
- Step 1: Symptom Collector: Collect and summarize symptoms and relevant information from the user.  
- Step 2: Diagnosis Agent: Based on the collected symptoms, suggest a potential diagnosis with reasoning.  
- Step 3: Treatment Recommender: Provide treatment options or next steps.  
Always think step-by-step and clearly explain your reasoning at each stage.
"""

# Main #

crew=Crew([symptom_collector_agent,diagnosis_agent,treatment_recommender_agent],
          system_prompt=sys_prompt)
          
response = crew.invoke("I have been experiencing headaches, nausea, and sensitivity to light.")
print(response)

Configuration

Environment Variables

Ensure the appropriate API keys are set in your environment variables:

  • TOGETHER_API_KEY
  • GROQ_API_KEY
  • REPLICATE_API_KEY

Supported LLM Providers and Models:

  • Refer to maslibpy/llm/constants.py for the list of supported providers and models.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a pull request with a detailed description.

Contact


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

maslibpy-0.0.2.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

maslibpy-0.0.2-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file maslibpy-0.0.2.tar.gz.

File metadata

  • Download URL: maslibpy-0.0.2.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for maslibpy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8cdf1e3bc1e87f3926eebe8a22cdb46b8766e33114403196da038e54fc02408b
MD5 905f8ae40051fa35088af6bca0e98d60
BLAKE2b-256 f3eed1439aa9954c0da0315392ebda13d1e7e1b2d92fd6c129a100637c37a56b

See more details on using hashes here.

File details

Details for the file maslibpy-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: maslibpy-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for maslibpy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 50021ee9982914ed8ce63b3a14647524eac84cd50d5a2a806b868c4e3957231a
MD5 bdd5415f0366b3ad4ded8c1abd0bbbbc
BLAKE2b-256 090825f59f237b9fe7e9fa75b7ecc563243a071235669b33fd9f824e69e8159e

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