trace: the usage a Pi tool reports on its own result is left out of the session's usage
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with tokeneconomizer/trace/pi.py and inspect how pi_session_usage totals assistant messages and session entries; compare its handling with the toolResult usage in the reproduction. Add the reproduced session as a regression case in the relevant tests, then confirm totals include both calls: 150 input tokens, 300 output tokens, 2 requests, and $0.15 cost. A pull request is already open for this issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
tokeneconomizer/trace/pi.py's pi_session_usage adds up the usage of the active branch's assistant messages and its usage, compaction and branch_summary entries, but not the usage on a toolResult message. A Pi tool that calls a model itself reports that usage on its own result: pi-ai's ToolResultMessage has an optional usage, documented as "Usage from the tool execution itself" (packages/ai/src/types.ts), and Pi's own session stats add it to the session's totals (AgentSession.getSessionStats in packages/coding-agent/src/core/agent-session.ts). So a session whose tools made model calls is recorded in the ledger with fewer tokens, requests and less cost than Pi itself reports for it.
Reproduction (offline):
import json, os, tempfile
from tokeneconomizer import trace
u = {"input": 100, "output": 200, "cacheRead": 1000, "cacheWrite": 0, "cost": {"total": 0.1}}
tool = {"input": 50, "output": 100, "cacheRead": 500, "cacheWrite": 0, "cost": {"total": 0.05}}
entries = [
{"type": "session", "version": 3, "id": "s1", "cwd": "/w/acme/widget"},
{"type": "message", "id": "u1", "parentId": None,
"message": {"role": "user", "content": "fix the parser"}},
{"type": "message", "id": "a1", "parentId": "u1", "message": {
"role": "assistant", "usage": u,
"content": [{"type": "toolCall", "id": "c1", "name": "subagent", "arguments": {}}]}},
{"type": "message", "id": "r1", "parentId": "a1", "message": {
"role": "toolResult", "toolCallId": "c1", "toolName": "subagent", "isError": False,
"content": [{"type": "text", "text": "tests/test_parser.py"}], "usage": tool}},
]
p = os.path.join(tempfile.mkdtemp(), "session.jsonl")
open(p, "w").write("\n".join(json.dumps(e) for e in entries) + "\n")
s = trace.pi_session_usage(p)
print({k: s[k] for k in ("input_tokens", "output_tokens", "requests", "cost_usd_vendor")})
Expected: {'input_tokens': 150, 'output_tokens': 300, 'requests': 2, 'cost_usd_vendor': 0.15}, the agent's call and the tool's.
Actual: {'input_tokens': 100, 'output_tokens': 200, 'requests': 1, 'cost_usd_vendor': 0.1}
Upstream main: 747b8016538c13da7ba9d455b89e5e6595bf5294
Python 3.13.18, Linux
- Ngôn ngữ chính
- Python
- Star
- 7.4k
- Fork
- 500
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 123
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/TokenEconomizer
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/TokenEconomizer#360 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
microskills: bundle exec and pnpm exec are recorded as bundle run and pnpm runCó thể đã có người làm @Shizoqua đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
microsoft/TokenEconomizer#344 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
microskills: a command wrapped in bash -lc or zsh -lc is not observedCó thể đã có người làm @Shizoqua đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/TokenEconomizer#343 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
README: state the minimum Python version next to the test instructionsCó thể đã có người làm @rahul05ranjan đã nhận 4 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
microsoft/TokenEconomizer#328 · 3 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
loopguard: a PHPUnit or CTest run is judged without its summary, so a failing run can end a turn greenCó thể đã có người làm @Shizoqua đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
microsoft/TokenEconomizer#353 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/TokenEconomizer
Issue tương tự
-
docs: powerpc not supportedĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
reasons-gate
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
benthomasson/reasons-service#190 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 3 ngày