Skip to content

fix(sdk): respect disabled prompt caching - #4559

Open
zora-zi wants to merge 1 commit into
OpenHands:mainfrom
zora-zi:fix/issue-4511-cache-control
Open

fix(sdk): respect disabled prompt caching#4559
zora-zi wants to merge 1 commit into
OpenHands:mainfrom
zora-zi:fix/issue-4511-cache-control

Conversation

@zora-zi

@zora-zi zora-zi commented Aug 20, 2026

Copy link
Copy Markdown

HUMAN:

I reviewed the changes and test results, and confirmed that disabled prompt caching no longer emits cache_control markers in tool-call messages.


AGENT:

This draft was prepared with AI assistance. The human author reviewed the code changes and verification results before submission.

Why

Message.to_chat_dict() selects list serialization when function calling is enabled. That path previously did not pass cache_enabled to _list_serializer(), so content marked with cache_prompt=True could still emit cache_control even when the call-level caching switch was disabled.

Summary

  • Pass the call-level cache_enabled setting into list serialization.
  • Remove content-level cache markers when prompt caching is disabled.
  • Add regression coverage for both tool and user messages with function calling enabled.

Issue Number

#4511

How to Test

Run the focused message serialization tests:

uv run pytest tests/sdk/llm/test_message.py -q

Result on this branch:

32 passed in 0.05s

I also invoked the public Message.to_chat_dict() API for tool and user messages with cache_prompt=True, cache_enabled=False, and function_calling_enabled=True. The serialized output was:

{"content": [{"text": "Tool response", "type": "text"}], "name": "test_tool", "role": "tool", "tool_call_id": "call_123"}
{"content": [{"text": "User request", "type": "text"}], "role": "user"}
PASS: cache_control is absent when prompt caching is disabled

Video/Screenshots

Not applicable; this is a message serialization fix. The end-to-end serialized output is included above.

Design Doc

Not needed for this focused bug fix.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

PR #4512 already addresses the same issue. This draft is intentionally transparent about that overlap and is being submitted to validate this independently tested implementation through the project's CI and review workflow. It adds regression coverage for both tool-role and user-role messages.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

Copy link
Copy Markdown
Contributor

📁 PR Artifacts Notice

This PR contains a .pr/ directory with temporary PR-specific documents. Because this is a fork PR, the directory will be automatically removed from main immediately after merge.

@zora-zi
zora-zi marked this pull request as ready for review August 20, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant