sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
@@ -0,0 +1,43 @@
|
||||
"""Optional administrator-managed runtime guidance shared by agents."""
|
||||
|
||||
from deerflow.config.system_settings import load_system_settings
|
||||
|
||||
PYTHON_DEPENDENCY_POLICY = """
|
||||
|
||||
<python_dependency_boundary>
|
||||
禁止以清理、释放空间或排错为由,主动删除或单独卸载 Python 依赖;不得通过 Python 脚本、Shell、子进程或其他工具绕过此限制。
|
||||
- 不得执行独立的 pip/uv/conda 卸载操作,不得用 os.remove、pathlib.unlink、shutil.rmtree、rm 等直接删除依赖文件、包目录或整个 Python 环境。
|
||||
- 允许正常使用已有依赖、执行技能、查询版本;缺少依赖或版本不兼容时,允许安装、升级、降级,或寻找并安装合适的替代依赖,无需仅因缺包而停止等待管理员。
|
||||
- 允许包管理器在正常安装、升级或版本替换过程中自动移除旧版本;这不属于禁止的独立删除。不要先手动删除或卸载依赖再安装,也不要顺带清理无关依赖。
|
||||
- 允许在获准工作区正常创建、修改和删除任务脚本、临时数据及输出文件;将以上依赖操作边界传递给子智能体。
|
||||
</python_dependency_boundary>
|
||||
"""
|
||||
|
||||
|
||||
def get_python_dependency_policy() -> str:
|
||||
"""Read the shared runtime switch whenever a new agent prompt is built."""
|
||||
if load_system_settings().prompt_prefix.python_dependency_delete_protection_enabled:
|
||||
return PYTHON_DEPENDENCY_POLICY
|
||||
return ""
|
||||
|
||||
|
||||
IMAGE_GENERATION_UNAVAILABLE_POLICY = """
|
||||
|
||||
<image_generation_unavailable>
|
||||
当前服务未提供 AI 图片生成或图片编辑能力。
|
||||
- 当用户要求文生图、绘画、生成照片/插画/海报图片、图生图或修改图片内容时,直接明确告知:“当前服务暂不支持生成或编辑图片。”不要承诺稍后生成,不要伪造图片、下载链接或声称已完成。
|
||||
- 不要为此调用技能、委派子智能体、安装图片生成依赖或访问外部图片生成服务;不要自行改用 Python 绘图、SVG、HTML 截图等来冒充用户要求的 AI 生图。
|
||||
- 可简短说明能够帮助整理图片描述、构图方案或绘图提示词;用户接受替代方案后再执行。混合请求中不依赖图片生成的部分仍可正常完成。
|
||||
- 此限制不影响服务已有的图片上传/理解、图片搜索,以及用户明确请求的数据图表、流程图、Mermaid、SVG 代码或 HTML 页面制作。是否可用仍以实际工具为准,不得虚构其他能力。
|
||||
- 用户只要求撰写或修改绘图提示词时,直接完成文字任务,不要误判为图片生成请求。将以上边界传递给子智能体。
|
||||
</image_generation_unavailable>
|
||||
"""
|
||||
|
||||
|
||||
def get_agent_runtime_policy() -> str:
|
||||
"""Build independently toggled policies for each new lead/subagent run."""
|
||||
settings = load_system_settings().prompt_prefix
|
||||
return (
|
||||
(PYTHON_DEPENDENCY_POLICY if settings.python_dependency_delete_protection_enabled else "")
|
||||
+ (IMAGE_GENERATION_UNAVAILABLE_POLICY if settings.image_generation_unavailable_hint_enabled else "")
|
||||
)
|
||||
+20
-11
@@ -1,4 +1,5 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from threading import RLock
|
||||
|
||||
from deerflow.config import get_app_config
|
||||
from deerflow.reflection import resolve_class
|
||||
@@ -39,6 +40,10 @@ class SandboxProvider(ABC):
|
||||
|
||||
|
||||
_default_sandbox_provider: SandboxProvider | None = None
|
||||
# Constructors can reconcile containers and start lifecycle threads. Publishing
|
||||
# just one instance must be atomic with explicit replacement/reset operations.
|
||||
# Reentrancy also permits same-thread lifecycle callbacks to use these helpers.
|
||||
_sandbox_provider_lock = RLock()
|
||||
|
||||
|
||||
def get_sandbox_provider(**kwargs) -> SandboxProvider:
|
||||
@@ -51,11 +56,12 @@ def get_sandbox_provider(**kwargs) -> SandboxProvider:
|
||||
A sandbox provider instance.
|
||||
"""
|
||||
global _default_sandbox_provider
|
||||
if _default_sandbox_provider is None:
|
||||
config = get_app_config()
|
||||
cls = resolve_class(config.sandbox.use, SandboxProvider)
|
||||
_default_sandbox_provider = cls(**kwargs)
|
||||
return _default_sandbox_provider
|
||||
with _sandbox_provider_lock:
|
||||
if _default_sandbox_provider is None:
|
||||
config = get_app_config()
|
||||
cls = resolve_class(config.sandbox.use, SandboxProvider)
|
||||
_default_sandbox_provider = cls(**kwargs)
|
||||
return _default_sandbox_provider
|
||||
|
||||
|
||||
def reset_sandbox_provider() -> None:
|
||||
@@ -69,7 +75,8 @@ def reset_sandbox_provider() -> None:
|
||||
Use `shutdown_sandbox_provider()` for proper cleanup.
|
||||
"""
|
||||
global _default_sandbox_provider
|
||||
_default_sandbox_provider = None
|
||||
with _sandbox_provider_lock:
|
||||
_default_sandbox_provider = None
|
||||
|
||||
|
||||
def shutdown_sandbox_provider() -> None:
|
||||
@@ -80,10 +87,11 @@ def shutdown_sandbox_provider() -> None:
|
||||
is shutting down or when you need to completely reset the sandbox system.
|
||||
"""
|
||||
global _default_sandbox_provider
|
||||
if _default_sandbox_provider is not None:
|
||||
if hasattr(_default_sandbox_provider, "shutdown"):
|
||||
_default_sandbox_provider.shutdown()
|
||||
_default_sandbox_provider = None
|
||||
with _sandbox_provider_lock:
|
||||
if _default_sandbox_provider is not None:
|
||||
if hasattr(_default_sandbox_provider, "shutdown"):
|
||||
_default_sandbox_provider.shutdown()
|
||||
_default_sandbox_provider = None
|
||||
|
||||
|
||||
def set_sandbox_provider(provider: SandboxProvider) -> None:
|
||||
@@ -95,4 +103,5 @@ def set_sandbox_provider(provider: SandboxProvider) -> None:
|
||||
provider: The SandboxProvider instance to use.
|
||||
"""
|
||||
global _default_sandbox_provider
|
||||
_default_sandbox_provider = provider
|
||||
with _sandbox_provider_lock:
|
||||
_default_sandbox_provider = provider
|
||||
@@ -1750,7 +1750,13 @@ def _reconcile_tree(skills_root: Path, view_root: Path, source_root: Path, entry
|
||||
key = relative.as_posix()
|
||||
destination = view_root / relative
|
||||
source_same = cached_source.get(key) == _metadata(source)
|
||||
target_same = cached_target.get(key) == _metadata(destination)
|
||||
destination_metadata = _metadata(destination)
|
||||
# A missing file and an uncached file are both represented by ``None``.
|
||||
# After an offline skill has been removed from the published view, the
|
||||
# source metadata can still be current while the target key is absent.
|
||||
# Do not mistake that cache miss for an unchanged destination or the
|
||||
# skill will be marked online without restoring any of its files.
|
||||
target_same = destination_metadata is not None and cached_target.get(key) == destination_metadata
|
||||
if not (source_same and target_same):
|
||||
_copy_file_atomic(source, destination)
|
||||
return prefix
|
||||
|
||||
Reference in new issue
Block a user