Dev

How to Enable Prompt Caching with the AgentCore Harness

Explaining how to forcibly enable prompt caching in the AWS Bedrock AgentCore harness by modifying the code to address the default disabled state.

5 min read Reviewed & edited by the SINGULISM Editorial Team

How to Enable Prompt Caching with the AgentCore Harness
Photo by Oberon Copeland @veryinformed.com on Unsplash

Amazon Bedrock’s agent development framework, “AgentCore,” has been found to have an issue where prompt caching is disabled. An article published by Qiita user moritalous on July 18, 2026, presented a specific workaround for this issue. The method involves exporting the AgentCore harness to runtime and making direct code modifications to forcibly enable caching.

Prompt caching is a feature that reduces response time and API costs by caching the repetitive portions of prompts sent to LLMs. This feature is especially beneficial for agent-based applications where system prompts or tool definitions tend to be lengthy. While the Strands Agents framework allows relatively easy activation of prompt caching in conjunction with Claude, the default configuration of the AgentCore harness leaves this feature disabled.

The Issue at Hand

AgentCore is an integrated framework for developing and deploying agents on Amazon Bedrock. The GUI-based “AgentCore harness” offers intuitive operability, but the code generated internally does not support prompt caching. According to tests conducted by moritalous, even if the code exported from the harness is executed as-is, caching will not function.

The crux of the issue lies in the Python code exported from the harness, specifically in the model loading section of the Strands Agents. By default, no caching settings are configured, necessitating manual modifications.

Detailed Resolution Steps

Creating and Exporting the Harness

First, create a harness in the AgentCore console. The quick create option is sufficient. After creation, click “Show steps to export code” displayed on the screen. The export instructions provided here will include the ARN of the harness.

Install the AgentCore CLI (version 0.24.1).

npm install -g @aws/agentcore

Next, create an AgentCore project. This step is not listed in the export instructions but is a necessary preparation.

agentcore create myharness

When prompted with “What would you like to build?” select “Skip.” After navigating to the project directory, export the harness.

cd myharness
agentcore export harness --arn arn:aws:bedrock-agentcore:us-east-1:123456789012:harness/harness_adhn1-V8gQRoqV92

If the export is successful, Strands Agents-based Python code will be generated in the app/harness_adhn1Agent/ directory.

Modifying the Code

The file to be modified is app/harness_adhn1Agent/model/load.py. Add caching settings when instantiating the model client in this file.

First, add CacheConfig to the import statements.

from strands.models.bedrock import BedrockModel, CacheConfig

Next, add parameters to the BedrockModel creation in the load_model function.

return BedrockModel(
 model_id="global.anthropic.claude-sonnet-4-6",
 cache_tools="default",
 cache_config=CacheConfig(strategy="auto"),
)

Here, cache_tools="default" enables caching for tool definitions, and CacheConfig(strategy="auto") applies an automatic strategy for caching. This ensures that prompt caching works during communication with Claude Sonnet 4.6.

Deploying and Verifying Operation

After making the modifications, deploy the code using the following command:

agentcore deploy

One crucial point to note is that the modified code cannot be deployed back into the original AgentCore harness; it must be deployed as an AgentCore runtime. When you execute multiple conversations in the runtime environment, you can confirm that prompt caching is functioning correctly.

Differences Between Harness and Runtime

This workaround highlights an architectural challenge in the AgentCore framework. The AgentCore harness excels in its integration with Step Functions, making it suitable for use cases where agents are invoked within workflows. On the other hand, the AgentCore runtime can be configured behind an API gateway and offers the advantage of adding guardrails (safety mechanisms).

Moritalous notes a desire for these features to be unified. The different feature sets between the harness and runtime add complexity to user decision-making. Furthermore, the realization of prompt caching is constrained by the necessity of transitioning to the runtime.

Insights for Practical Deployment

This workaround serves as valuable knowledge for teams considering the adoption of AgentCore. Particularly for agents that operate with long system prompts or numerous tool definitions, the presence or absence of prompt caching directly impacts costs and latency. Without caching, the need to resend a large portion of the prompt for each interaction can significantly increase response times and proportionally inflate API costs.

The official Strands Agents documentation explains the activation of prompt caching with Claude in relatively simple steps. The fact that AgentCore’s exported code does not apply these settings by default highlights a maturity gap in the framework.

Editorial Opinion

In the short term, this workaround is likely to be widely shared among AgentCore users. Until AWS officially addresses this issue, modifying the code will remain a necessary task. For teams focused on cost optimization, the presence or absence of this workaround could be a key factor in deciding whether to adopt AgentCore.

AgentCore is still a rapidly evolving platform, and the lack of prompt caching support represents a typical challenge faced by early adopters. From a long-term perspective, the direction of feature integration between the harness and runtime is worth watching. Users currently face a binary choice between the “harness that can be invoked from Step Functions” and the “runtime that can have guardrails.” If a unified platform incorporating the advantages of both were to emerge, AgentCore’s practical value would significantly increase.

How quickly AWS incorporates community feedback into its product will be a critical differentiator relative to competitors like Google Vertex AI Agent Builder and Azure AI Agent Service. As an editorial team, we would like to raise the following points for discussion.

References

Source: Qiita

Comments

← Back to Home