[PR #1268] [MERGED] refract: anthropic claude prompt caching #1807

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

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-official-plugins/pull/1268
Author: @fdb02983rhy
Created: 7/11/2025
Status: Merged
Merged: 7/12/2025
Merged by: @crazywoola

Base: mainHead: feat-anthropic-claude-prompt-caching


📝 Commits (4)

  • ee0605d feat: anthropic claude prompt caching
  • 49e95c1 Update llm.py
  • d14607d Improve cache block pruning by prioritizing longer text
  • b63e215 Handle base64 source data length in LLM blocks

📊 Changes

11 files changed (+671 additions, -189 deletions)

View changed files

📝 models/anthropic/README.md (+22 -0)
📝 models/anthropic/main.py (+3 -0)
📝 models/anthropic/manifest.yaml (+1 -1)
📝 models/anthropic/models/llm/claude-3-5-haiku-20241022.yaml (+60 -0)
📝 models/anthropic/models/llm/claude-3-5-sonnet-20240620.yaml (+60 -0)
📝 models/anthropic/models/llm/claude-3-5-sonnet-20241022.yaml (+60 -0)
📝 models/anthropic/models/llm/claude-3-7-sonnet-20250219.yaml (+60 -0)
📝 models/anthropic/models/llm/claude-opus-4-20250514.yaml (+60 -0)
📝 models/anthropic/models/llm/claude-sonnet-4-20250514.yaml (+60 -0)
📝 models/anthropic/models/llm/llm.py (+284 -187)
📝 models/anthropic/requirements.txt (+1 -1)

📄 Description

Related Issues or Context

Also handle multi-modal contents in best practice.
CleanShot 2025-07-12 at 12 41 31@2x
https://docs.anthropic.com/en/docs/build-with-claude/pdf-support#:~:text=Send%20your%20first%20PDF%20request

CleanShot 2025-07-12 at 10 52 13@2x

https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching

This PR contains Changes to Non-Plugin

  • Documentation
  • Other

This PR contains Changes to Non-LLM Models Plugin

  • I have Run Comprehensive Tests Relevant to My Changes

This PR contains Changes to LLM Models Plugin

  • My Changes Affect Message Flow Handling (System Messages and User→Assistant Turn-Taking)
CleanShot 2025-07-12 at 10 14 48@2x
  • My Changes Affect Tool Interaction Flow (Multi-Round Usage and Output Handling, for both Agent App and Agent Node)
CleanShot 2025-07-12 at 10 17 15@2x
  • My Changes Affect Multimodal Input Handling (Images, PDFs, Audio, Video, etc.)
CleanShot 2025-07-12 at 10 17 52@2x
  • My Changes Affect Multimodal Output Generation (Images, Audio, Video, etc.)
  • My Changes Affect Structured Output Format (JSON, XML, etc.)
  • My Changes Affect Token Consumption Metrics

Before Caching

CleanShot 2025-07-12 at 10 44 31@2x CleanShot 2025-07-12 at 10 44 37@2x

After Caching

CleanShot 2025-07-12 at 10 45 18@2x CleanShot 2025-07-12 at 10 45 38@2x
  • My Changes Affect Other LLM Functionalities (Reasoning Process, Grounding, Prompt Caching, etc.)

Tool Definitions Caching

CleanShot 2025-07-12 at 10 25 18@2x

Images and Documents Caching

CleanShot 2025-07-12 at 10 28 57@2x

System Message Caching

CleanShot 2025-07-12 at 10 29 27@2x

Tool Use Results Caching

CleanShot 2025-07-12 at 10 30 03@2x

Assistant and User Message Flow Caching

CleanShot 2025-07-12 at 10 42 05@2x
  • Other Changes (Add New Models, Fix Model Parameters etc.)
CleanShot 2025-07-12 at 10 20 13@2x

Version Control (Any Changes to the Plugin Will Require Bumping the Version)

  • I have Bumped Up the Version in Manifest.yaml (Top-Level Version Field, Not in Meta Section)

Dify Plugin SDK Version

  • I have Ensured dify_plugin>=0.3.0,<0.5.0 is in requirements.txt (SDK docs)

Environment Verification (If Any Code Changes)

Local Deployment Environment

  • Dify Version is: , I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration.

SaaS Environment

  • I have Tested My Changes on cloud.dify.ai with a Clean Environment That Matches the Production Configuration

🔄 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/1268 **Author:** [@fdb02983rhy](https://github.com/fdb02983rhy) **Created:** 7/11/2025 **Status:** ✅ Merged **Merged:** 7/12/2025 **Merged by:** [@crazywoola](https://github.com/crazywoola) **Base:** `main` ← **Head:** `feat-anthropic-claude-prompt-caching` --- ### 📝 Commits (4) - [`ee0605d`](https://github.com/langgenius/dify-official-plugins/commit/ee0605d84f1089f1c35656275318d7f75506509e) feat: anthropic claude prompt caching - [`49e95c1`](https://github.com/langgenius/dify-official-plugins/commit/49e95c109a81935c7b099b02393bc00cca71afc6) Update llm.py - [`d14607d`](https://github.com/langgenius/dify-official-plugins/commit/d14607d5ec295d01b2b30bbd33e38245a36036d4) Improve cache block pruning by prioritizing longer text - [`b63e215`](https://github.com/langgenius/dify-official-plugins/commit/b63e215cff54fcd9f529b703d943651be7b91657) Handle base64 source data length in LLM blocks ### 📊 Changes **11 files changed** (+671 additions, -189 deletions) <details> <summary>View changed files</summary> 📝 `models/anthropic/README.md` (+22 -0) 📝 `models/anthropic/main.py` (+3 -0) 📝 `models/anthropic/manifest.yaml` (+1 -1) 📝 `models/anthropic/models/llm/claude-3-5-haiku-20241022.yaml` (+60 -0) 📝 `models/anthropic/models/llm/claude-3-5-sonnet-20240620.yaml` (+60 -0) 📝 `models/anthropic/models/llm/claude-3-5-sonnet-20241022.yaml` (+60 -0) 📝 `models/anthropic/models/llm/claude-3-7-sonnet-20250219.yaml` (+60 -0) 📝 `models/anthropic/models/llm/claude-opus-4-20250514.yaml` (+60 -0) 📝 `models/anthropic/models/llm/claude-sonnet-4-20250514.yaml` (+60 -0) 📝 `models/anthropic/models/llm/llm.py` (+284 -187) 📝 `models/anthropic/requirements.txt` (+1 -1) </details> ### 📄 Description ## Related Issues or Context Also handle multi-modal contents in best practice. <img width="1182" height="182" alt="CleanShot 2025-07-12 at 12 41 31@2x" src="https://github.com/user-attachments/assets/25d8a085-ca5b-419f-9981-dfc582c6ce16" /> https://docs.anthropic.com/en/docs/build-with-claude/pdf-support#:~:text=Send%20your%20first%20PDF%20request <img width="2158" height="1364" alt="CleanShot 2025-07-12 at 10 52 13@2x" src="https://github.com/user-attachments/assets/34fde67d-8a9c-4354-9cc7-dce0a6b3bbd1" /> https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching ## This PR contains Changes to *Non-Plugin* <!-- Put an `x` in all the boxes that apply by replacing [ ] with [x] For example: - [x] Documentation --> - [ ] Documentation - [ ] Other ## This PR contains Changes to *Non-LLM Models Plugin* - [ ] I have Run Comprehensive Tests Relevant to My Changes <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> ## This PR contains Changes to *LLM Models Plugin* <!-- LLM Models Test Example: --> <!-- https://github.com/langgenius/dify-official-plugins/blob/main/.assets/test-examples/llm-plugin-tests/llm_test_example.md --> - [x] My Changes Affect Message Flow Handling (System Messages and User→Assistant Turn-Taking) <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> <img width="2778" height="1524" alt="CleanShot 2025-07-12 at 10 14 48@2x" src="https://github.com/user-attachments/assets/8d111ad5-f940-4143-8d12-0c0220dc0158" /> - [x] My Changes Affect Tool Interaction Flow (Multi-Round Usage and Output Handling, for both Agent App and Agent Node) <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> <img width="2642" height="1524" alt="CleanShot 2025-07-12 at 10 17 15@2x" src="https://github.com/user-attachments/assets/150a67d0-898a-4420-9ddc-8b81d6755c1d" /> - [x] My Changes Affect Multimodal Input Handling (Images, PDFs, Audio, Video, etc.) <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> <img width="1442" height="974" alt="CleanShot 2025-07-12 at 10 17 52@2x" src="https://github.com/user-attachments/assets/bd213d7a-a6f9-4a43-b219-a3e936e3ff24" /> - [ ] My Changes Affect Multimodal Output Generation (Images, Audio, Video, etc.) <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> - [ ] My Changes Affect Structured Output Format (JSON, XML, etc.) <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> - [x] My Changes Affect Token Consumption Metrics <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> ### Before Caching <img width="630" height="122" alt="CleanShot 2025-07-12 at 10 44 31@2x" src="https://github.com/user-attachments/assets/7d3fed4e-413c-4d3c-b382-48c30c0cdd3e" /> <img width="568" height="560" alt="CleanShot 2025-07-12 at 10 44 37@2x" src="https://github.com/user-attachments/assets/0efec974-03e6-4faa-91dc-9e1c14e8a41a" /> ### After Caching <img width="570" height="222" alt="CleanShot 2025-07-12 at 10 45 18@2x" src="https://github.com/user-attachments/assets/e77a4f9f-a121-4efe-b461-6751582293f4" /> <img width="476" height="562" alt="CleanShot 2025-07-12 at 10 45 38@2x" src="https://github.com/user-attachments/assets/b6a3a5b9-c2f8-42f2-ab4d-62dffbfbbfaa" /> - [x] My Changes Affect Other LLM Functionalities (Reasoning Process, Grounding, Prompt Caching, etc.) <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> ### Tool Definitions Caching <img width="2090" height="662" alt="CleanShot 2025-07-12 at 10 25 18@2x" src="https://github.com/user-attachments/assets/1f6e681b-b426-4363-8e32-da27f534c4ca" /> ### Images and Documents Caching <img width="1334" height="748" alt="CleanShot 2025-07-12 at 10 28 57@2x" src="https://github.com/user-attachments/assets/341777e8-9ddd-4642-b2eb-fff16537dd93" /> ### System Message Caching <img width="1326" height="408" alt="CleanShot 2025-07-12 at 10 29 27@2x" src="https://github.com/user-attachments/assets/11b785b0-c58c-4006-83f1-68bcca2ed371" /> ### Tool Use Results Caching <img width="2078" height="736" alt="CleanShot 2025-07-12 at 10 30 03@2x" src="https://github.com/user-attachments/assets/3f5e072c-0da8-4dff-994b-ded6f4287808" /> ### Assistant and User Message Flow Caching <img width="2102" height="364" alt="CleanShot 2025-07-12 at 10 42 05@2x" src="https://github.com/user-attachments/assets/e42b3c22-caf3-4cc7-b167-44d1b13847ea" /> - [x] Other Changes (Add New Models, Fix Model Parameters etc.) <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking Changes. --> <img width="780" height="712" alt="CleanShot 2025-07-12 at 10 20 13@2x" src="https://github.com/user-attachments/assets/c55d651d-59bd-4da5-8582-b1a36a576de5" /> ## Version Control (Any Changes to the Plugin Will Require Bumping the Version) - [x] I have Bumped Up the Version in Manifest.yaml (Top-Level `Version` Field, Not in Meta Section) <!-- ⚠️ NOTE: Version Format: MAJOR.MINOR.PATCH - MAJOR (0.x.x): Reserved for Significant architectural changes or incompatible API modifications - MINOR (x.0.x): For New feature additions while maintaining backward compatibility - PATCH (x.x.0): For Backward-compatible bug fixes and minor improvements - Note: Each Version Component (MAJOR, MINOR, PATCH) Can Be 2 Digits, e.g., 10.11.22 --> ## Dify Plugin SDK Version - [x] I have Ensured `dify_plugin>=0.3.0,<0.5.0` is in requirements.txt ([SDK docs](https://github.com/langgenius/dify-plugin-sdks/blob/main/python/README.md)) ## Environment Verification (If Any Code Changes) <!-- ⚠️ NOTE: At Least One Environment Must Be Tested. --> ### Local Deployment Environment - [ ] Dify Version is: <!-- Specify Your Version (e.g., 1.2.0) -->, I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration. <!-- - Python Virtual Env Matching Manifest.yaml & requirements.txt - No Breaking Changes in Dify That May Affect the Testing Result --> ### SaaS Environment - [x] I have Tested My Changes on cloud.dify.ai with a Clean Environment That Matches the Production Configuration <!-- - Python Virtual Env Matching Manifest.yaml & requirements.txt --> --- <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:24:02 -05:00
yindo closed this issue 2026-02-16 10:24:02 -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#1807