[GH-ISSUE #280] Allow customization of Anthropic prompt caching middleware options #240

Closed
opened 2026-06-05 17:21:13 -04:00 by yindo · 2 comments
Owner

Originally created by @JadenKim-dev on GitHub (Mar 5, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/280

Summary

Currently, createDeepAgent uses anthropicPromptCachingMiddleware with hardcoded default options:

anthropicPromptCachingMiddleware({
  unsupportedModelBehavior: "ignore",
})

This doesn't allow users to customize important caching parameters like:

  • ttl (cache duration: "5m" or "1h")
  • minMessagesToCache (minimum messages before caching applies)
  • enableCaching (toggle caching on/off)

Proposed Solution

Add a new optional parameter to CreateDeepAgentParams to expose prompt caching configuration:

interface CreateDeepAgentParams {
  // ... existing params
  promptCaching?: {
    enableCaching?: boolean;
    ttl?: "5m" | "1h";
    minMessagesToCache?: number;
    unsupportedModelBehavior?: "ignore" | "warn" | "raise";
  };
}

Example usage:

const agent = createDeepAgent({
  model: "claude-sonnet-4-5-20250929",
  promptCaching: {
    ttl: "1h",  // Cache for 1 hour instead of default 5 minutes
    minMessagesToCache: 5  // Only cache after 5 messages
  }
});

Use Cases

  1. Long-running conversations: Users may want ttl: "1h" for extended sessions
  2. Short system prompts: Users with minimal context may want higher minMessagesToCache to avoid unnecessary API overhead
  3. Cost optimization: Fine-tuning these parameters can significantly impact API costs for different usage patterns
  4. Development/testing: Ability to disable caching entirely during development
Originally created by @JadenKim-dev on GitHub (Mar 5, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/280 ## Summary Currently, `createDeepAgent` uses `anthropicPromptCachingMiddleware` with hardcoded default options: ```typescript anthropicPromptCachingMiddleware({ unsupportedModelBehavior: "ignore", }) ``` This doesn't allow users to customize important caching parameters like: - `ttl` (cache duration: "5m" or "1h") - `minMessagesToCache` (minimum messages before caching applies) - `enableCaching` (toggle caching on/off) ## Proposed Solution Add a new optional parameter to `CreateDeepAgentParams` to expose prompt caching configuration: ```typescript interface CreateDeepAgentParams { // ... existing params promptCaching?: { enableCaching?: boolean; ttl?: "5m" | "1h"; minMessagesToCache?: number; unsupportedModelBehavior?: "ignore" | "warn" | "raise"; }; } ``` Example usage: ```typescript const agent = createDeepAgent({ model: "claude-sonnet-4-5-20250929", promptCaching: { ttl: "1h", // Cache for 1 hour instead of default 5 minutes minMessagesToCache: 5 // Only cache after 5 messages } }); ``` ## Use Cases 1. **Long-running conversations**: Users may want `ttl: "1h"` for extended sessions 2. **Short system prompts**: Users with minimal context may want higher `minMessagesToCache` to avoid unnecessary API overhead 3. **Cost optimization**: Fine-tuning these parameters can significantly impact API costs for different usage patterns 4. **Development/testing**: Ability to disable caching entirely during development
yindo closed this issue 2026-06-05 17:21:13 -04:00
Author
Owner

@JadenKim-dev commented on GitHub (Mar 5, 2026):

I'd be happy to implement this feature if the proposed interface looks good to the maintainers. Please let me know if you'd like me to open a PR for this.

<!-- gh-comment-id:4008589521 --> @JadenKim-dev commented on GitHub (Mar 5, 2026): I'd be happy to implement this feature if the proposed interface looks good to the maintainers. Please let me know if you'd like me to open a PR for this.
Author
Owner

@hntrl commented on GitHub (Jun 2, 2026):

Hey @JadenKim-dev! Sorry for the delay in response.

I think its a little bit awkward for us to introduce anthropic specific prompt caching parameters because deepagents is a harness that is intended to work across models. Our current guidance is if you want to bring this level of configurability, you should leverage profiles to explicitly remove + add middleware.

Closing in light of that. We are starting to think a fair bit about how we want a lower level configuration api to look for deepagents

<!-- gh-comment-id:4603826152 --> @hntrl commented on GitHub (Jun 2, 2026): Hey @JadenKim-dev! Sorry for the delay in response. I think its a little bit awkward for us to introduce anthropic specific prompt caching parameters because deepagents is a harness that is intended to work across models. Our current guidance is if you want to bring this level of configurability, you should leverage [profiles](https://docs.langchain.com/oss/javascript/deepagents/profiles) to explicitly remove + add middleware. Closing in light of that. We are starting to think a fair bit about how we want a lower level configuration api to look for deepagents
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#240