Skip to content

Commit ca4659b

Browse files
author
Robin DE BASTOS
committed
fix(skill): address review — mutable defaults, cache prefix anchor, docstring
- 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
1 parent 9b577f7 commit ca4659b

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

langfuse/_client/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4088,7 +4088,7 @@ def get_skill(
40884088
keyword argument. If not set, defaults to 60 seconds. Disables caching if set to 0.
40894089
fallback: Optional[str]: The skill instructions to return if fetching the skill fails. Important on the first call where no cached skill is available. Follows Langfuse skill formatting with double curly braces for variables. Defaults to None.
40904090
max_retries: Optional[int]: The maximum number of retries in case of API/network errors. Defaults to 2. The maximum value is 4. Retries have an exponential backoff with a maximum delay of 10 seconds.
4091-
fetch_timeout_seconds: Optional[int]: The timeout in milliseconds for fetching the skill. Defaults to the default timeout set on the SDK, which is 5 seconds per default.
4091+
fetch_timeout_seconds: Optional[int]: The timeout in seconds for fetching the skill. Defaults to the default timeout set on the SDK, which is 5 seconds per default.
40924092
40934093
Returns:
40944094
The skill object retrieved from the cache or directly fetched if not cached or expired, as a SkillClient.
@@ -4244,7 +4244,7 @@ def create_skill(
42444244
name: str,
42454245
instructions: str,
42464246
description: Optional[str] = None,
4247-
labels: List[str] = [],
4247+
labels: Optional[List[str]] = None,
42484248
tags: Optional[List[str]] = None,
42494249
metadata: Optional[Any] = None,
42504250
allowed_tools: Optional[List[str]] = None,
@@ -4265,6 +4265,8 @@ def create_skill(
42654265
Returns:
42664266
SkillClient: The created skill.
42674267
"""
4268+
labels = labels or []
4269+
42684270
try:
42694271
langfuse_logger.debug(f"Creating skill {name=}, {labels=}")
42704272

@@ -4295,7 +4297,7 @@ def update_skill(
42954297
*,
42964298
name: str,
42974299
version: int,
4298-
new_labels: List[str] = [],
4300+
new_labels: Optional[List[str]] = None,
42994301
) -> Any:
43004302
"""Update an existing skill version in Langfuse. The Langfuse SDK skill cache is invalidated for all skills with the specified name.
43014303
@@ -4308,6 +4310,8 @@ def update_skill(
43084310
Skill: The updated skill from the Langfuse API.
43094311
43104312
"""
4313+
new_labels = new_labels or []
4314+
43114315
updated_skill = self.api.skill_version.update(
43124316
name=self._url_encode(name),
43134317
version=version,

langfuse/_utils/skill_cache.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ def delete(self, key: str) -> None:
178178

179179
def invalidate(self, skill_name: str) -> None:
180180
"""Invalidate all cached skills with the given skill name."""
181+
prefix = skill_name + "-"
181182
with self._lock:
182183
for key in list(self._cache):
183-
if key.startswith(skill_name):
184+
if key.startswith(prefix):
184185
del self._cache[key]
185186

186187
def add_refresh_skill_task(self, key: str, fetch_func: Callable[[], None]) -> None:

0 commit comments

Comments
 (0)