sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)

This commit is contained in:
gozeros committed 2026-10-21 14:51:31 +08:00
1 parent 4f7f07504a
commit 8bc8b0e082
1651 files changed
+278599 -11416

No files matched your search

@@ -0,0 +1,41 @@
"""A skill snapshot is reusable only inside one explicitly enabled tool call."""
from collections.abc import Callable
from contextvars import ContextVar
from dataclasses import dataclass
from functools import wraps
from typing import TYPE_CHECKING
from deerflow.config.runtime_performance_config import get_runtime_performance_config
if TYPE_CHECKING:
from deerflow.sandbox.skill_view import SkillSandboxView
@dataclass
class SkillViewScope:
view: "SkillSandboxView | None" = None
error: Exception | None = None
_scope: ContextVar[SkillViewScope | None] = ContextVar("sandbox_skill_view_scope", default=None)
def get_active_skill_view_scope() -> SkillViewScope | None:
return _scope.get()
def with_skill_view_scope[**P, R](func: Callable[P, R]) -> Callable[P, R]:
@wraps(func)
def wrapped(*args: P.args, **kwargs: P.kwargs) -> R:
if not get_runtime_performance_config().skill_view_reuse_enabled:
return func(*args, **kwargs)
token = _scope.set(SkillViewScope())
try:
return func(*args, **kwargs)
finally:
# Do not leak a previously enabled skill into the next tool call,
# including when a tool raises or shares an executor thread.
_scope.reset(token)
return wrapped