You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to have a cached version of the LLM client, which writes output to local files within test flows. This implies converting the existing client into a class that would need to be initialized and incorporated into ElroyContext
The test llm client should still be able to call real endpoints like it does currently, but it should write responses to a fixtures dir in the test dir. This can be checked into version control (not automated, user can do this), so remote runs can just used cached data rather than re-running llm queries.
This caching mechanism should ONLY affect tests, there should not be caching that affects production
The cache should be written in json files, in a test/fixtures/llm_cache dir
Replays cached streaming responses for generate_chat_completion_message
Maintains compatibility with existing code expecting StreamParser
Test Integration:
Added cached_ctx fixture to conftest.py for easy test usage
Updated george_ctx fixture to use cached responses
Created comprehensive tests in tests/llm/test_cached_client.py
ElroyContext Enhancement:
Added set_custom_llm_client() method to allow overriding the default LLM client
Maintains backward compatibility
Features
Test-only caching: Only affects test environment, production code unchanged
Offline testing: Tests can run without API access once responses are cached
Deterministic results: Same inputs always produce same outputs
CI/CD friendly: Cache files can be committed to version control
Automatic cache directory creation: Creates tests/fixtures/llm_cache/ as needed
Parameter-based caching: Different requests create separate cache entries
Usage
Tests can now use the cached_ctx fixture instead of ctx to get automatic LLM response caching:
deftest_something(cached_ctx):
response=cached_ctx.llm.query_llm("What is 2+2?", "You are helpful")
# First run makes API call and caches response# Subsequent runs use cached response
Activity
elroy-bot commentedon Sep 3, 2025
@claude implement
claude commentedon Sep 3, 2025
Claude finished @elroy-bot's task —— View job •
claude/issue-484-20250903-2251• Create PR ➔LLM Response Caching Implementation ✅
I have successfully implemented LLM response caching for tests as requested.
Todo List
Implementation Summary
Key Components Created:
CachedLlmClient(elroy/llm/cached_client.py):LlmClientclassquery_llm,get_embedding,generate_chat_completion_message, etc.tests/fixtures/llm_cache/MockStreamParser(elroy/llm/mock_stream_parser.py):generate_chat_completion_messageTest Integration:
cached_ctxfixture toconftest.pyfor easy test usagegeorge_ctxfixture to use cached responsestests/llm/test_cached_client.pyElroyContext Enhancement:
set_custom_llm_client()method to allow overriding the default LLM clientFeatures
tests/fixtures/llm_cache/as neededUsage
Tests can now use the
cached_ctxfixture instead ofctxto get automatic LLM response caching:All changes committed and pushed to the branch.