Skip to main content

mainspring-langfuse:trace + score 面板外挂(可选依赖)

什么时候才需要它(先读这张表再装)

现状 建议
只有工程师跑评估、看报告 不要装。报告 + 快照 + 夹具回放已经覆盖判定、门禁、回归对比
PM / QA 要看「agent 到底做了什么」的面板 装。自托管 Langfuse,trace 自动入库,数据不出网
跨团队协作查线上现场 / 看分数趋势 装。trace 按 session_id(run_id)串树,score 按 trace_id 回写

装上它不会让评估变准:judge、门禁、端态预言机全部在离线 harness 里; 面板只是「看现场 + 收纳分数」。

装法与版本矩阵

# SDK 永不进默认依赖(CI 禁网不装,卸载后核心套件全绿)
uv add "mainspring-langfuse[sdk]"

# 本地 v4 栈:宿主端口 3001,数据主体在项目目录 langfuse-v4-data/(不入库);
# ClickHouse 因 Windows 绑定挂载无法 rename part,独用 Linux 命名卷
docker compose -f docker-compose.langfuse-v4.yml up -d
SDK 服务端最低版本 本外挂
Python v2 / v3 v2 / v3.63+ 不支持(0.2.0 起移除旧适配器)
Python v4 v3.63.0+ 支持(start_observation / propagate_attributes)
Python v5 v4.59.0+ 支持,推荐(create_score / flush 未变,关停走 shutdown)

先升服务端,再升 SDK。v3 只收到 2027-01-31 的安全补丁;v4 已是 GA。 旧 v2 栈与 docker-compose.langfuse.yml 已删除,新代码一律打 3001 的 v4 栈。

跑法

from mainspring import Runner
from mainspring_langfuse import langfuse_sink

with langfuse_sink(host="http://127.0.0.1:3001") as sink:  # 退出自动 flush + shutdown
    runner = Runner(sink=sink)
    result = await runner.run(agent, prompt)
    trace_id = sink.trace_id_for_run(result.run_id)  # 收尾后仍可查
    sink.score_run(
        result.run_id,
        name="judge_quality",
        value=4,
        comment=verdict.reason,
        score_id=f"{case_id}:judge",  # 幂等键:重跑覆盖同一条
    )

完整可跑示例(本地 v4 栈):

uv run python examples/langfuse_eval_loop.py

score 契约

固定五个分面(SCORE_NAMES),名字进面板即成列,改名等于丢历史:

name 类型 来源
judge_quality NUMERIC 0~5 evals.scorers.judge 的 verdict
deterministic_pass BOOLEAN tool_names / finish_reason / contains
end_state_pass BOOLEAN env 端态预言机 diff
pass_k NUMERIC expect.pass_k(回放模式标忽略,不伪造通过率)
cost_tokens NUMERIC Usage.input_tokens + output_tokens
  • score_id 默认 {run_id}:{name};重跑覆盖同一条,不在面板堆假样本。
  • 缺 trace_id 时 score_run 显式报 LookupError,不静默丢分。
  • 分数不与门禁耦合:CI 仍跑 python -m evals.run_eval --mode replay,Langfuse 只收结果。

设计

  • client 注入:LangfuseSink 只依赖七方法客户面 (start_trace / start_span / end / trace_id / create_score / flush / close), SDK 适配器懒加载——CI 不装 SDK 照常全绿,映射逻辑用 Fake client 回归;
  • trace_id 自造:适配器用 trace_context 注入 32 位 hex,emit 结束即可拿到出口, 不依赖服务端回包;run_finished 只清活跃句柄,trace_id 留档供写分/反哺;
  • 先脱敏再上面板:payload 过 core redact_payload,密钥 / SecretStr 不进 metadata;
  • 树不断:审批恢复等首个事件缺 run_started 的场景自动补根 trace;
  • metadata 压平:v4+ 只收 str→str 且 value ≤200 字符,外挂先截断,不让 SDK 边警告边丢字段;
  • 版本面收敛在 _SdkAdapter 一个类:v4/v5 同一组手动观测入口,SDK 升级只改这里。

Metadata

Release files for mainspring-langfuse 0.1.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 mainspring-langfuse 0.1.2
File Size Uploaded Provenance Actions
mainspring_langfuse-0.1.2.tar.gz 8.7 kB With provenance Details for mainspring_langfuse-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mainspring-langfuse 0.1.2
File Interpreter ABI Platform Actions
mainspring_langfuse-0.1.2-py3-none-any.whl Python 3 none any Details for mainspring_langfuse-0.1.2-py3-none-any.whl

Total release size: 18.9 kB

Release files / mainspring_langfuse-0.1.2.tar.gz

Download URL mainspring_langfuse-0.1.2.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
52fef1b73f71a353246722b5e453635bf3ed58d42525339a335d02a13ef3840d
BLAKE2b-256 checksum
How to use checksums
175f2b4625e0e818ca82252f426f8d8052857e8fc356264744ea8559c658c92e
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 log

Release files / mainspring_langfuse-0.1.2-py3-none-any.whl

Download URL mainspring_langfuse-0.1.2-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00903eec9259a2922e01c8b76f2907938cdfc51e90f5f1228fc22e5528a79a9a
BLAKE2b-256 checksum
How to use checksums
56e64003a0bcdd5b122ed1d9c53230f0b084f36e1cc918b46bc04ac111cc491f
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 log

Security for mainspring-langfuse 0.1.2

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.

Select from 2 files

Attestation for mainspring_langfuse-0.1.2.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 log

A 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.

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