Skip to content

Add cache directive to Bedrock system prompt via providerOptions#663

Open
timko212 wants to merge 1 commit into
laravel:0.xfrom
timko212:bedrock-cache-directive
Open

Add cache directive to Bedrock system prompt via providerOptions#663
timko212 wants to merge 1 commit into
laravel:0.xfrom
timko212:bedrock-cache-directive

Conversation

@timko212
Copy link
Copy Markdown

@timko212 timko212 commented May 27, 2026

Follow-up to #634, which was closed because it overlapped with how Anthropic already works.

Bedrock is the part that's actually missing. The Converse API doesn't accept cache_control on the system string; it wants an extra cachePoint block appended to the system list, which isn't something a generic passthrough can do. So there's no clean way to enable Bedrock prompt caching from an agent today.

This PR adds a cache directive that BedrockTextGateway recognises and turns into the cachePoint block. From the agent side it looks like this:

public function providerOptions(Lab|string \$provider): array
{
    return \$provider === Lab::Bedrock
        ? ['cache' => [['target' => 'system']]]
        : [];
}

The directive is consumed by the gateway and stripped before the rest of providerOptions is merged into the Converse parameters, so AWS never sees the cache key.

The new test (`tests/Feature/Providers/Bedrock/CacheControlTest.php`) checks three things: the marker shows up when the directive is set, it doesn't leak through to AWS, and the system block stays untouched when no directive is set. There's also a small `capturingBedrockClient` helper in `BedrockHelpers` so the test can read the exact Converse payload.

Anthropic already accepts cache_control through providerOptions and it flows
straight into the request body. Bedrock needs the marker emitted as a separate
cachePoint block in the system list, so providerOptions alone is not enough.

This adds a 'cache' directive that the Bedrock Converse gateway translates into
a cachePoint marker on the system blocks:

    return ['cache' => [['target' => 'system']]];

The directive is stripped before the remaining providerOptions are merged into
the Converse parameters, so it never reaches the AWS API.
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.

2 participants