feat(app-instance): 集成Beaver后端并更新配置管理
集成新的Beaver后端服务到应用实例中,替换原有的nanobot实现。 主要变更包括: - 在Dockerfile和环境配置中添加Beaver相关路径和配置变量 - 更新工作目录结构从.nanobot到.beaver - 实现Beaver引擎加载器,支持配置文件加载和工具组装 - 添加内置工具如ListDirectoryTool、ReadFileTool、SearchFilesTool - 更新消息处理流程,支持通道适配器和网关模式 - 重构技能系统,支持显式工具提示和嵌入式检索 - 改进错误处理和生命周期管理 此变更使应用实例能够使用统一的Beaver后端进行AI代理运行时管理。
This commit is contained in:
@ -4,9 +4,12 @@ set -euo pipefail
|
||||
APP_PUBLIC_PORT="${APP_PUBLIC_PORT:-8080}"
|
||||
APP_FRONTEND_PORT="${APP_FRONTEND_PORT:-3000}"
|
||||
APP_BACKEND_PORT="${APP_BACKEND_PORT:-18080}"
|
||||
NANOBOT_HOME="${NANOBOT_HOME:-/root/.nanobot}"
|
||||
NANOBOT_AUTH_FILE="${NANOBOT_AUTH_FILE:-$NANOBOT_HOME/web_auth_users.json}"
|
||||
NANOBOT_RUNTIME_ENV_FILE="${NANOBOT_RUNTIME_ENV_FILE:-$NANOBOT_HOME/runtime.env}"
|
||||
BEAVER_HOME="${BEAVER_HOME:-/root/.beaver}"
|
||||
BEAVER_CONFIG_PATH="${BEAVER_CONFIG_PATH:-$BEAVER_HOME/config.json}"
|
||||
BEAVER_WORKSPACE="${BEAVER_WORKSPACE:-$BEAVER_HOME/workspace}"
|
||||
NANOBOT_HOME="${NANOBOT_HOME:-$BEAVER_HOME}"
|
||||
NANOBOT_AUTH_FILE="${NANOBOT_AUTH_FILE:-$BEAVER_HOME/web_auth_users.json}"
|
||||
NANOBOT_RUNTIME_ENV_FILE="${NANOBOT_RUNTIME_ENV_FILE:-$BEAVER_HOME/runtime.env}"
|
||||
|
||||
log() {
|
||||
printf '[app-instance] %s\n' "$*"
|
||||
@ -21,40 +24,6 @@ require_file() {
|
||||
fi
|
||||
}
|
||||
|
||||
render_swarms_env_file() {
|
||||
local config_path="$1"
|
||||
local target_path="$2"
|
||||
|
||||
CONFIG_PATH="$config_path" TARGET_PATH="$target_path" python3 - <<'PY'
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
config_path = Path(os.environ["CONFIG_PATH"])
|
||||
target_path = Path(os.environ["TARGET_PATH"])
|
||||
|
||||
data = json.loads(config_path.read_text(encoding="utf-8"))
|
||||
model = str(data.get("agents", {}).get("defaults", {}).get("model") or "").strip()
|
||||
if model and "/" not in model:
|
||||
model = f"openai/{model}"
|
||||
provider_cfg = data.get("providers", {}).get("openai", {}) or {}
|
||||
api_key = str(provider_cfg.get("apiKey") or "").strip()
|
||||
api_base = str(provider_cfg.get("apiBase") or "").strip()
|
||||
|
||||
lines = [
|
||||
'# Generated from /root/.nanobot/config.json for vendored swarms runtime.',
|
||||
'WORKSPACE_DIR="/root/.nanobot/workspace"',
|
||||
'SWARMS_VERBOSE_GLOBAL="False"',
|
||||
'SWARMS_TELEMETRY_ON="false"',
|
||||
f'SWARMS_DEFAULT_MODEL="{model}"',
|
||||
f'OPENAI_API_KEY="{api_key}"',
|
||||
f'OPENAI_API_BASE="{api_base}"',
|
||||
f'OPENAI_BASE_URL="{api_base}"',
|
||||
]
|
||||
target_path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
PY
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
local status=$?
|
||||
|
||||
@ -74,7 +43,7 @@ cleanup() {
|
||||
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
mkdir -p "$NANOBOT_HOME" "$NANOBOT_HOME/workspace"
|
||||
mkdir -p "$BEAVER_HOME" "$BEAVER_WORKSPACE"
|
||||
|
||||
if [[ -f "$NANOBOT_RUNTIME_ENV_FILE" ]]; then
|
||||
set -a
|
||||
@ -82,24 +51,21 @@ if [[ -f "$NANOBOT_RUNTIME_ENV_FILE" ]]; then
|
||||
set +a
|
||||
fi
|
||||
|
||||
require_file "$NANOBOT_HOME/config.json" "Missing Boardware Genius config"
|
||||
require_file "$NANOBOT_AUTH_FILE" "Missing web auth users file"
|
||||
|
||||
SWARMS_ENV_FILE="/opt/app/backend/third_party/swarms/.env"
|
||||
render_swarms_env_file "$NANOBOT_HOME/config.json" "$SWARMS_ENV_FILE"
|
||||
if [[ -f "$SWARMS_ENV_FILE" ]]; then
|
||||
set -a
|
||||
. "$SWARMS_ENV_FILE"
|
||||
set +a
|
||||
fi
|
||||
require_file "$BEAVER_CONFIG_PATH" "Missing Beaver config"
|
||||
|
||||
export NANOBOT_AUTH_FILE
|
||||
export NANOBOT_RUNTIME_ENV_FILE
|
||||
export BEAVER_HOME
|
||||
export BEAVER_CONFIG_PATH
|
||||
export BEAVER_WORKSPACE
|
||||
export PORT="$APP_FRONTEND_PORT"
|
||||
export HOSTNAME="127.0.0.1"
|
||||
|
||||
log "starting backend on 127.0.0.1:${APP_BACKEND_PORT}"
|
||||
nanobot web --host 127.0.0.1 --port "$APP_BACKEND_PORT" &
|
||||
log "starting Beaver backend on 127.0.0.1:${APP_BACKEND_PORT}"
|
||||
(
|
||||
cd /opt/app/backend
|
||||
python -m uvicorn "beaver.interfaces.web.app:create_app" --factory --host 127.0.0.1 --port "$APP_BACKEND_PORT"
|
||||
) &
|
||||
BACKEND_PID=$!
|
||||
|
||||
log "starting frontend on 127.0.0.1:${APP_FRONTEND_PORT}"
|
||||
|
||||
Reference in New Issue
Block a user