[Bug]: Bedrock LLM prompt_tokens leaves out cache read/write tokens
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
Start in the Bedrock provider at BedrockCompletion._track_token_usage_internal, named in the issue, and compare its accounting with the Anthropic provider’s cache token handling. Check the mocked Converse usage example and the existing token usage tests; done means prompt_tokens includes input, cache read, and cache write, cached_prompt_tokens and cache_creation_tokens track their respective fields, and the totals add up when consistent.
索引モデルが issue の本文から書いたものです。
説明
Description
When using the native Bedrock provider with prompt caching, UsageMetrics.prompt_tokens undercounts billed input. Bedrock Converse reports usage.inputTokens as the non-cached input only; cache hits and writes are separate (cacheReadInputTokens / cacheWriteInputTokens). AWS documents total input as the sum of those three, and totalTokens already includes them.
BedrockCompletion._track_token_usage_internal currently does:
self._token_usage["prompt_tokens"] += input_tokens # inputTokens only
self._token_usage["cached_prompt_tokens"] += cached_tokens # read only
# cache writes never recorded; prompt+completion != totalTokens
The Anthropic provider in this repo already folds cache_read_input_tokens + cache_creation_input_tokens into input_tokens before tracking.
Steps to Reproduce
Offline with a mocked converse response (no live AWS needed):
from unittest.mock import patch
from crewai.llm import LLM
llm = LLM(model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0")
usage = {
"inputTokens": 10,
"outputTokens": 5,
"totalTokens": 18906,
"cacheReadInputTokens": 18891,
"cacheWriteInputTokens": 0,
}
with patch.object(llm._client, "converse") as mock_converse:
mock_converse.return_value = {
"output": {"message": {"role": "assistant", "content": [{"text": "OK"}]}},
"usage": usage,
"stopReason": "end_turn",
}
llm.call("Hello")
print(llm._token_usage)
# main: prompt_tokens=10, cached_prompt_tokens=18891, total_tokens=18906
# expected: prompt_tokens=18901 (== 10+18891), prompt+completion == total
Same gap on the first (cache-write) turn: cacheWriteInputTokens is ignored entirely (cache_creation_tokens stays 0).
Expected behavior
prompt_tokens == inputTokens + cacheRead + cacheWritecached_prompt_tokens == cacheReadcache_creation_tokens == cacheWriteprompt_tokens + completion_tokens == total_tokens(whentotalTokensis consistent)
Actual behavior
prompt_tokens= non-cachedinputTokensonly- cache writes not tracked
prompt + completion != totalon cached turns
CrewAI version
main @ 7abc196 (2026-11-06)
Additional context
HUMAN: I hit this while checking Bedrock prompt-caching metrics in crewAI: on a cache-hit turn, prompt_tokens stayed at the non-cached input count while total_tokens already included the cache read, so the parts didn't add up. Looking at the Converse usage fields and how the Anthropic path in this repo folds cache read/write into input, Bedrock wasn't doing the same. Happy to take a fix once this is confirmed.
- 主要言語
- Python
- スター
- 60.6k
- フォーク
- 9.1k
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 214
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
crewAIInc/crewAI のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
feature-request
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
crewAIInc/crewAI#9200 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
crewAIInc/crewAI#9132 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] Scrape tools reject the documented cookies mapping and drop cookies when the URL is passed at runtime対応中かも @Luckyou-d が 5 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
[BUG] OpenAI-compatible embedding model alias breaks embedder construction対応中かも @gokay-ai が 11 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
crewAIInc/crewAI#8761 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
crewAIInc/crewAI の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
bigbio/sdrf-pipelines#372 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
521xueweihan/HelloGitHub#4297 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
aws-samples/sample-per-model-bedrock#822 ·
メンテナーはふだん 1 日以内に返信
-
area:study-data p2-high ready-for-agent type:chore
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
fderuiter/deruiter.dev#3706 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
awslabs/visual-asset-management-system#1234 ·
メンテナーはふだん 1 日以内に返信