Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Sep 5, 2025

Summary

Fixes compatibility issue with Vertex SDK where system prompts were incorrectly converted to array format when caching is enabled.

Problem

The Vertex SDK does not support array-form system prompts with cache_control, unlike the regular Anthropic SDK. When caching was enabled, the system prompt was being converted from a plain string to an array with cache metadata, causing compatibility issues.

Solution

  • Keep system prompt as plain string for Vertex SDK compatibility
  • Apply cache_control only to message content blocks
  • System prompt cannot be cached directly due to SDK limitations

Changes

  • Modified src/api/providers/anthropic-vertex.ts to maintain system prompt as string
  • Updated tests in src/api/providers/__tests__/anthropic-vertex.spec.ts to match corrected behavior
  • All 18 tests passing successfully

Root Cause

Issue introduced in commit a3d8c0e (April 28, 2025) as part of vertex/gemini prompt caching feature.

Fixes compatibility with @anthropic-ai/vertex-sdk v0.7.0 and newer versions.


Important

Fixes Vertex SDK compatibility by keeping system prompts as plain strings and applying cache_control only to message content blocks.

  • Behavior:
    • System prompts remain as plain strings in createMessage() and completePrompt() in anthropic-vertex.ts for Vertex SDK compatibility.
    • cache_control applied only to message content blocks, not system prompts.
  • Tests:
    • Updated anthropic-vertex.spec.ts to reflect system prompt as string and verify cache control application.
    • All 18 tests pass successfully.
  • Root Cause:
    • Issue introduced in commit a3d8c0e (April 28, 2025) related to prompt caching feature.
    • Fixes compatibility with @anthropic-ai/vertex-sdk v0.7.0 and newer.

This description was created by Ellipsis for d98bd8f. You can customize this summary. It will automatically update as commits are pushed.

The Vertex SDK does not support array-form system prompts with cache_control,
unlike the regular Anthropic SDK. This fix ensures the system parameter remains
a plain string, applying cache_control only to message content blocks.

- Modified system prompt handling to maintain string format
- Updated tests to match corrected behavior
- Maintains caching functionality for message blocks only

Fixes compatibility issue introduced in commit a3d8c0e
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Sep 5, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Sep 5, 2025
@daniel-lxs daniel-lxs marked this pull request as draft September 5, 2025 16:38
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Sep 5, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Thank you for this important fix! The changes correctly address the Vertex SDK compatibility issue by keeping system prompts as plain strings. The solution is clean, well-documented, and includes comprehensive test coverage.

The fix properly:
✅ Maintains system prompts as plain strings for Vertex SDK compatibility
✅ Updates the caching strategy documentation
✅ Includes thorough test coverage
✅ Preserves caching functionality for message content

Great work on identifying and fixing this compatibility issue!

* 1. Maximum of 4 blocks can have cache_control
* 2. Only text blocks can be cached (images and other content types cannot)
* 3. Cache control can only be applied to user messages, not assistant messages
* 4. System prompt must remain as a plain string - Vertex SDK does not support array format
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent documentation update! The comment clearly explains the SDK limitation. Would it be worth adding a TODO about potentially re-enabling system prompt caching if future Vertex SDK versions support it? This could help future maintainers understand the limitation is SDK-specific rather than an API constraint.

system: supportsPromptCache
? [{ text: systemPrompt, type: "text" as const, cache_control: { type: "ephemeral" } }]
: systemPrompt,
// System must remain as plain string for Vertex SDK compatibility
Copy link
Contributor

Choose a reason for hiding this comment

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

Good change here. The comment clearly indicates this is for SDK compatibility rather than a design choice.

cache_control: { type: "ephemeral" },
},
],
system: "You are a helpful assistant", // System remains as plain string
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make the comment more explicit about why the system remains as a plain string? Something like: // System remains as plain string for Vertex SDK compatibility

cache_control: { type: "ephemeral" },
},
],
system: "You are a helpful assistant", // System remains as plain string
Copy link
Contributor

Choose a reason for hiding this comment

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

Same suggestion here - could we be more explicit about the SDK compatibility requirement in the comment?

@daniel-lxs
Copy link
Member Author

#7697

@daniel-lxs daniel-lxs closed this Sep 5, 2025
@github-project-automation github-project-automation bot moved this from PR [Draft / In Progress] to Done in Roo Code Roadmap Sep 5, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Draft / In Progress size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants