mirascope

MirascopeMIT活跃维护

用 Python 和 TypeScript 统一调用各家大模型,把提示词、工具调用和结构化输出封装成轻量模块,避免被重型框架绑死。

The LLM Anti-Framework

v2.8.2发布于 2026-10-22 22:54 UTC1,535star155fork同步于 2026-11-10 17:50 UTC

怎么上手

由 README 提炼,执行前请确认
uv add "mirascope[all]"
硬件要求按 README 说明

README 未说明;调用的是云端 LLM API,本地无需 GPU 或显存

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用统一接口调用各家前沿 LLM 的 Python 库,号称反框架,轻量不绑架你的代码

用 Python 和 TypeScript 统一调用各家大模型,把提示词、工具调用和结构化输出封装成轻量模块,避免被重型框架绑死。

核心能力

  • 用 @llm.call 装饰器把函数直接变成 LLM 调用
  • 传 format=Pydantic 模型即可拿到结构化输出并 parse
  • 用 @llm.tool 定义工具,循环 resume 执行工具调用构建 Agent
  • 模型用 provider/model 字符串指定,如 anthropic/claude-sonnet-4-5
  • 同一仓库同时提供 Python 与 TypeScript 实现

容易踩的坑

需要自备对应厂商的 API Key 才能实际调用模型;示例默认用 anthropic/claude-sonnet-4-5,换模型要改 provider/model 字符串;本地开发网站需另装 Bun

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.8.2
  1. v2.8.2最新正式版2026-10-22 · 2026-10-22 22:54 UTC

    Fixes

    • Keep OpenAI streamed tool calls separate when providers omit or reuse their index; handle failed and incomplete Responses streams, refusals, and strict structured output more reliably.
    • Improve Anthropic error and finish-reason mapping, and prevent a tool cache breakpoint from leaking into later requests.
    • Correct Google streamed usage totals and tool-use prompt token accounting; handle empty tool arguments and image refusals.
    • Refresh MiniMax Flash model suggestions and improve context-length finish reasons in instrumentation.

    Thanks to @pcbeingused333 and everyone who contributed reviews and fixes.

    TypeScript remains an alpha release (2.8.2-alpha.0).

  2. v2.8.12026-10-20 · 2026-10-20 19:06 UTC
    查看更新说明

    Fixes

    • Correct Anthropic streamed input token totals to include cache reads and writes.
    • Keep cumulative and partial stream usage events accurate in Python and TypeScript.

    Thanks to @pcbeingused333 for reporting and starting the fix in #2911.

    TypeScript remains an alpha release (2.8.1-alpha.0).

  3. v2.8.02026-10-20 · 2026-10-20 18:40 UTC
    查看更新说明

    What's Changed

    • Add API Route as an OpenAI-compatible provider in Python and the TypeScript alpha.
    • Support adaptive thinking and effort for newer Claude models in both SDKs.
    • Keep parallel tool calls separate when OpenAI-compatible streams omit a tool-call index, in both SDKs.
    • Preserve Google streaming finish reasons and token usage from chunks without content, including usage-only chunks without a candidate.
    • Preserve Annotated and Field constraints in tool schemas without changing callable parameter names.

    Python is released as 2.8.0; TypeScript remains an alpha at 2.8.0-alpha.0 on npm's alpha tag.

    Full Changelog: https://github.com/Mirascope/mirascope/compare/v2.7.0...v2.8.0

  4. v2.7.02026-10-19 · 2026-10-19 19:19 UTC
    查看更新说明

    What's Changed

    • Resume active development of the TypeScript alpha and align its supported providers with Python, including Anthropic beta support, Atlas Cloud, Cheaper Inference, MiniMax, Requesty, and xAI.
    • Add TypeScript MCP tool pagination and validation of LLM-generated arguments for interface-based tools.
    • Keep MLX documented as a Python-only provider.
    • Release Python 2.7.0 and TypeScript 2.7.0-alpha.0. The TypeScript package remains an alpha release on npm's alpha dist-tag.

    Full Changelog: https://github.com/Mirascope/mirascope/compare/v2.6.0...v2.7.0

  5. v2.6.02026-10-19 · 2026-10-19 16:53 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/Mirascope/mirascope/compare/v2.5.0...v2.6.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Mirascope

    Welcome to Mirascope, which allows you to use any frontier LLM with one unified interface.

    Quick Start

    Install Mirascope:

    uv add "mirascope[all]"
    

    Call LLMs with a Decorator

    from mirascope import llm
    
    
    @llm.call("anthropic/claude-sonnet-4-5")
    def recommend_book(genre: str):
        return f"Recommend a {genre} book."
    
    
    response = recommend_book("fantasy")
    print(response.text())
    

    Get Structured Output

    from pydantic import BaseModel
    from mirascope import llm
    
    
    class Book(BaseModel):
        title: str
        author: str
    
    
    @llm.call("anthropic/claude-sonnet-4-5", format=Book)
    def recommend_book(genre: str):
        return f"Recommend a {genre} book."
    
    
    book = recommend_book("fantasy").parse()
    print(f"{book.title} by {book.author}")
    

    Build an Agent with Tools

    from pydantic import BaseModel
    from mirascope import llm
    
    
    class Book(BaseModel):
        title: str
        author: str
    
    
    @llm.tool
    def get_available_books(genre: str) -> list[Book]:
        """Get available books in the library by genre."""
        return [Book(title="The Name of the Wind", author="Patrick Rothfuss")]
    
    
    @llm.call("anthropic/claude-sonnet-4-5", tools=[get_available_books], format=Book)
    def librarian(request: str):
        return f"You are a librarian. Help the user: {request}"
    
    
    response = librarian("I want a fantasy book")
    while response.tool_calls:
        response = response.resume(response.execute_tools())
    book = response.parse()
    print(f"Recommending: {book.title} by {book.author}")
    

    For streaming, async, multi-turn conversations, and more, see the full documentation.

    Monorepo Structure

    This project is structured as a monorepo, that conceptually divides into four parts:

    • python/ contains the Python implementation, and examples (in python/examples)
    • typescript/ contains the Typescript implementation, and examples (in typescript/examples)
    • website/ contains the marketing website (docs, blog, landing page)
    • docs/ contains the unified cross-language documentation (in docs/content), as well as configuration needed to build the docs

    For detailed information about the codebase structure, architecture, and design decisions, see STRUCTURE.md.

    Developing the site

    Use bun run website:dev to launch the dev server.

    Note that Bun must be installed.

    CI and local testing

    We currently have four CI jobs:

    • codespell: Checks for common misspellings including python, typescript, and docs repos
    • python-lint: Linting and typechecking for Python code
    • typescript-lint: Linting and typechecking for Typescript code
    • cloudflare docs build: Builds and previews the documentation site

    You can run bun run ci in the root directory to run all CI checks locally. If adding new checks to GitHub CI, please also add it to the ci script in root package.json as well.

    Versioning

    Mirascope uses Semantic Versioning.

    License

    This project is licensed under the MIT License.