Skip to main content

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


Metadata

Release files for maslibpy 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maslibpy 0.0.2
File Size Uploaded Provenance Actions
maslibpy-0.0.2.tar.gz 14.9 kB Without provenance Details for maslibpy-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for maslibpy 0.0.2
File Interpreter ABI Platform Actions
maslibpy-0.0.2-py3-none-any.whl Python 3 none any Details for maslibpy-0.0.2-py3-none-any.whl

Total release size: 34.3 kB

Release files / maslibpy-0.0.2.tar.gz

Download URL maslibpy-0.0.2.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8cdf1e3bc1e87f3926eebe8a22cdb46b8766e33114403196da038e54fc02408b
BLAKE2b-256 checksum
How to use checksums
f3eed1439aa9954c0da0315392ebda13d1e7e1b2d92fd6c129a100637c37a56b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / maslibpy-0.0.2-py3-none-any.whl

Download URL maslibpy-0.0.2-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50021ee9982914ed8ce63b3a14647524eac84cd50d5a2a806b868c4e3957231a
BLAKE2b-256 checksum
How to use checksums
090825f59f237b9fe7e9fa75b7ecc563243a071235669b33fd9f824e69e8159e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Security for maslibpy 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page