Forward cache_control from message-level placement in ChatDatabricks - #456
Forward cache_control from message-level placement in ChatDatabricks#456adamgurary wants to merge 1 commit into
Conversation
_convert_message_to_dict built the outbound message from message.content only, so an Anthropic cache_control breakpoint reached the endpoint solely when nested inside a typed content block. A message-level breakpoint (stored by LangChain in additional_kwargs) was dropped silently, so prompt caching never activated for that placement. Forward cache_control from additional_kwargs onto the outbound message dict. Add unit tests for the present and absent cases. Co-authored-by: Isaac Signed-off-by: Adam Gurary <guraryadam@gmail.com>
670d455 to
d9d5216
Compare
|
Hey @fanzeyi and @aravind-segu, this PR fixes a silent drop of message-level |
|
One thing on my side is blocked: the test workflow is waiting on a maintainer to click "Approve and run workflows" (first PR I've opened here, so the runs are sitting at action_required). Once that runs, CI should be green. The two new unit tests cover the present and absent |
|
Hi @fanzeyi @aravind-segu, following up from Aug 3. CI here is gated on a maintainer clicking "Approve and run workflows" in the Actions tab (first-time-contributor fork gate), so all checks are sitting at action_required. Could one of you approve the workflow run so this can get a review? |
Context
This fix came out of a hands-on end-to-end evaluation of building, tracing, and improving a LangGraph agent on Databricks.
Problem: ChatDatabricks drops cache_control unless it is inside a typed content block
ChatDatabricksforwards an Anthropiccache_controlbreakpoint only when it is nested inside a typed content block. A message-level key or anadditional_kwargsplacement is dropped silently, with no error, so prompt caching never activates for those placements.Steps to reproduce
Send the same large static system block three ways through the same
ChatDatabricksclient and check warm-callcache_readper placement:Root cause
_convert_message_to_dict(v0.17.0) builds the outbound message as{"content": message.content}and copies nothing else fromadditional_kwargs. Socache_controlsurvives only when it is nested inside a content block that lives inmessage.content.Fix
_convert_message_to_dictnow forwards a message-levelcache_controlfromadditional_kwargsonto the outbound message dict. The forwarding fires only whencache_controlis present, so the no-breakpoint path is unchanged.Two unit tests cover the present and absent cases.
This is a distinct bug from #446 (token-count inflation when caching is active). This PR addresses the breakpoint being dropped so caching never activates.