feat: add async prompt fetching API with shared caching and tests #1423
+283
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Introduces async prompt fetching API with shared caching and tests in
client.pyandtest_prompt.py.aget_prompt()inclient.pyfor async prompt fetching with caching._fetch_prompt_and_update_cache_async()for async server fetches with retries._create_fallback_prompt_client().test_async_get_fresh_prompt,test_async_get_prompt_uses_cache_without_fetch, andtest_async_get_prompt_returns_fallback_on_failureintest_prompt.pyto validate async fetching and caching behavior.This description was created by
for e0b1626. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Updated On: 2025-10-31 00:29:58 UTC
Greptile Summary
Adds async prompt fetching API (
aget_prompt) that mirrors the synchronousget_promptmethod with identical caching semantics.Key Changes:
aget_prompt()async method with same signature and behavior as sync version_fetch_prompt_and_update_cache_async()to handle async API calls with retry logic_create_fallback_prompt_client()helper to eliminate code duplicationPromptCacheinstance for consistencyrun_async_safely()to handle event loop conflictsImplementation Quality:
AsyncMockin testsConfidence Score: 5/5
Important Files Changed
File Analysis
aget_promptasync method and refactored fallback creation into_create_fallback_prompt_clienthelper. Implementation correctly shares cache with sync method and properly handles async refresh logic usingrun_async_safely.aget_promptcovering cache hits, cache misses, and fallback scenarios. Tests properly useAsyncMockandasyncio.run. Imports correctly placed at module top.Sequence Diagram
sequenceDiagram participant User participant Langfuse participant PromptCache participant AsyncAPI participant TaskManager User->>Langfuse: aget_prompt(name) Langfuse->>PromptCache: get(cache_key) alt Cache Miss PromptCache-->>Langfuse: None Langfuse->>AsyncAPI: prompts.get(name) AsyncAPI-->>Langfuse: prompt_response Langfuse->>PromptCache: set(cache_key, prompt) Langfuse-->>User: PromptClient else Cache Hit (Valid) PromptCache-->>Langfuse: cached_prompt Langfuse-->>User: cached_prompt.value else Cache Hit (Expired) PromptCache-->>Langfuse: expired_prompt Langfuse->>TaskManager: add_refresh_prompt_task() Note over TaskManager: Background refresh in thread TaskManager->>AsyncAPI: prompts.get(name) AsyncAPI-->>TaskManager: updated_prompt TaskManager->>PromptCache: set(cache_key, updated_prompt) Langfuse-->>User: expired_prompt.value (stale) end