Skip to main content

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
import os

# 1. Configure DSPy
lm = dspy.LM('openai/gpt-4o-mini', api_key=os.getenv("OPENAI_API_KEY"))
dspy.configure(lm=lm)

# 2. Enable tracing
handler = ma.tracing.init()

# 3. Define agent state
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.tracing.init() - One-Line Tracing

handler = ma.tracing.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

Metadata

Release files for mahsm 0.2.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 mahsm 0.2.2
File Size Uploaded
mahsm-0.2.2.tar.gz 36.9 kB Details

Built distribution (wheel)

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

Total release size: 54.2 kB

Release files / mahsm-0.2.2.tar.gz

Download URL mahsm-0.2.2.tar.gz
Size 36.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5c4e9754285efbc1470bdb00f4e40478f7d8505cc2187cc2a17a302167c4906e
BLAKE2b-256 checksum
How to use checksums
c05615a9fe69689f2ffeedc11784d9c568d65cafbb936b884f18ee6b9db65577
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2025.

Transparency log

Release files / mahsm-0.2.2-py3-none-any.whl

Download URL mahsm-0.2.2-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09673a4687646216bad3a64e586d07066b5d1cb893b4dcd5829c64410b0a5974
BLAKE2b-256 checksum
How to use checksums
0d92df5afcd24748ddfbc31ca4db6872d4bc3faebe07422e7276faf89aca0295
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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