返回顶部
l

langfuse-trace-loggerLangfuse追踪日志

Log subagent task completions as Langfuse traces for replay, evaluation, and cost analysis. Called during session-wrap Phase 4. Supports backfill, tag-based filtering, and replay-judge integration. Requires Python 3.11 via chatterbox-venv due to pydantic v1 compatibility.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
80
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

langfuse-trace-logger

技能:langfuse-trace-logger

目的: 将子代理任务完成情况记录为 Langfuse 追踪,用于回放、评估和成本分析。
范围: 由 Loki 在每个会话包装(阶段 4)结束时,针对每个重要的子代理完成情况调用。
脚本: /Users/loki/.openclaw/workspace/scripts/langfuse-trace-logger.py



⚠️ 关键:Python 版本

始终使用 ~/.chatterbox-venv/bin/python3(Python 3.11.15)

Langfuse SDK 使用 pydantic v1,与 Python 3.14 不兼容。使用系统 Python(python3)或 pyenv Python(3.14.x)会导致静默失败——没有导入错误,没有异常,追踪只是不会出现在 Langfuse UI 中。这将浪费 30 分钟以上的调试时间。

bash

✅ 正确


~/.chatterbox-venv/bin/python3 scripts/langfuse-trace-logger.py ...

❌ 错误——在 Python 3.14 上静默失败

python3 scripts/langfuse-trace-logger.py ... /Users/loki/.pyenv/versions/3.14.3/bin/python3 scripts/langfuse-trace-logger.py ...

基本调用

bash
~/.chatterbox-venv/bin/python3 /Users/loki/.openclaw/workspace/scripts/langfuse-trace-logger.py \
--session-id $SESSION_ID \
--parent-id agent:main \
--agent kit \
--task task-label-kebab-case \
--model anthropic/claude-sonnet-4-6 \
--status completed \
--input full task prompt given to agent (first 4000 chars)... \
--output what the agent returned or accomplished... \
--duration 278 \
--tokens 16900 \
--project reddi-agent-protocol \
--skills product-tour-capture



追踪模式


字段类型用途备注
--session-id字符串子代理会话键使用实际的子代理会话键——支持血缘追踪
--parent-id
字符串 | 父会话引用 | 除非是嵌套子代理,否则始终为 agent:main |
| --agent | 字符串 | 代理名称 | 小写:kit, archie, sara, finn, quill 等 |
| --task | 字符串 | 任务标签(短横线命名) | 用于回放分组:replay-judge.py --tag task:kit-setup-rebuild |
| --model | 字符串 | 使用的模型 | 例如 anthropic/claude-sonnet-4-6, anthropic/claude-haiku-4-5 |
| --status | 字符串 | 结果 | completed / partial / failed |
| --input | 字符串 | 完整任务提示 | 前 4000 个字符——这是在评估运行中针对其他模型回放的内容 |
| --output | 字符串 | 结果摘要 | 代理的输出/结果——这是评估器评分的内容 |
| --duration | 整数 | 时间(秒) | 用于效率分析和代理路由决策 |
| --tokens | 整数 | 使用的总令牌数 | 用于成本分析和预算治理 |
| --project | 字符串 | 项目标识 | 必须匹配 projects//STATUS.md——支持项目级过滤 |
| --skills | 字符串 | 逗号分隔的技能 | 例如 product-tour-capture,ffmpeg-studio——支持技能有效性过滤 |

标签分类法

记录器会自动从上述字段生成这些标签:

  • - agent:kit——来自 --agent
  • model_family:claude-sonnet——从 --model 派生
  • project:reddi-agent-protocol——来自 --project
  • skill:product-tour-capture——--skills 中每个技能一个标签
  • task:kit-setup-rebuild——来自 --task
  • status:completed——来自 --status

这些标签为回放评估过滤器语法提供支持。



回填模式

用于会话包装被跳过或追踪缺失时的追溯性记录。

