[Bug]: Bedrock LLM prompt_tokens leaves out cache read/write tokens
I maintainer di solito rispondono entro 1 giorno
@lalith0407 ci sta già lavorando.
Dal 6/11/2026.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- python
- Ambito
- backend-api-design
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 60.6k
- Fork
- 9.1k
- Merge medio
- 1g 4h
- PR unite (30g)
- 214
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di crewAIInc/crewAI
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
Feature request: GoldenDirectiveTool (harmonic relationship score, full vs cropped reporting)Apertafeature-request
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
crewAIInc/crewAI#9200 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[FEATURE] Docs: ApifyActorsTool example with a typed-input ActorForse già presa @johnisanerd l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
crewAIInc/crewAI#9132 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG] Scrape tools reject the documented cookies mapping and drop cookies when the URL is passed at runtimeForse già presa @Luckyou-d l’ha presa 6 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
[BUG] OpenAI-compatible embedding model alias breaks embedder constructionForse già presa @gokay-ai l’ha presa 12 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
crewAIInc/crewAI#8761 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di crewAIInc/crewAI
Issue simili
-
area: providers/aws priority: p2 size: S type: bug type: testing
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
finos/open-resource-broker#851 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
sandialabs/atlas-ui-3#1196 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ShaftHQ/SHAFT_ENGINE#7902 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: GraphML export writes invalid XML when a value contains a control character (e.g. form feed)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
topoteretes/cognee#6646 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
DOI-USGS/pywatershed#428 ·