Skip to content

feat(fireworks): add prompt caching middleware#38823

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

feat(fireworks): add prompt caching middleware#38823
Mason Daugherty (mdrxy) wants to merge 1 commit 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.

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