[PR #614] [MERGED] feat: Anthropic cache control = with token count updates #1461

Closed
opened 2026-02-16 10:23:00 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-official-plugins/pull/614
Author: @mendybraun
Created: 3/30/2025
Status: Merged
Merged: 4/1/2025
Merged by: @crazywoola

Base: mainHead: anthropic-cache_control


📝 Commits (3)

  • eb253ef Update models/anthropic from upstream
  • 4d2fa67 Added cache control for antropic models
  • 1b5ca15 Merge branch 'main' into anthropic-cache_control

📊 Changes

2 files changed (+190 additions, -51 deletions)

View changed files

📝 models/anthropic/manifest.yaml (+1 -1)
📝 models/anthropic/models/llm/llm.py (+189 -50)

📄 Description

Related Issue or Context

https://github.com/langgenius/dify/issues/7382

Type of Change

  • Bug Fix (non-breaking change which fixes an Issue)
  • New Feature (non-breaking change which adds Functionality)
  • Breaking Change (fix or feature that may cause existing Functionality to not work as expected)
  • Documentation Update
  • Code Refactoring
  • Other

Version Control (if applicable)

  • Version bumped in Manifest.yaml (top-level Version field, not in Meta section)

Test Evidence (if applicable)

Important

Visual Proof is required for Bug Fixes, New Features, and Breaking Changes:

Screenshots or Video/GIF:

Add a <cache> tag at the end of the system/user message and it will add a "cache_control": {"type": "ephemeral"} to that block.
the prompt token count will be updated to reflect the discounted amount (or added amount for cache read).

Without any <cache> tag:
image

Same prompt text with <cache> tag (cache write = 25% more)

image

Same prompt text with <cache> tag (cache read = 90% less)

image
see the difference in token count...

Note

For Non-LLM Models Changes:

  • Bug Fixes:
    • Show the Fix working
  • New Features:
    • Demonstrate the Functionality
  • Breaking Changes:
    • Show both Old and New Behavior

For LLM Models Changes:
LLM Models Test Example

  • Bug Fixes:
    • Show the Fix working with Example Inputs/Outputs
  • New Features:
    • Demonstrate the Functionality with Example Inputs/Outputs
  • Breaking Changes (requires comprehensive Testing):
    • Conversation & Interaction:
      • Message Flow Handling (System Messages and User→Assistant Turn-taking)
      • Tool Interaction Flow (Multi-round Usage and Output Handling if applicable)
    • Input/Output Handling:
      • Multimodal Input Handling (Images, PDFs, Audio, Video if applicable)
      • Multimodal Output Generation (Images, Audio, Video if applicable)
      • Structured Output Format (if applicable)
    • Metrics:
      • Token Consumption Metrics
    • Others:
      • e.g., Reasoning Process for Claude 3.7 Sonnet, Grounding for Gemini (if applicable)

Environment Verification

Important

At least one environment must be tested.

Local Deployment Environment

Local Deployment Dify Version: 1.1.2
  • Changes tested in an Isolated Environment that matches Production Configuration
  • No Cached Data influenced the Test Results

SaaS Environment

  • Testing performed on cloud.dify.ai

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-official-plugins/pull/614 **Author:** [@mendybraun](https://github.com/mendybraun) **Created:** 3/30/2025 **Status:** ✅ Merged **Merged:** 4/1/2025 **Merged by:** [@crazywoola](https://github.com/crazywoola) **Base:** `main` ← **Head:** `anthropic-cache_control` --- ### 📝 Commits (3) - [`eb253ef`](https://github.com/langgenius/dify-official-plugins/commit/eb253ef9108984eb1da635ffd0786c401a7bcc8a) Update models/anthropic from upstream - [`4d2fa67`](https://github.com/langgenius/dify-official-plugins/commit/4d2fa67b18da1a07274c9936501d0a7053e55bc9) Added cache control for antropic models - [`1b5ca15`](https://github.com/langgenius/dify-official-plugins/commit/1b5ca15e0162c7d8ee4348071128981b10893442) Merge branch 'main' into anthropic-cache_control ### 📊 Changes **2 files changed** (+190 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `models/anthropic/manifest.yaml` (+1 -1) 📝 `models/anthropic/models/llm/llm.py` (+189 -50) </details> ### 📄 Description ## Related Issue or Context https://github.com/langgenius/dify/issues/7382 ## Type of Change <!-- Put an `x` in all the boxes that apply --> - [ ] Bug Fix (non-breaking change which fixes an Issue) - [x] New Feature (non-breaking change which adds Functionality) - [ ] Breaking Change (fix or feature that may cause existing Functionality to not work as expected) - [ ] Documentation Update - [ ] Code Refactoring - [ ] Other ## Version Control (if applicable) - [x] Version bumped in Manifest.yaml (top-level `Version` field, not in Meta section) <!-- Version format: MAJOR.MINOR.PATCH - MAJOR (0.x.x): Reserved for Major Releases with widespread Breaking Changes - MINOR (x.0.x): For New Features or limited Breaking Changes - PATCH (x.x.0): For backwards-compatible Bug Fixes and minor Improvements - Note: Each version component (MAJOR, MINOR, PATCH) can be 2 digits, e.g., 10.11.22 --> ## Test Evidence (if applicable) > [!IMPORTANT] > Visual Proof is required for Bug Fixes, New Features, and Breaking Changes: ### Screenshots or Video/GIF: Add a `<cache>` tag at the end of the `system`/`user` message and it will add a `"cache_control": {"type": "ephemeral"}` to that block. the prompt token count will be updated to reflect the discounted amount (or added amount for cache read). <!-- Provide your evidence here --> **Without any `<cache>` tag:** ![image](https://github.com/user-attachments/assets/c616d4ee-17a5-453f-8d8e-350877f953ad) ### Same prompt text with `<cache>` tag (cache write = 25% more) ![image](https://github.com/user-attachments/assets/f7345cb2-aca7-4e9b-b147-ad5160b9a7e1) ### Same prompt text with `<cache>` tag (cache read = 90% less) ![image](https://github.com/user-attachments/assets/576e5673-87b5-4886-a92f-abfd52b40d0c) see the difference in token count... > [!NOTE] > For Non-LLM Models Changes: > - **Bug Fixes**: > - [ ] Show the Fix working > - **New Features**: > - [ ] Demonstrate the Functionality > - **Breaking Changes**: > - [ ] Show both Old and New Behavior > > For LLM Models Changes: > [LLM Models Test Example](https://github.com/langgenius/dify-official-plugins/blob/main/.assets/test-examples/llm-plugin-tests/llm_test_example.md) > - **Bug Fixes**: > - [ ] Show the Fix working with Example Inputs/Outputs > - **New Features**: > - [x] Demonstrate the Functionality with Example Inputs/Outputs > - **Breaking Changes** (requires comprehensive Testing): > - **Conversation & Interaction**: > - [ ] Message Flow Handling (System Messages and User→Assistant Turn-taking) > - [ ] Tool Interaction Flow (Multi-round Usage and Output Handling if applicable) > - **Input/Output Handling**: > - [ ] Multimodal Input Handling (Images, PDFs, Audio, Video if applicable) > - [ ] Multimodal Output Generation (Images, Audio, Video if applicable) > - [ ] Structured Output Format (if applicable) > - **Metrics**: > - [x] Token Consumption Metrics > - **Others**: > - [ ] e.g., Reasoning Process for Claude 3.7 Sonnet, Grounding for Gemini (if applicable) ### Environment Verification > [!IMPORTANT] > At least one environment must be tested. #### Local Deployment Environment ##### Local Deployment Dify Version: 1.1.2 - [x] Changes tested in an Isolated Environment that matches Production Configuration <!-- - Python virtual env matching Manifest.yaml & requirements.txt - No breaking changes in Dify that may affect the testing result --> - [ ] No Cached Data influenced the Test Results #### SaaS Environment - [ ] Testing performed on cloud.dify.ai --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 10:23:00 -05:00
yindo closed this issue 2026-02-16 10:23:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#1461