mainspring
Autonomous motion, precise control.
A Python agent framework whose core has exactly two runtime dependencies: pydantic and httpx.
Everything else — MCP, workflow graphs, session stores, OpenTelemetry, sandboxing, coding tools — is
an opt-in package you can remove without touching the core.
English | 简体中文
Why another agent framework?
Most agent frameworks grow into platforms. mainspring is built around five constraints instead.
| 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, keep the same Agent. Missing capabilities degrade explicitly or fail before the request — never a vendor-side 500. |
| Control is declarative | Turn/token/wall-clock/no-progress budgets, tool allowlists, input and output guardrails, and human-in-the-loop approve → deny → resume are all declaration slots on Agent, not if statements scattered through business code. |
| Isolation is enforced | import-linter contracts make it impossible for the core to import an extra, or for extras to import 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. |
Install
pip install mainspring-agent
The import name stays mainspring — the PyPI name mainspring was already taken by another project.
Optional pieces are separate packages:
pip install "mainspring-agent[config]" # YAML config loader (pyyaml)
pip install mainspring-coding-tools # 14 coding tools + terminal REPL
pip install mainspring-mcp # MCP client (stdio + Streamable HTTP)
pip install mainspring-otel # OpenTelemetry export + replay CLI
Quickstart — no API key
Requires Python ≥ 3.11 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())
To use a cloud model, swap the import and the model name — the agent code does not change:
from mainspring.providers.deepseek import create_model
model = create_model("deepseek-chat") # reads DEEPSEEK_API_KEY
Keys only ever enter 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 .
You get tool cards, diffs, and a y/n approval prompt for every write or shell command. Three
commands to start: /new (new session), /resume (continue an interrupted run), /model <name>
(switch model). Read-only tools run without asking; side effects do not.
HTTP server and web UI
The application layer is delivered 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: 25.2 KB. Reproduce with uv run python benchmarks/bench_run.py
(no API, no network).
Documentation
- Quickstart — from zero to a working agent
- Core concepts — the six layers of the framework
- Tool design — writing tools a model actually calls correctly
- HITL and approvals — human approval for dangerous operations
- Model switching and fallback
- API reference
The docs site is built with mkdocs: uv sync --group docs && uv run mkdocs serve.
Development
uv sync # installs the workspace, extras, and dev tools
uv run pytest # 700+ tests
Quality gates that must pass on every commit:
uv run ruff check . && uv run ruff format --check .
uv run mypy # strict, core + server
uv run lint-imports # dependency-direction contracts
uv run pytest # coverage gate: 85% (currently 100% on core)
CI runs with no network access and no API keys: recorded fixtures replay the model calls. The same property holds locally — every example runs offline by default.
More detail in CONTRIBUTING.md.
Status
v0.1.0. The framework, extensions, CLI, server, and web client are usable today. 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 CHANGELOG.md for what changed, and the roadmap for the compatibility policy.
Contributing
Issues and pull requests are welcome. Please read CONTRIBUTING.md and CODE_OF_CONDUCT.md first. Security reports go through SECURITY.md, not public issues.
License
MIT — see LICENSE.
Metadata
Release files for mainspring-agent 0.1.0
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.0.tar.gz | 410.8 kB | With provenance | Details for mainspring_agent-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mainspring_agent-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for mainspring_agent-0.1.0-py3-none-any.whl |
Total release size: 562.8 kB
Release files / mainspring_agent-0.1.0.tar.gz
| Download URL | mainspring_agent-0.1.0.tar.gz |
|---|---|
| Size | 410.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7728f2de617961873931172ac7f74bed712cea93f464af9e2541c5d0022fbe6f
|
|
BLAKE2b-256 checksum How to use checksums |
21ca9aa9a52ebdda459c348847f0618142d3c50f97a6c30262f94c88711b4767
|
| 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.0-py3-none-any.whl
| Download URL | mainspring_agent-0.1.0-py3-none-any.whl |
|---|---|
| Size | 152.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21d49878d3ca8bc6c2abb32fcd7271669fdf5e37cec792e37b15f091db46b2f6
|
|
BLAKE2b-256 checksum How to use checksums |
c22dd87285790fe61ea030534b42ecc70d898a4b62d3c3d885ed290a4d9799e9
|
| 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.0
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.0.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.