Skip to content

feat(fireworks): add prompt caching middleware - #38823

Open
Mason Daugherty (mdrxy) wants to merge 2 commits into
masterfrom
mdrxy/fireworks/prompt-cache-middleware
Open

feat(fireworks): add prompt caching middleware#38823
Mason Daugherty (mdrxy) wants to merge 2 commits into
masterfrom
mdrxy/fireworks/prompt-cache-middleware

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Jul 13, 2026

Copy link
Copy Markdown
Member

Fireworks agents can now use FireworksPromptCachingMiddleware to automatically set prompt-cache session affinity from the active thread ID. Cross-provider model fallbacks remove those Fireworks-specific settings before invoking the fallback model.


Fireworks prompt caching is most effective when requests from the same agent thread reach the same model replica. Agents currently need to manage that routing affinity themselves, which makes cache reuse easy to miss.

This adds FireworksPromptCachingMiddleware, which derives session affinity from config.configurable.thread_id while respecting affinity settings supplied by the caller. It also updates ModelFallbackMiddleware so Fireworks-only cache settings are retained for Fireworks fallbacks and removed before requests are sent to another provider.

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file (e.g. `pyproject.toml` or `uv.lock`) feature For PRs that implement a new feature; NOT A FEATURE REQUEST fireworks `langchain-fireworks` package issues & PRs integration PR made that is related to a provider partner package integration internal langchain `langchain` package issues & PRs size: L 500-999 LOC labels Jul 13, 2026

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

Comment on lines +127 to +129
if not _supports_fireworks_prompt_cache(fallback_model):
model_settings, fireworks_cache_changed = _without_fireworks_prompt_cache(model_settings)
model_settings_changed = model_settings_changed or fireworks_cache_changed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Preserve OpenAI prompt cache keys

prompt_cache_key is not Fireworks-specific: ChatOpenAI also exposes it as a supported per-invocation setting for cache routing. Because every non-Fireworks fallback now passes through this branch, an OpenAI primary/fallback request with model_settings={"prompt_cache_key": ...} silently loses the caller's valid key after the primary fails, reducing cache affinity and changing the fallback request. The sanitizer needs to distinguish affinity injected for Fireworks from a provider setting that the selected fallback supports, rather than removing this shared key from every non-Fireworks model.

(Refers to lines 127-129)


Your feedback helps Open SWE learn. React with 👍 or 👎 to tell us if this review comment was useful.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedlangchain@​1.3.1399100100100100

View full report

@codspeed-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 2 untouched benchmarks
⏩ 15 skipped benchmarks1


Comparing mdrxy/fireworks/prompt-cache-middleware (a2f04da) with master (cdca311)2

Open in CodSpeed

Footnotes

  1. 15 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (b8a6e36) during the generation of this report, so cdca311 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace


[[package]]
name = "langchain-core"
version = "1.5.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Regenerate the stale Fireworks lockfile

The merge resolution leaves this lockfile out of sync with its editable workspace sources: uv lock --check --directory libs/partners/fireworks now fails, and uv lock --dry-run reports that langchain-core must move from 1.5.0 to 1.5.2 and langchain from 1.3.13 to 1.3.14. Any CI or contributor workflow that checks the package lockfile therefore fails until the Fireworks lockfile is regenerated after the merge.

(Refers to line 819)


Your feedback helps Open SWE learn. React with 👍 or 👎 to tell us if this review comment was useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file (e.g. `pyproject.toml` or `uv.lock`) feature For PRs that implement a new feature; NOT A FEATURE REQUEST fireworks `langchain-fireworks` package issues & PRs integration PR made that is related to a provider partner package integration internal langchain `langchain` package issues & PRs size: L 500-999 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant