feat: enhance agent skills sandbox configuration and availability
- Updated .env.example to set default sandbox mode to 'docker' and added timeout and docker image variables. - Modified docker-compose files to include a sandbox service for building and pulling the sandbox image. - Adjusted frontend API to reflect sandbox availability for skills, ensuring UI elements are conditionally displayed based on sandbox status. - Implemented backend logic to disable skills when the sandbox is not enabled, improving error handling and user experience.
This commit is contained in:
+4
-4
@@ -177,14 +177,14 @@ COS_ENABLE_OLD_DOMAIN=true
|
|||||||
# MAX_FILE_SIZE_MB=50
|
# MAX_FILE_SIZE_MB=50
|
||||||
|
|
||||||
# ========== Agent Skills Sandbox 配置 ==========
|
# ========== Agent Skills Sandbox 配置 ==========
|
||||||
# Sandbox 模式: docker(推荐), local, disabled(默认)
|
# Sandbox 模式: docker(默认), local, disabled
|
||||||
# WEKNORA_SANDBOX_MODE=disabled
|
WEKNORA_SANDBOX_MODE=docker
|
||||||
|
|
||||||
# 脚本执行超时时间(秒),默认60
|
# 脚本执行超时时间(秒),默认60
|
||||||
# WEKNORA_SANDBOX_TIMEOUT=60
|
WEKNORA_SANDBOX_TIMEOUT=60
|
||||||
|
|
||||||
# 自定义 Sandbox Docker 镜像
|
# 自定义 Sandbox Docker 镜像
|
||||||
# WEKNORA_SANDBOX_DOCKER_IMAGE=wechatopenai/weknora-sandbox:latest
|
WEKNORA_SANDBOX_DOCKER_IMAGE=wechatopenai/weknora-sandbox:latest
|
||||||
|
|
||||||
# APK 镜像源设置(可选)
|
# APK 镜像源设置(可选)
|
||||||
APK_MIRROR_ARG=mirrors.tencent.com
|
APK_MIRROR_ARG=mirrors.tencent.com
|
||||||
|
|||||||
@@ -94,6 +94,17 @@ services:
|
|||||||
- neo4j
|
- neo4j
|
||||||
- full
|
- full
|
||||||
|
|
||||||
|
# Sandbox 镜像:仅用于 build/pull,非常驻服务;本地 app 执行 Skills 时按需 docker run 该镜像,用毕即释
|
||||||
|
sandbox:
|
||||||
|
image: wechatopenai/weknora-sandbox:${WEKNORA_VERSION:-latest}
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: docker/Dockerfile.sandbox
|
||||||
|
profiles:
|
||||||
|
- sandbox
|
||||||
|
command: ["true"]
|
||||||
|
restart: "no"
|
||||||
|
|
||||||
docreader:
|
docreader:
|
||||||
image: wechatopenai/weknora-docreader:latest
|
image: wechatopenai/weknora-docreader:latest
|
||||||
container_name: WeKnora-docreader-dev
|
container_name: WeKnora-docreader-dev
|
||||||
|
|||||||
+16
-11
@@ -96,19 +96,13 @@ services:
|
|||||||
- TENANT_AES_KEY=${TENANT_AES_KEY:-}
|
- TENANT_AES_KEY=${TENANT_AES_KEY:-}
|
||||||
- CONCURRENCY_POOL_SIZE=${CONCURRENCY_POOL_SIZE:-5}
|
- CONCURRENCY_POOL_SIZE=${CONCURRENCY_POOL_SIZE:-5}
|
||||||
- JWT_SECRET=${JWT_SECRET:-}
|
- JWT_SECRET=${JWT_SECRET:-}
|
||||||
- INIT_LLM_MODEL_NAME=${INIT_LLM_MODEL_NAME:-}
|
|
||||||
- INIT_LLM_MODEL_BASE_URL=${INIT_LLM_MODEL_BASE_URL:-}
|
|
||||||
- INIT_LLM_MODEL_API_KEY=${INIT_LLM_MODEL_API_KEY:-}
|
|
||||||
- INIT_EMBEDDING_MODEL_NAME=${INIT_EMBEDDING_MODEL_NAME:-}
|
|
||||||
- INIT_EMBEDDING_MODEL_BASE_URL=${INIT_EMBEDDING_MODEL_BASE_URL:-}
|
|
||||||
- INIT_EMBEDDING_MODEL_API_KEY=${INIT_EMBEDDING_MODEL_API_KEY:-}
|
|
||||||
- INIT_EMBEDDING_MODEL_DIMENSION=${INIT_EMBEDDING_MODEL_DIMENSION:-}
|
|
||||||
- INIT_EMBEDDING_MODEL_ID=${INIT_EMBEDDING_MODEL_ID:-}
|
|
||||||
- INIT_RERANK_MODEL_NAME=${INIT_RERANK_MODEL_NAME:-}
|
|
||||||
- INIT_RERANK_MODEL_BASE_URL=${INIT_RERANK_MODEL_BASE_URL:-}
|
|
||||||
- INIT_RERANK_MODEL_API_KEY=${INIT_RERANK_MODEL_API_KEY:-}
|
|
||||||
# File size limit (in MB)
|
# File size limit (in MB)
|
||||||
- MAX_FILE_SIZE_MB=${MAX_FILE_SIZE_MB:-50}
|
- MAX_FILE_SIZE_MB=${MAX_FILE_SIZE_MB:-50}
|
||||||
|
# Agent Skills Sandbox
|
||||||
|
- WEKNORA_SANDBOX_MODE=${WEKNORA_SANDBOX_MODE:-docker}
|
||||||
|
- WEKNORA_SANDBOX_TIMEOUT=${WEKNORA_SANDBOX_TIMEOUT:-60}
|
||||||
|
- WEKNORA_SANDBOX_DOCKER_IMAGE=${WEKNORA_SANDBOX_DOCKER_IMAGE:-wechatopenai/weknora-sandbox:${WEKNORA_VERSION:-latest}}
|
||||||
|
- APK_MIRROR_ARG=${APK_MIRROR_ARG:-}
|
||||||
depends_on:
|
depends_on:
|
||||||
redis:
|
redis:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
@@ -122,6 +116,17 @@ services:
|
|||||||
extra_hosts:
|
extra_hosts:
|
||||||
- "host.docker.internal:host-gateway"
|
- "host.docker.internal:host-gateway"
|
||||||
|
|
||||||
|
# Sandbox 镜像:仅用于 build/pull,非常驻服务;app 执行 Skills 时按需 docker run 该镜像,用毕即释
|
||||||
|
sandbox:
|
||||||
|
image: wechatopenai/weknora-sandbox:${WEKNORA_VERSION:-latest}
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: docker/Dockerfile.sandbox
|
||||||
|
profiles:
|
||||||
|
- sandbox
|
||||||
|
command: ["true"]
|
||||||
|
restart: "no"
|
||||||
|
|
||||||
docreader:
|
docreader:
|
||||||
image: wechatopenai/weknora-docreader:${WEKNORA_VERSION:-latest}
|
image: wechatopenai/weknora-docreader:${WEKNORA_VERSION:-latest}
|
||||||
build:
|
build:
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export interface SkillInfo {
|
|||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取预装Skills列表
|
// 获取预装Skills列表;skills_available 为 false 表示沙箱未启用,前端应隐藏/禁用 Skills 配置
|
||||||
export function listSkills() {
|
export function listSkills() {
|
||||||
return get<{ data: SkillInfo[] }>('/api/v1/skills');
|
return get<{ data: SkillInfo[]; skills_available?: boolean }>('/api/v1/skills');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1069,6 +1069,8 @@ const allModels = ref<ModelConfig[]>([]);
|
|||||||
const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq'; count?: number }[]>([]);
|
const kbOptions = ref<{ label: string; value: string; type?: 'document' | 'faq'; count?: number }[]>([]);
|
||||||
const mcpOptions = ref<{ label: string; value: string }[]>([]);
|
const mcpOptions = ref<{ label: string; value: string }[]>([]);
|
||||||
const skillOptions = ref<{ name: string; description: string }[]>([]);
|
const skillOptions = ref<{ name: string; description: string }[]>([]);
|
||||||
|
// 是否允许启用 Skills(取决于后端沙箱是否启用,disabled 时为 false;未请求前为 false 避免闪显)
|
||||||
|
const skillsAvailable = ref(false);
|
||||||
|
|
||||||
// 系统默认配置(用于内置智能体显示默认提示词)
|
// 系统默认配置(用于内置智能体显示默认提示词)
|
||||||
const defaultAgentSystemPrompt = ref(''); // Agent 模式的默认系统提示词(来自 agent-config)
|
const defaultAgentSystemPrompt = ref(''); // Agent 模式的默认系统提示词(来自 agent-config)
|
||||||
@@ -1236,8 +1238,8 @@ const navItems = computed(() => {
|
|||||||
if (isAgentMode.value) {
|
if (isAgentMode.value) {
|
||||||
items.push({ key: 'tools', icon: 'tools', label: t('agent.editor.toolsConfig') || '工具配置' });
|
items.push({ key: 'tools', icon: 'tools', label: t('agent.editor.toolsConfig') || '工具配置' });
|
||||||
}
|
}
|
||||||
// Agent模式才显示Skills配置
|
// Agent 模式且沙箱已启用时才显示 Skills 配置(disabled 时无法启用 Skills)
|
||||||
if (isAgentMode.value) {
|
if (isAgentMode.value && skillsAvailable.value) {
|
||||||
items.push({ key: 'skills', icon: 'lightbulb', label: t('agent.editor.skillsConfig') });
|
items.push({ key: 'skills', icon: 'lightbulb', label: t('agent.editor.skillsConfig') });
|
||||||
}
|
}
|
||||||
// 有知识库能力时才显示检索策略
|
// 有知识库能力时才显示检索策略
|
||||||
@@ -1646,14 +1648,16 @@ const loadDependencies = async () => {
|
|||||||
console.warn('Failed to load MCP services', e);
|
console.warn('Failed to load MCP services', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载预装 Skills 列表
|
// 加载预装 Skills 列表及沙箱可用性(skills_available=false 时前端不展示 Skills 配置)
|
||||||
try {
|
try {
|
||||||
const skillsRes = await listSkills();
|
const skillsRes = await listSkills();
|
||||||
|
skillsAvailable.value = skillsRes.skills_available !== false;
|
||||||
if (skillsRes.data && skillsRes.data.length > 0) {
|
if (skillsRes.data && skillsRes.data.length > 0) {
|
||||||
skillOptions.value = skillsRes.data;
|
skillOptions.value = skillsRes.data;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to load skills', e);
|
console.warn('Failed to load skills', e);
|
||||||
|
skillsAvailable.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载占位符定义(从统一 API)
|
// 加载占位符定义(从统一 API)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Tencent/WeKnora/internal/agent/tools"
|
"github.com/Tencent/WeKnora/internal/agent/tools"
|
||||||
@@ -856,6 +857,15 @@ func (s *sessionService) configureSkillsFromAgent(
|
|||||||
if customAgent == nil {
|
if customAgent == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// When sandbox is disabled, skills cannot be enabled (no script execution environment)
|
||||||
|
sandboxMode := os.Getenv("WEKNORA_SANDBOX_MODE")
|
||||||
|
if sandboxMode == "" || sandboxMode == "disabled" {
|
||||||
|
agentConfig.SkillsEnabled = false
|
||||||
|
agentConfig.SkillDirs = nil
|
||||||
|
agentConfig.AllowedSkills = nil
|
||||||
|
logger.Infof(ctx, "Sandbox is disabled: skills are not available")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch customAgent.Config.SkillsSelectionMode {
|
switch customAgent.Config.SkillsSelectionMode {
|
||||||
case "all":
|
case "all":
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/Tencent/WeKnora/internal/errors"
|
"github.com/Tencent/WeKnora/internal/errors"
|
||||||
"github.com/Tencent/WeKnora/internal/logger"
|
"github.com/Tencent/WeKnora/internal/logger"
|
||||||
@@ -57,8 +58,13 @@ func (h *SkillHandler) ListSkills(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skills_available: true only when sandbox is enabled (docker or local), so frontend can hide/disable Skills UI
|
||||||
|
sandboxMode := os.Getenv("WEKNORA_SANDBOX_MODE")
|
||||||
|
skillsAvailable := sandboxMode != "" && sandboxMode != "disabled"
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"success": true,
|
"success": true,
|
||||||
"data": response,
|
"data": response,
|
||||||
|
"skills_available": skillsAvailable,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user