Skip to content

[BUG] cache read/write usage not exported as string when it is zero #971

@alesanfra

Description

@alesanfra

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

1.10.0

Python Version

3.12.11

Operating System

macOS 15.7.1

Installation Method

pip

Steps to Reproduce

agent = Agent(
    ...
    model=BedrockModel(
        ...
        cache_prompt="default",
        cache_tools="default",
    )
)

Expected Behavior

{
    "gen_ai.usage.prompt_tokens": "177"
    "gen_ai.usage.input_tokens": "177"
    "gen_ai.usage.completion_tokens": "233"
    "gen_ai.usage.output_tokens": "233"
    "gen_ai.usage.total_tokens": "9944"
    "gen_ai.usage.cache_read_input_tokens": "9534"
    "gen_ai.usage.cache_write_input_tokens": "0"
}

Actual Behavior

{
    "gen_ai.usage.prompt_tokens": "177"
    "gen_ai.usage.input_tokens": "177"
    "gen_ai.usage.completion_tokens": "233"
    "gen_ai.usage.output_tokens": "233"
    "gen_ai.usage.total_tokens": "9944"
    "gen_ai.usage.cache_read_input_tokens": "9534"
    "gen_ai.usage.cache_write_input_tokens": {
        intValue: 0
    }
}

Additional Context

I discovered the issue analyzing the traces with Langfuse:

Image

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions