Skip to main content

Multi-Agent Hyper-Scaling Methods

Project description

mahsm: Multi-Agent Hyper-Scaling Methods

A declarative framework for building, tracing, and evaluating multi-agent LLM systems

CI Status PyPI Python License


What is mahsm?

mahsm unifies four best-in-class libraries into a single, zero-boilerplate framework:

Component Purpose What mahsm Adds
DSPy Programming LLMs with optimizable modules Automatic LangGraph integration via @ma.dspy_node
LangGraph Stateful, cyclical multi-agent workflows Zero-boilerplate DSPy module wrapping
Langfuse Deep LLM observability & tracing Automatic instrumentation with ma.init()
EvalProtocol Pytest-based LLM evaluation Pre-configured harness for LangGraph apps

The mahsm Advantage

Before mahsm (Traditional approach):

# Manual state mapping, verbose boilerplate
def my_node(state: dict) -> dict:
    module = MyDSPyModule()
    result = module(input=state["input"])
    return {"output": result.output}  # Manual extraction

# Separate tracing setup
from langfuse import Langfuse
langfuse = Langfuse()
# ... complex instrumentation code ...

With mahsm (Declarative approach):

import mahsm as ma

ma.init()  # One-line tracing setup

@ma.dspy_node  # Automatic state mapping
class MyModule(ma.Module):
    def forward(self, input):
        return self.predictor(input=input)

⚡ Quick Start

Installation

pip install mahsm

Your First Agent (60 seconds)

import mahsm as ma
from typing import TypedDict
import dspy

# 1. Configure
lm = dspy.OpenAI(model='gpt-4o-mini')
dspy.settings.configure(lm=lm)
ma.init()  # Enable tracing

# 2. Define agent
class State(TypedDict):
    query: str
    answer: str

@ma.dspy_node
class Researcher(ma.Module):
    def __init__(self):
        super().__init__()
        self.cot = ma.dspy.ChainOfThought("query -> answer")
    
    def forward(self, query):
        return self.cot(query=query)

# 3. Build graph
workflow = ma.graph.StateGraph(State)
workflow.add_node("researcher", Researcher())
workflow.add_edge(ma.START, "researcher")
workflow.add_edge("researcher", ma.END)

graph = workflow.compile()

# 4. Run
result = graph.invoke({"query": "What is DSPy?"})
print(result["answer"])

That's it! Your agent is now:

  • ✅ Running with proper state management
  • ✅ Automatically traced in Langfuse
  • ✅ Ready for evaluation with EvalProtocol

📖 Complete Tutorial

Want to build a production-ready agent with full observability and evaluation?

👉 Read the Complete Quickstart Guide

You'll learn:

  • 🎯 Building complex multi-node agents
  • 📊 Setting up Langfuse for tracing
  • 🧪 Running systematic evaluations
  • 📈 Viewing results in Langfuse & EvalProtocol UIs
  • ⚡ Optimizing agents with DSPy compilers

🏗️ Core Features

1. @ma.dspy_node Decorator

The heart of mahsm: converts DSPy modules to LangGraph nodes automatically.

Supports two patterns:

Class Decorator

@ma.dspy_node
class MyModule(ma.Module):
    def forward(self, input1, input2):
        # Your logic here
        return self.predictor(input1=input1, input2=input2)

# Use in graph
workflow.add_node("my_node", MyModule())

Instance Wrapper

# Wrap any DSPy module instance
cot = ma.dspy.ChainOfThought("question -> answer")
node = ma.dspy_node(cot)

# Use directly
workflow.add_node("cot", node)

What it does:

  • ✅ Introspects forward() parameters (excludes self)
  • ✅ Extracts matching fields from LangGraph state
  • ✅ Returns result as state updates (non-private fields)
  • ✅ No manual state mapping needed

2. ma.init() - One-Line Tracing

handler = ma.init()

