Skip to content

feat(llm): cache recent Claude prompt context - #910

Open
ousamabenyounes wants to merge 1 commit into
usestrix:mainfrom
ousamabenyounes:feat/issue-279-prompt-cache
Open

feat(llm): cache recent Claude prompt context#910
ousamabenyounes wants to merge 1 commit into
usestrix:mainfrom
ousamabenyounes:feat/issue-279-prompt-cache

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Fixes #279.

Summary

  • Adds a second rolling Claude prompt-cache breakpoint on the previous message (index: -2).
  • Keeps the existing system prompt and latest-message breakpoints.
  • Keeps Bedrock within Claude's four-cache-control-block limit by using system + tool_config + previous message + latest message.

Test verification (RED -> GREEN)

RED on origin/main with only the updated expectations:

$ uv run pytest tests/test_inputs.py::test_make_model_settings_enables_prompt_cache_for_bedrock_claude tests/test_inputs.py::test_make_model_settings_enables_prompt_cache_for_non_bedrock_claude -q
AssertionError: ... {'location': 'message', 'index': -1} != {'location': 'message', 'index': -2}
4 failed

GREEN after the fix:

$ uv run pytest tests/test_inputs.py::test_make_model_settings_enables_prompt_cache_for_bedrock_claude tests/test_inputs.py::test_make_model_settings_enables_prompt_cache_for_non_bedrock_claude -q
4 passed

Fix-reverted proof:

$ git apply -R /tmp/strix-issue-279-fix.patch && uv run pytest tests/test_inputs.py::test_make_model_settings_enables_prompt_cache_for_bedrock_claude -q
AssertionError: ... {'location': 'message', 'index': -1} != {'location': 'message', 'index': -2}
1 failed

Validation

  • uv run pytest tests/test_inputs.py tests/test_models.py -q -> 92 passed
  • uv run ruff check strix/core/inputs.py tests/test_inputs.py -> pass
  • uv run ruff format --check strix/core/inputs.py tests/test_inputs.py -> pass
  • uv run mypy strix/core/inputs.py tests/test_inputs.py -> pass
  • uv run bandit -q -c pyproject.toml strix/core/inputs.py -> pass

@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds a rolling Claude prompt-cache breakpoint for the previous message.

  • Defines constants for Claude cache-control locations, roles, and rolling message indices.
  • Configures system, previous-message, and latest-message breakpoints for Claude routes.
  • Retains Bedrock’s tool-config breakpoint while remaining within its four-block limit.
  • Updates model-settings tests for supported Bedrock and non-Bedrock Claude models.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable correctness or security issues identified.

The added previous-message breakpoint is ignored when no previous message exists and becomes effective once sufficient conversation history is available, while Bedrock remains within its four-cache-control-block limit.

Important Files Changed

Filename Overview
strix/core/inputs.py Adds the previous-message cache breakpoint while preserving route-specific Bedrock behavior and cache-block limits.
tests/test_inputs.py Updates prompt-cache expectations for supported Bedrock, Anthropic, and OpenRouter Claude models.

Reviews (1): Last reviewed commit: "feat(llm): cache recent Claude prompt co..." | Re-trigger Greptile

@ousamabenyounes
ousamabenyounes force-pushed the feat/issue-279-prompt-cache branch from c8e4220 to 708ab05 Compare July 27, 2026 20:37
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.

Improve Claude prompt caching usage

1 participant