Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Pydantic AI integration does not record reasoning tokens

未关闭 适合新手
#7,876 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
observability

调研方向

从 pydantic_ai/spans/utils.py 中的 _set_usage_data 入手,追踪它如何从 RequestUsage 读取 token 使用量。检查现有的 OpenAI 集成和相关测试,了解 reasoning-token 属性的约定。完成标准是:Pydantic AI spans 从 details["reasoning_tokens"] 记录 reasoning tokens,并且有测试验证该属性。

由索引模型根据 Issue 内容生成。

描述

Improvement Python Spans
Version

2.71.0 (master @ 6a4eb20), pydantic-ai 2.x

Steps to Reproduce

Run a Pydantic AI agent on a reasoning model (e.g. gpt-oss-20b), so the response usage has reasoning tokens. Pydantic AI stores them in RequestUsage.details["reasoning_tokens"].

Expected Result

The chat span has gen_ai.usage.output_tokens.reasoning, like the OpenAI integration.

Actual Result

No reasoning attribute. _set_usage_data (pydantic_ai/spans/utils.py#L49-L87) reads input, cache, output and total tokens but not details. On live calls the provider reported 9, 14 and 16 reasoning tokens and the spans had none.

I have a small fix with a test and can open a PR if that works for you.

主要语言
Python
星标
2.2k
派生
680
平均合并
1 天 3 小时
30 天内合并 PR
264

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

getsentry/sentry-python 的其他 Issue

查看 getsentry/sentry-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。