Automatically:

  • ✅ Initializes Langfuse client from environment variables
  • ✅ Instruments DSPy for automatic trace capture
  • ✅ Returns LangChain CallbackHandler for LangGraph tracing
  • ⚠️ Gracefully warns if credentials missing

3. ma.testing.PytestHarness

Bridge from LangGraph apps to EvalProtocol evaluations:

from my_agent import graph
import mahsm as ma

harness = ma.testing.PytestHarness(graph=graph)

@ma.testing.evaluation_test(
    data_loaders=harness.data_loaders,
    rollout_processor=harness.rollout_processor,
    completion_params=[{"model": "openai/gpt-4o-mini"}],
)
async def test_quality(row):
    return await ma.testing.aha_judge(row, judge_model="openai/gpt-4o", rubric="...")

🛠️ Development

Setup

git clone https://github.com/chimera-research/mahsm.git
cd mahsm
pip install -e .

Run Tests

python tests/test_core.py              # Unit tests
python tests/test_graph_integration.py  # Integration tests

CI/CD

  • GitHub Actions: Runs tests on push/PR (Python 3.10-3.12, Linux/Mac/Windows)
  • PyPI Publishing: Automatic via GitHub Releases or manual workflow dispatch

📊 Architecture

┌─────────────────────────────────────────────────────────────┐
│                        mahsm Framework                      │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌──────────────┐      ┌──────────────┐                   │
│  │   DSPy       │─────▶│  @dspy_node  │                   │
│  │   Modules    │      │  Decorator   │                   │
│  └──────────────┘      └──────┬───────┘                   │
│                                │                            │
│                                ▼                            │
│  ┌──────────────────────────────────────────────────┐     │
│  │          LangGraph StateGraph                    │     │
│  │  ┌─────┐   ┌─────┐   ┌─────┐   ┌─────┐         │     │
│  │  │Node1│──▶│Node2│──▶│Node3│──▶│End  │         │     │
│  │  └─────┘   └─────┘   └─────┘   └─────┘         │     │
│  └──────────────────────┬───────────────────────────┘     │
│                         │                                  │
│         ┌───────────────┴───────────────┐                 │
│         │                                │                 │
│         ▼                                ▼                 │
│  ┌──────────────┐              ┌──────────────┐           │
│  │   Langfuse   │              │ EvalProtocol │           │
│  │   Tracing    │              │  Evaluation  │           │
│  └──────────────┘              └──────────────┘           │
│                                                             │
└─────────────────────────────────────────────────────────────┘

🤝 Contributing

We welcome contributions! Please:

  1. Check existing issues or create one
  2. Fork the repo and create a feature branch
  3. Write tests for new functionality
  4. Submit a PR with clear description

📄 License

MIT License - see LICENSE for details.


🌟 Acknowledgments

mahsm stands on the shoulders of giants:


📬 Contact


Built with ❤️ by Chimera Research

⭐ Star us on GitHub

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

mahsm-0.1.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

mahsm-0.1.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file mahsm-0.1.1.tar.gz.

File metadata

  • Download URL: mahsm-0.1.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mahsm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6ea7a0d6261798fc5b59d37b203f7f5cd704365c51e163772ab2fbee4a6ac37d
MD5 28cf6a648e326b3d3ce7c078256a0abd
BLAKE2b-256 0a7874b9d1078c950fa3f5b91c64dfa6966a3991d4e0083eb09a0735c5b818a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mahsm-0.1.1.tar.gz:

Publisher: publish.yml on chimera-research/mahsm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mahsm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mahsm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mahsm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f20d7731d1857661c7a04b0433c5baa12814d26c78ff365de88ce5e276616133
MD5 8684561ed29ebe9f42a51359147d0e3a
BLAKE2b-256 ee007c745baf15906fce720ca04768f737d31a75af1aaaf36a67bda062b4bb94

See more details on using hashes here.

Provenance

The following attestation bundles were made for mahsm-0.1.1-py3-none-any.whl:

Publisher: publish.yml on chimera-research/mahsm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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