mainspring
mainspring is an open-source Python agent framework whose core depends on exactly two runtime
packages: pydantic and httpx. MCP, workflow graphs, session stores, OpenTelemetry, sandboxing,
and coding tools ship as separate packages that can be removed without touching the core.
English | 简体中文
Project status
mainspring is at v0.1.1 and in developer preview. The framework, extensions, CLI, server, and web
client are usable today, but APIs may change between minor versions while the design settles.
Known gap: cloud smoke tests for eight hosted providers still need to be re-run with real API keys. The locally reachable Ollama path and all zero-key replay paths are verified. See the release notes and the release and compatibility policy.
Design constraints
The core is kept deliberately small. Five constraints define what belongs in it:
| Constraint | What it means |
|---|---|
| Two dependencies | pip install mainspring-agent pulls in pydantic and httpx. Provider SDKs are never imported; every vendor is spoken to over plain HTTP. |
| One switch for models | 13 dialects: an OpenAI-compatible base plus native Anthropic and Gemini. Change provider and model; the Agent object does not change. Unsupported capabilities fail before the request instead of surfacing as a vendor error. |
| Control is declarative | Turn, token, wall-clock, and no-progress budgets; tool allowlists; input and output guardrails; and human-in-the-loop approve/deny/resume are declaration slots on Agent, not if statements scattered through business code. |
| Isolation is enforced | import-linter contracts prevent the core from importing an extra and prevent extras from importing each other. CI uninstalls each extra in turn and the core suite stays green. |
| Observable and replayable | Every step emits a RunEvent. The console sink is built in; the OTel extra turns the same stream into a span tree. Recorded JSONL replays into an identical event sequence. |
Run
From PyPI
pip install mainspring-agent
The import name is mainspring; the PyPI distribution is mainspring-agent because the name
mainspring was already taken by another project.
Optional packages are installed separately:
pip install "mainspring-agent[config]" # YAML config loader (pyyaml)
pip install mainspring-coding-tools # 14 coding tools and a terminal REPL
pip install mainspring-mcp # MCP client (stdio and Streamable HTTP)
pip install mainspring-otel # OpenTelemetry export and replay CLI
Quickstart without an API key
Requires Python 3.11 or newer and Ollama:
ollama pull qwen3:14b
from mainspring import Agent, Runner, tool
from mainspring.providers.ollama import create_model
@tool
def add(a: int, b: int) -> int:
"""Add two integers."""
return a + b
agent = Agent(
name="assistant",
instructions="Use tools when they help. Keep answers short.",
model=create_model("qwen3:14b"), # local, zero cost
tools=[add],
)
result = Runner().run_sync(agent, "What is 2 + 3?")
print(result.status, result.finish_reason, result.message.text_content())
Cloud models use the same agent code; only the import and model name change:
from mainspring.providers.deepseek import create_model
model = create_model("deepseek-chat") # reads DEEPSEEK_API_KEY
Keys enter only through environment variables. They are never written to YAML files, event payloads, or traces.
Terminal coding agent
pip install mainspring-coding-tools
mainspring-coder --root .
Every write or shell command produces a tool card, a unified diff where applicable, and a y/n
approval prompt. Read-only tools run without asking. Three commands start the session: /new,
/resume, and /model <name>.
From source: server and web UI
The application layer ships as artifacts rather than PyPI packages, so this part runs from a clone:
git clone https://github.com/chyong/mainspring
cd mainspring
uv sync
uv run uvicorn mainspring_server.app:app --port 8900
The server exposes an AG-UI event stream (SSE) plus REST endpoints for sessions and approvals. A
React web client and a Tauri desktop shell live under apps/.
Repository layout
core/ # framework (directory is core/, import name is mainspring)
extras/ # 11 independent packages: mcp, workflow, session-{sqlite,redis,postgres},
# otel, memory, sandbox, coding-tools, eval-online, langfuse
apps/ # application layer: mainspring-server (HTTP), web (React), desktop (Tauri)
examples/ # runnable examples, all offline-capable by default
docs/ # mkdocs documentation site
mainspring.yaml # config layer: model, storage, budgets
Performance
Framework overhead is measured separately from model latency (local qwen3:14b, 2026-10-31):
| Scenario | End-to-end p50 | Framework overhead p50 |
|---|---|---|
| Single-step run (synthetic model) | 0.044 ms | 0.039 ms |
| Tool step (one tool call) | 0.315 ms | 0.301 ms |
| Replayed support-ticket run (hooks + 2 tools + structured output) | 0.958 ms | — |
Live run (qwen3:14b) |
18,334 ms | 1.41 ms (< 0.01%) |
tracemalloc peak per run is 25.2 KB. Reproduce with uv run python benchmarks/bench_run.py; the
benchmark needs no API key and no network.
Documentation
- Quickstart — from zero to a working agent
- Core concepts — the six layers of the framework
- Tool design — writing tools a model calls correctly
- HITL and approvals — human approval for dangerous operations
- Model switching and fallback
- API reference
The documentation site is built with mkdocs: uv sync --group docs && uv run mkdocs serve.
Development
uv sync # installs the workspace, extras, and development tools
uv run pytest # 700+ tests
These checks must pass on every commit:
uv run ruff check . && uv run ruff format --check .
uv run mypy # strict, core and server
uv run lint-imports # dependency-direction contracts
uv run pytest # coverage gate: 85% (core is at 100%)
CI runs with no network access and no API keys: recorded fixtures replay the model calls. Every example runs offline by default for the same reason.
More detail is in CONTRIBUTING.md.
Community and support
- Questions, ideas, and bug reports: GitHub Discussions and Issues.
- Security reports: follow SECURITY.md instead of opening a public issue.
- Contributions: read CONTRIBUTING.md and CODE_OF_CONDUCT.md first.
Citation
@misc{mainspring2026,
title={mainspring: A two-dependency Python agent framework},
author={mainspring contributors},
year={2026},
publisher={GitHub},
howpublished={\url{https://github.com/chyong/mainspring}}
}
License
MIT — see LICENSE.
Metadata
Release files for mainspring-agent 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mainspring_agent-0.1.1.tar.gz | 413.0 kB | With provenance | Details for mainspring_agent-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mainspring_agent-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for mainspring_agent-0.1.1-py3-none-any.whl |
Total release size: 565.2 kB
Release files / mainspring_agent-0.1.1.tar.gz
| Download URL | mainspring_agent-0.1.1.tar.gz |
|---|---|
| Size | 413.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7ae396fb01976fea5eb53e7cd5452a261e31f9830c936b4ff43f614ba2b6760
|
|
BLAKE2b-256 checksum How to use checksums |
d1f330481f5f7ccc49a6ca41eb798fe7eb5f226207cdb0a6d04c902f4a1b2441
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 6, 2026.
Transparency logRelease files / mainspring_agent-0.1.1-py3-none-any.whl
| Download URL | mainspring_agent-0.1.1-py3-none-any.whl |
|---|---|
| Size | 152.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
79fd373c78d355b54ff71aeb9cd6c17a7b063e2e2b3d2f73b47f86838e697f4c
|
|
BLAKE2b-256 checksum How to use checksums |
462317b9a8e7dca4e2e6eb66632911d5788fee9ba7a5e7971ed3fa05f0642893
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 6, 2026.
Transparency logSecurity for mainspring-agent 0.1.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mainspring_agent-0.1.1.tar.gz
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 Dec 6, 2026.
Transparency logA 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.