Skip to content

Conversation

@dbschmigelski
Copy link
Member

Description

This is the followup to feat(models): add SystemContentBlock support for provider-agnostic caching #1112. We are now processing SystemContentBlocks within LiteLLM which enables prompt caching.

Note, this will be breaking for some integrators. At launch, it was a mistake to not apply kwargs to all public methods. This leaves us with two options.

  1. Forever maintain these with branching logic
  2. Make a one time breaking change to apply kwargs everywhere

For the sake of maintainability, and the expectation that very few people will be extending the OpenAIModel as a base model, the proposal in this PR is to add kwargs to the existing public methods. This will enable future changes in a backwards compatible way.

Related Issues

#937

Documentation PR

To come after the merge.

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • [todo] I have updated the documentation accordingly
  • [todo] I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions github-actions bot added the size/m label Nov 5, 2025
@dbschmigelski dbschmigelski changed the title Litellm caching feat(models): allow SystemContentBlocks in LiteLLMModel Nov 5, 2025
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 90.74074% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/models/litellm.py 85.71% 0 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

# Apply cache control to the immediately preceding content block
# for LiteLLM/Anthropic compatibility
if system_content:
system_content[-1]["cache_control"] = {"type": "ephemeral"}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know the other types? What if we set type to block["cachePoint"].get("type", "ephemeral")?

"totalTokens": event["data"].total_tokens,
}

# Only LiteLLM over Anthropic supports cache cache write tokens
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "cache cache ..."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants