feat(skill): skills management client, cache and manager methods#1739
Open
Robin1511 wants to merge 2 commits into
Open
feat(skill): skills management client, cache and manager methods#1739Robin1511 wants to merge 2 commits into
Robin1511 wants to merge 2 commits into
Conversation
Hand-written high-level skills API mirroring the prompt manager: - SkillCache (TTL, background stale-while-revalidate refresh, prefix invalidation) in langfuse/_utils/skill_cache.py - SkillClient wrapper with .compile() variable substitution of the instructions body (single client; skills have no chat/text split) - Langfuse client methods get_skill / create_skill / update_skill / delete_skill / clear_skill_cache with caching, fallback and retries - unit tests for cache TTL and client compilation Depends on the auto-generated langfuse.api skills client (api-spec-bot regeneration from the Fern contract in langfuse/langfuse).
…ocstring - create_skill/update_skill: default labels/new_labels to None and coerce to [] in the body (avoid shared mutable default list) - SkillCache.invalidate: anchor prefix match with '-' separator so a skill named 'foo' cannot evict 'foobar-*' cache entries - get_skill: docstring fetch_timeout_seconds is seconds, not milliseconds
ca4659b to
1952f27
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Skills management (Python SDK)
Hand-written high-level skills API mirroring the prompt manager:
SkillCache(TTL, background stale-while-revalidate refresh, prefix invalidation)SkillClientwith.compile()variable substitution of theinstructionsbody (single client — skills have no chat/text split)Langfusemethodsget_skill/create_skill/update_skill/delete_skill/clear_skill_cachewith caching, fallback, retriesDepends on the auto-generated
langfuse.apiskills client from theapi-spec-botregeneration of the Fern contract in langfuse/langfuse (langfuse/langfuse#14838). Imports resolve once that client lands.Greptile Summary
This PR adds a skills management API to the Python SDK — mirroring the existing prompt manager — with
SkillCache(TTL + stale-while-revalidate background refresh),SkillClient(variable substitution viacompile()), and five newLangfusemethods (get_skill,create_skill,update_skill,delete_skill,clear_skill_cache).SkillCacheandSkillCacheTaskManagerare near-exact copies of thePromptCacheinfrastructure; the background-refresh deduplication and shutdown logic work correctly.SkillClientwraps the generatedSkillAPI model withcompile()delegating toTemplateParserand adict()helper for serialization.labels=[]increate_skill,new_labels=[]inupdate_skill) and a prefix-matching bug inSkillCache.invalidateneed attention before merge.Confidence Score: 3/5
Needs three straightforward fixes before merge: two mutable default arguments and a cache invalidation prefix bug.
The invalidate method does a bare startswith(skill_name) check, which silently evicts cache entries for any skill whose name starts with the target name. The two mutable [] defaults in create_skill/update_skill are a latent correctness hazard. All three are straightforward one-line fixes, but they affect the correctness of the core cache and public API surface.
langfuse/_utils/skill_cache.py (invalidate prefix logic) and langfuse/_client/client.py (mutable defaults, docstring unit error).
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Caller participant Langfuse participant SkillCache participant API as Langfuse API Caller->>Langfuse: get_skill(name, version, label, cache_ttl_seconds) Langfuse->>SkillCache: get(cache_key) alt "Cache miss or ttl==0" SkillCache-->>Langfuse: None Langfuse->>API: skills.get(name, version, label) API-->>Langfuse: Skill response Langfuse->>SkillCache: set(cache_key, SkillClient, ttl) Langfuse-->>Caller: SkillClient else Cache hit fresh SkillCache-->>Langfuse: SkillCacheItem not expired Langfuse-->>Caller: cached_skill.value else Cache hit stale expired SkillCache-->>Langfuse: SkillCacheItem expired Langfuse->>SkillCache: add_refresh_skill_task_if_current Note over SkillCache: Background thread refreshes cache Langfuse-->>Caller: stale cached_skill.value end Caller->>Langfuse: create_skill(name, instructions, labels) Langfuse->>API: skills.create(CreateSkillRequest) API-->>Langfuse: Skill Langfuse->>SkillCache: invalidate(name) Langfuse-->>Caller: SkillClient%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Caller participant Langfuse participant SkillCache participant API as Langfuse API Caller->>Langfuse: get_skill(name, version, label, cache_ttl_seconds) Langfuse->>SkillCache: get(cache_key) alt "Cache miss or ttl==0" SkillCache-->>Langfuse: None Langfuse->>API: skills.get(name, version, label) API-->>Langfuse: Skill response Langfuse->>SkillCache: set(cache_key, SkillClient, ttl) Langfuse-->>Caller: SkillClient else Cache hit fresh SkillCache-->>Langfuse: SkillCacheItem not expired Langfuse-->>Caller: cached_skill.value else Cache hit stale expired SkillCache-->>Langfuse: SkillCacheItem expired Langfuse->>SkillCache: add_refresh_skill_task_if_current Note over SkillCache: Background thread refreshes cache Langfuse-->>Caller: stale cached_skill.value end Caller->>Langfuse: create_skill(name, instructions, labels) Langfuse->>API: skills.create(CreateSkillRequest) API-->>Langfuse: Skill Langfuse->>SkillCache: invalidate(name) Langfuse-->>Caller: SkillClientPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "feat(skill): add skills management clien..." | Re-trigger Greptile