Skip to content

fix: support Responses input in Redis semantic cache - #28274

Closed
balcsida wants to merge 4 commits into
BerriAI:shin_agent_oss_staging_05_19_2026from
balcsida:fix/redis-semantic-responses-input
Closed

fix: support Responses input in Redis semantic cache#28274
balcsida wants to merge 4 commits into
BerriAI:shin_agent_oss_staging_05_19_2026from
balcsida:fix/redis-semantic-responses-input

Conversation

@balcsida

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #28272

Linear ticket

N/A

Pre-Submission checklist

  • I have added testing in the tests/test_litellm directory
  • My PR passes all unit tests on make test-unit
  • My PR scope is isolated and solves one specific problem
  • I have requested a Greptile review

Screenshots / Proof of Fix

Before this change, RedisSemanticCache only extracted prompts from messages. Responses API calls pass input instead, so RedisVL store/check were skipped and the RediSearch index stayed empty.

Validation run locally:

uv run pytest tests/test_litellm/caching/test_redis_semantic_cache.py -q
...................                                                      [100%]
19 passed in 0.27s

uv run ruff check litellm/caching/caching.py litellm/caching/redis_semantic_cache.py tests/test_litellm/caching/test_redis_semantic_cache.py
All checks passed!

uv run black --check litellm/caching/caching.py litellm/caching/redis_semantic_cache.py tests/test_litellm/caching/test_redis_semantic_cache.py
All done!
3 files would be left unchanged.

I also attempted the broader caching test directory, but the local environment is missing optional dependencies for unrelated Azure/S3 cache tests (azure, boto3).

Type

Bug Fix
Test

Changes

  • Added RedisSemanticCache prompt extraction for Responses API input, while preserving existing chat messages extraction.
  • Supported string input and structured Responses input content lists.
  • Updated sync cache lookup to pass original kwargs through to backend caches so input and metadata are available to semantic caches.
  • Added regression tests for sync set/get, async set/get, structured Responses input extraction, and wrapper passthrough.

@CLAassistant

CLAassistant commented May 19, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
5 out of 7 committers have signed the CLA.

✅ TorvaldUtne
✅ mubashir1osmani
✅ balcsida
✅ ro31337
✅ cwang-otto
❌ oss-agent-shin
❌ IshaMeera
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/caching/redis_semantic_cache.py 90.00% 7 Missing ⚠️
litellm/caching/caching.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@balcsida
balcsida force-pushed the fix/redis-semantic-responses-input branch from c0e4aa4 to 3d16a55 Compare May 19, 2026 19:20
@balcsida
balcsida marked this pull request as ready for review May 19, 2026 20:33
@greptile-apps

greptile-apps Bot commented May 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes RedisSemanticCache ignoring Responses API calls by extracting a cacheable prompt from the input field when messages is absent, and updates the sync Cache.get_cache to forward full **kwargs to backend caches (making it consistent with the async path that already did this).

  • _get_prompt_from_kwargs / _collect_responses_input_text / _coerce_response_input_value are added to RedisSemanticCache to handle string input, nested structured content lists, and Pydantic model objects.
  • The sync Cache.get_cache now passes **kwargs rather than messages=messages to the backend, enabling semantic caches to access input and other Responses API fields.
  • Eight new unit tests cover sync/async set+get with string input, structured Responses input flattening, edge-case prompt extraction, and the Cache wrapper passthrough; all are fully mocked.

Confidence Score: 4/5

Safe to merge; the fix is well-scoped and the async path already behaved this way, so the sync change is a consistency fix rather than new ground.

Both the dict and object branches of _collect_responses_input_text return early when any text-keyed attribute is a present-but-blank string, so a fallback key with real content would be silently missed. This is an edge case unlikely to surface with real Responses API payloads.

litellm/caching/redis_semantic_cache.py — the text-key fallback loop in both the dict and object branches of _collect_responses_input_text.

Important Files Changed

Filename Overview
litellm/caching/redis_semantic_cache.py Adds _get_prompt_from_kwargs, _collect_responses_input_text, and _coerce_response_input_value to extract prompts from Responses API input alongside existing messages support; replaces four hard-coded messages extractions in set/get (sync+async) with the new helper. Minor edge case in text-key fallback logic.
litellm/caching/caching.py Removes local messages extraction in sync get_cache and passes full **kwargs to backend cache, making it consistent with the already-existing async path behavior.
tests/test_litellm/caching/test_redis_semantic_cache.py Adds 8 new unit tests covering sync/async set+get with string input, structured Responses input flattening, prompt extraction edge cases (model objects, None, whitespace), and the Cache wrapper passthrough. All mocked, no real network calls.
tests/test_litellm/interactions/test_openapi_compliance.py Adds "budget_exceeded" to the expected Responses API status enum in the OpenAPI compliance assertion.

Reviews (1): Last reviewed commit: "test: include budget exceeded interactio..." | Re-trigger Greptile

Comment thread litellm/caching/redis_semantic_cache.py
Comment thread litellm/caching/redis_semantic_cache.py Outdated
@oss-pr-review-agent-shin

Copy link
Copy Markdown
Contributor

🤖 litellm-agent: Auto-merge skipped — the staging branch shin_agent_oss_staging_05_19_2026 has 5 commit(s) not in your branch. Merging as-is would produce a confusing diff on the staging PR.

Please rebase your branch onto shin_agent_oss_staging_05_19_2026 and push; the agent will re-review automatically.

@balcsida
balcsida force-pushed the fix/redis-semantic-responses-input branch from 81002f7 to 716e17f Compare May 19, 2026 22:01
@balcsida
balcsida changed the base branch from litellm_internal_staging to shin_agent_oss_staging_05_19_2026 May 19, 2026 22:07
@Sameerlite
Sameerlite deleted the branch BerriAI:shin_agent_oss_staging_05_19_2026 May 22, 2026 12:07
@Sameerlite Sameerlite closed this May 22, 2026
@balcsida

Copy link
Copy Markdown
Contributor Author

May I ask why this was closed?

@Sameerlite

Copy link
Copy Markdown
Contributor

@balcsida The branch was deleted when cleaning old branches up. Can you use the latest internal staging as base and recreate the PR? sorry for the trouble.

@balcsida

Copy link
Copy Markdown
Contributor Author

Fair enough, @Sameerlite
Unless there was another constraint I’m missing, updating the base branch seems like it would have been the cleaner option than closing the PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redis Semantic Cache skips Responses API input, leaving RediSearch empty

3 participants