幂等性: 使用基于 date+agent+task 哈希的确定性追踪 ID。安全地重新运行——不会创建重复项。

bash

先预览(试运行)


~/.chatterbox-venv/bin/python3 scripts/langfuse-backfill-historical.py \
--from-date 2026-03-24 \
--to-date 2026-03-24 \
--dry-run

然后实际运行

~/.chatterbox-venv/bin/python3 scripts/langfuse-backfill-historical.py \ --from-date 2026-03-24 \ --to-date 2026-03-24

数据源: 回填解析 memory/YYYY-MM-DD.md 文件并提取结构化任务结果块。这就是为什么内存文件中的任务结果块格式必须一致——格式不一致会静默破坏解析。

回填 ID 格式: backfill-YYYY-MM-DD--——确定性,无重复风险。



回放和评估

bash

报告所有 Kit 追踪(过去 30 天)


~/.chatterbox-venv/bin/python3 scripts/replay-judge.py \
--tag agent:kit --report

将所有 Kit 追踪与 Haiku 比较(成本降低分析)

~/.chatterbox-venv/bin/python3 scripts/replay-judge.py \ --tag agent:kit --models claude-haiku-4-5 --judge claude-haiku-4-5 --report

评估特定追踪

~/.chatterbox-venv/bin/python3 scripts/replay-judge.py \ --trace-id backfill-2026-03-24-kit-setup-rebuild \ --models claude-haiku-4-5 --judge claude-haiku-4-5

按项目过滤

~/.chatterbox-venv/bin/python3 scripts/replay-judge.py \ --tag project:reddi-agent-protocol --report

按技能过滤

~/.chatterbox-venv/bin/python3 scripts/replay-judge.py \ --tag skill:product-tour-capture --report

验证追踪是否出现

记录后,在 Langfuse UI 中验证:http://localhost:3100

或以编程方式检查:

bash
~/.chatterbox-venv/bin/python3 -c
import subprocess
sk = subprocess.run(
[op, read, op://OpenClaw/Langfuse (Local)/credential],
capture_output=True, text=True
).stdout.strip()
from langfuse import Langfuse
lf = Langfuse(publickey=pk-lf-openclaw-local, secretkey=sk, host=http://localhost:3100)
traces = lf.client.trace.list(limit=5)
[print(t.name, t.id[:12]) for t in traces.data]

预期输出:最后 5 个追踪名称 + 截断的 ID。如果为空,则是 Python 版本问题(参见上面的警告)。



Langfuse 连接详情


设置
UIhttp://localhost:3100
公钥
pk-lf-openclaw-local |
| 密钥 | op://OpenClaw/Langfuse (Local)/credential(1Password) |
| 也在 1Password 中 | op://OpenClaw/Langfuse (Local)/Secret Key |
| Docker | 始终运行(守护进程服务) |


何时调用此技能

此技能在会话包装剧本(playbooks/session-wrap/PLAYBOOK.md)的阶段 4(追踪)期间调用。

每个重要的子代理完成时调用一次。 使用阶段 1(内存文件)中写入的任务结果块中的数据。不要从内存中重建——读取你刚刚写入的内容。

记录的最低阈值: 任何产生了可交付成果(写入文件、调用 API、生成分析)的子代理运行。跳过:简单查找、单行工具调用、没有输出的失败尝试。



故障排除


症状原因修复
追踪未出现在 UI 中Python 版本错误使用 ~/.chatterbox-venv/bin/python3
无输出,无错误
相同——Python 3.14 p

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 langfuse-trace-logger-1775965621 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 langfuse-trace-logger-1775965621 技能

通过命令行安装

skillhub install langfuse-trace-logger-1775965621

下载

⬇ 下载 langfuse-trace-logger v1.0.0(免费)

文件大小: 4 KB | 发布时间: 2026-4-13 10:48

v1.0.0 最新 2026-4-13 10:48
New skill: Langfuse trace logging and observability for agent pipelines

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部