[BUG] A cachePoint block in message history makes OllamaModel, LlamaCppModel, WriterModel and LlamaAPIModel raise TypeError; GeminiModel sends an empty parts list
Human Overview
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
SDK Language
Python
Strands Version
main at 0943408
Language Runtime Version
Python 3.13.16
Operating System
Linux
Installation Method
git clone
Steps to Reproduce
Run the script in Additional Context with the SDK and the provider extras installed (python repro.py). It makes no network call: the four failing providers point at a closed local port and raise before connecting, and Gemini gets a stub client.
The script gives each provider an Agent whose messages contain a user-placed {"cachePoint": {"type": "default"}} block, as a session recorded with BedrockModel or AnthropicModel can, and sends a follow-up. For Gemini it uses a history where one user message holds only the cache point, and prints the contents of the request.
Expected Behavior
A provider that has no cache points skips the block with a warning, as OpenAIModel, OpenAIResponsesModel and MistralModel do. A message left with no content is not sent.
Actual Behavior
Four providers raise while formatting the request, before any I/O. GeminiModel skips the block but still sends the message, with an empty parts list:
OllamaModel: TypeError: content_type=<cachePoint> | unsupported type
LlamaCppModel: TypeError: content_type=<cachePoint> | unsupported type
WriterModel: TypeError: content_type=<cachePoint> | unsupported type
LlamaAPIModel: TypeError: content_type=<cachePoint> | unsupported type
count=<1> | cachePoint content block is not supported by Gemini | skipping
GeminiModel contents: [{'parts': [{'text': 'long reference document'}], 'role': 'user'}, {'parts': [], 'role': 'user'}, {'parts': [{'text': 'question?'}], 'role': 'user'}]
Every call fails once such a history is used with one of the four providers, so a stored session with cache points cannot be moved to them. No cache is involved: the request is never built.
Possible Solution
Skip cachePoint blocks, with the same "not supported | skipping" warning the other providers log, in the four formatters listed below. In GeminiModel._format_request_content, do not append a Content whose parts list is empty. Not tested.
Additional Context
Code locations, who can trigger it, extended output
Code locations (main at 0943408)
strands-py/src/strands/models/ollama.py:178,strands-py/src/strands/models/llamacpp.py:306,strands-py/src/strands/models/writer.py:142and:168,strands-py/src/strands/models/llamaapi.py:157: theraise TypeError(... unsupported type)fallthrough that acachePointblock reaches.strands-py/src/strands/models/gemini.py:334-336skips the block;:339-344appends theContenteven whenpartsis empty.- Providers that skip the block:
strands-py/src/strands/models/openai.py:479-480,strands-py/src/strands/models/openai_responses.py:827-828,strands-py/src/strands/models/mistral.py:276-277.
Who can trigger it
Deterministic. The application developer or a stored session supplies the history: a user-placed cachePoint is valid content for Bedrock and Anthropic and is persisted with the messages. The failure appears when that history is used with one of the four providers, for example after switching the model of a restored session or in a fallback to a local model.
Limits of what was verified
- The script was also run with socket connections blocked; the output is the same, so the
TypeErroris raised before any connection attempt. - Whether Gemini rejects a
Contentwith emptypartswas not checked against the API. A message that holds only a cache point is an edge case; the[document, cachePoint, question]shape is the common one. - TypeScript has none of these four providers. Its OpenAI (Chat Completions and Responses) and Google adapters drop the block and the cachePoint-only message at main 0943408 (request capture).
Script
"""A cachePoint block in history: four providers raise TypeError, Gemini sends an empty parts list. No network."""
import warnings
from types import SimpleNamespace as NS
from strands import Agent
from strands.models.gemini import GeminiModel
from strands.models.llamaapi import LlamaAPIModel
from strands.models.llamacpp import LlamaCppModel
from strands.models.ollama import OllamaModel
from strands.models.writer import WriterModel
warnings.simplefilter("ignore")
CLOSED = "http://127.0.0.1:9" # nothing listens here; the error below is raised before any connection attempt
DOCUMENT, CACHE_POINT = {"text": "long reference document"}, {"cachePoint": {"type": "default"}}
# History as a Bedrock or Anthropic session stores it: the user placed a cache point after a long document.
HISTORY = [
{"role": "user", "content": [DOCUMENT, CACHE_POINT, {"text": "question?"}]},
{"role": "assistant", "content": [{"text": "answer"}]},
]
MODELS = {
"OllamaModel": OllamaModel(CLOSED, model_id="llama3"),
"LlamaCppModel": LlamaCppModel(base_url=CLOSED),
"WriterModel": WriterModel(client_args={"api_key": "x", "base_url": CLOSED}, model_id="palmyra-x5"),
"LlamaAPIModel": LlamaAPIModel(client_args={"api_key": "x", "base_url": CLOSED}, model_id="Llama-4-Maverick"),
}
for name, model in MODELS.items():
try:
Agent(model=model, messages=list(HISTORY), callback_handler=None)("follow-up")
print(f"{name}: no error")
except Exception as error:
print(f"{name}: {type(error).__name__}: {error}")
sent = []
async def generate_content_stream(**request): # stub for the Gemini client: records the request, replies "ok"
sent.append(request)
async def stream():
part = NS(text="ok", thought=False, function_call=None, thought_signature=None)
yield NS(candidates=[NS(content=NS(parts=[part]), finish_reason="STOP")], usage_metadata=None)
return stream()
client = NS(aio=NS(models=NS(generate_content_stream=generate_content_stream)))
history = [{"role": "user", "content": [DOCUMENT]}, {"role": "user", "content": [CACHE_POINT]}]
Agent(model=GeminiModel(client=client, model_id="gemini-2.5-flash"), messages=history, callback_handler=None)("question?")
print("GeminiModel contents:", sent[0]["contents"])
Related Issues
#3642, #1140
Hi, I'd like to take this one if it's still free.
Looked at main: OpenAIModel (openai.py:479) and MistralModel (mistral.py:276) already skip cachePoint and log a warning. My plan is to do the same in OllamaModel, LlamaCppModel, WriterModel and LlamaAPIModel, which raise a TypeError today. For GeminiModel I'd stop appending a message when its parts end up empty (gemini.py:339).
For tests I'd add one parametrized test over the four providers with a history that has a cachePoint block, checking the request still gets built and the warning is logged. Plus a Gemini case with a message that only holds a cache point.
Does that approach work for you, or would you prefer a shared helper?
Disclosure, per your AI usage policy: I work with an AI coding agent (Claude Code) to trace this and draft the change. Everything goes through review before it goes out, and I'm responsible for it.