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
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 (excludesself) - ✅ 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
CallbackHandlerfor 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:
- Check existing issues or create one
- Fork the repo and create a feature branch
- Write tests for new functionality
- Submit a PR with clear description
📄 License
MIT License - see LICENSE for details.
🌟 Acknowledgments
mahsm stands on the shoulders of giants:
- DSPy by Stanford NLP
- LangGraph by LangChain
- Langfuse by Langfuse Team
- EvalProtocol by Fireworks AI
📬 Contact
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Twitter: @chimera_research (if applicable)
Built with ❤️ by Chimera Research
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mahsm-0.2.2.tar.gz.
File metadata
- Download URL: mahsm-0.2.2.tar.gz
- Upload date:
- Size: 36.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c4e9754285efbc1470bdb00f4e40478f7d8505cc2187cc2a17a302167c4906e
|
|
| MD5 |
0672790e0e4349b917354d087ef557be
|
|
| BLAKE2b-256 |
c05615a9fe69689f2ffeedc11784d9c568d65cafbb936b884f18ee6b9db65577
|
Provenance
The following attestation bundles were made for mahsm-0.2.2.tar.gz:
Publisher:
publish.yml on chimera-research/mahsm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mahsm-0.2.2.tar.gz -
Subject digest:
5c4e9754285efbc1470bdb00f4e40478f7d8505cc2187cc2a17a302167c4906e - Sigstore transparency entry: 719584860
- Sigstore integration time:
-
Permalink:
chimera-research/mahsm@517a27057df545af3fdb06a03dd1c6068205aa0a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/chimera-research
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@517a27057df545af3fdb06a03dd1c6068205aa0a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mahsm-0.2.2-py3-none-any.whl.
File metadata
- Download URL: mahsm-0.2.2-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09673a4687646216bad3a64e586d07066b5d1cb893b4dcd5829c64410b0a5974
|
|
| MD5 |
382460c5194d9a99857f5634a6ed9a4a
|
|
| BLAKE2b-256 |
0d92df5afcd24748ddfbc31ca4db6872d4bc3faebe07422e7276faf89aca0295
|
Provenance
The following attestation bundles were made for mahsm-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on chimera-research/mahsm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mahsm-0.2.2-py3-none-any.whl -
Subject digest:
09673a4687646216bad3a64e586d07066b5d1cb893b4dcd5829c64410b0a5974 - Sigstore transparency entry: 719584864
- Sigstore integration time:
-
Permalink:
chimera-research/mahsm@517a27057df545af3fdb06a03dd1c6068205aa0a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/chimera-research
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@517a27057df545af3fdb06a03dd1c6068205aa0a -
Trigger Event:
workflow_dispatch
-
Statement type: