Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

feat: 支持一键进程部署基于yuanrong的gateway+jiuwenswarm函数

tianmengyue4b2afc168eb7
diff --git a/deploy/extensions/agent_client/__init__.py b/deploy/extensions/agent_client/__init__.py
deleted file mode 100644
index 9029db0aef..0000000000
--- a/deploy/extensions/agent_client/__init__.py
+++ /dev/null
@@ -1,3 +0,0 @@
-from jiuwenswarm.extensions.agent_client.extension import register_extensions
-
-__all__ = ["register_extensions"]
diff --git a/deploy/yuanrong/.env.example b/deploy/yuanrong/.env.example
new file mode 100644
index 0000000000..5d5f46f7fb
--- /dev/null
+++ b/deploy/yuanrong/.env.example
@@ -0,0 +1,96 @@
+# ====================== 集群主机配置 ======================
+# 目标主机IP列表,逗号分隔。第一个IP为yr master节点,其余为agent节点
+# 单机部署示例:CLUSTER_HOSTS="192.168.1.1"
+# 多机部署示例:CLUSTER_HOSTS="192.168.1.1,192.168.1.2,192.168.1.3"
+# 也可通过命令行 --hosts 参数指定,命令行参数优先级更高
+# 不设置时默认使用本机IP
+CLUSTER_HOSTS=""
+
+# Python版本(用于远程安装 openYuanrong 依赖)
+YR_PYTHON_VERSION="3.11"
+
+# jiuwenswarm 函数代码目录(远程主机上的路径)
+# 留空则自动从远程主机pip安装路径推断:$(pip show jiuwenswarm Location)/jiuwenswarm/extensions
+# 如果推断失败,需要手动设置此值
+YR_FUNC_CODE_DIR=""
+
+# jiuwenswarm 安装包 URL(远程主机未安装 jiuwenswarm 时使用此URL进行pip安装)
+# 示例:JIUWENSWARM_PACKAGE_URL="https://example.com/jiuwenswarm-0.1.0-py3-none-any.whl"
+# 如果远程主机已安装 jiuwenswarm,此配置不需要设置
+JIUWENSWARM_PACKAGE_URL=""
+
+# ====================== 函数服务配置 ======================
+# 函数服务名称
+FUNC_SVC_NAME="0@jiuwen@swarm"
+
+# 单实例CPU限制(单位:毫核,300=0.3核)
+MGR_CPU=300
+
+# 单实例内存限制(单位:Mi)
+MGR_MEMORY=600
+
+# 服务最小实例数
+MGR_MIN_INSTANCE=1
+
+# 服务最大实例数
+MGR_MAX_INSTANCE=10
+
+# 服务并发处理数量/最大并发数
+MGR_CONCURRENT_NUM=10
+
+# ====================== Gateway配置 ======================
+# jiuwenswarm 实例名(留空则使用默认路径 ~/.jiuwenswarm)
+# 如果指定了实例名,配置目录变为 ~/.jiuwenswarm-instances/<实例名>
+JIUWENSWARM_INSTANCE_NAME=""
+
+# 网关同时向后端发送的最大并发请求数
+GATEWAY_CONCURRENCY=1
+
+# 网关调用后端接口的超时时间(秒)
+GATEWAY_INVOKE_TIMEOUT=60
+
+# SessionMap 会话映射策略
+# 可选值:per_chat_bot(同聊天窗口+机器人共享会话)、per_chat_bot_user(按用户维度隔离会话)
+GATEWAY_SESSION_MAP_SCOPE="per_chat_bot_user"
+
+# 扩展包搜索目录(远程主机上的路径,多个目录用分号;分隔)
+# 留空则自动从 jiuwenswarm 安装路径推断:<pip_location>/jiuwenswarm/extensions
+# 如需自定义,可设置完整路径,多个目录用分号分隔
+# 示例:EXTENSION_DIRS="/opt/pip_location/jiuwenswarm/extensions;/opt/my_extensions"
+EXTENSION_DIRS=""
+
+# ====================== Gateway独立部署配置 ======================
+# 以下配置仅在单独部署 gateway 时需要手动设置
+# 如果先部署 openYuanrong 再部署 gateway,这些值会自动获取,无需手动设置
+
+# Master节点IP(单独部署 gateway 时需要指定)
+MASTER_NODE_IP=""
+
+# 元戎Frontend端口(单独部署 gateway 时需要指定,默认8888)
+FRONTEND_PORT=""
+
+# 函数ID(单独部署 gateway 时需要指定,由 openYuanrong 注册函数后返回)
+FUNCTION_ID=""
+
+# ====================== 大模型接口配置 ======================
+# 模型厂商标识(如:OpenAI等)
+MODEL_PROVIDER=""
+
+# 大模型名称
+MODEL_NAME=""
+
+# 大模型API基础地址
+API_BASE=""
+
+# 大模型鉴权密钥
+API_KEY=""
+
+# ====================== 向量模型接口配置 ======================
+# 向量模型名称
+EMBED_MODEL=""
+
+# 向量模型API基础地址
+EMBED_API_BASE=""
+
+# 向量模型鉴权密钥
+EMBED_API_KEY=""
diff --git a/deploy/yuanrong/README.md b/deploy/yuanrong/README.md
new file mode 100644
index 0000000000..571e6af8d4
--- /dev/null
+++ b/deploy/yuanrong/README.md
@@ -0,0 +1,219 @@
+# JiuwenSwarm 分布式一键部署方案
+
+## 简介
+
+openYuanrong 是一个 Serverless 分布式计算引擎,旨在为分布式应用提供高性能运行和集群资源的高效利用。基于此引擎,我们打造了 JiuwenSwarm 分布式一键部署方案。
+
+基于 openYuanrong 进程部署模式,对 JiuwenSwarm 进行函数化部署,并以进程方式部署 gateway,无需 K8s 集群,适合快速体验和轻量级部署场景。
+
+## 前置要求
+
+- **openyuanrong 已正常安装部署**:执行本脚本前,需确保 openyuanrong 已在所有目标主机上安装并启动,集群处于正常运行状态。
+- 操作系统:Linux
+- 系统架构:amd64 或 arm64
+- 硬件资源:单机最低配置为 16 核 CPU 及 32GB 内存
+- 网络要求:部署机器到目标主机需配置 SSH 免密登录
+
+您可以通过以下命令检查:
+
+```
+# 操作系统
+uname -s
+# 系统架构
+uname -m
+# CPU核心数
+nproc
+# 检查内存大小 (GB)
+free -g | grep Mem | awk '{print $2}'
+```
+
+配置部署机器到所有目标主机的免密 SSH 登录:
+
+```
+ssh-copy-id root@<目标主机IP>
+```
+
+## 配置
+
+参考部署目录下 [.env.example](.env.example) 配置模板,按需修改环境变量、运行模式等自定义参数,完成业务与环境适配。将配置文件复制为 `.env.custom` 后修改:
+
+```
+cp .env.example .env.custom
+vim .env.custom
+```
+
+### 配置项说明
+
+#### 集群主机配置
+
+| 变量 | 说明 | 默认值 |
+| ------------------- | ------------------------------------------------------------------------------------------------ | ------ |
+| `CLUSTER_HOSTS` | 目标主机 IP 列表,逗号分隔。第一个 IP 为 yr master 节点,其余为 agent 节点。也可通过命令行 `--hosts` 参数指定,命令行优先级更高。不设置时默认使用本机 IP | `""` |
+| `YR_PYTHON_VERSION` | Python 版本,用于远程安装 jiuwenswarm 依赖(当前仅支持3.11) | `3.11` |
+
+#### jiuwenswarm 配置
+
+| 变量 | 说明 | 默认值 |
+| ------------------------- | ------------------------------------------------------------------------------------------------------------ | ---- |
+| `YR_FUNC_CODE_DIR` | jiuwenswarm 函数代码目录(远程主机上的路径)。留空则自动从远程主机 pip 安装路径推断:`$(pip show jiuwenswarm Location)/jiuwenswarm/extensions` | `""` |
+| `JIUWENSWARM_PACKAGE_URL` | jiuwenswarm 安装包 URL(远程主机未安装 jiuwenswarm 时使用此 URL 进行 pip 安装)。如果远程主机已安装 jiuwenswarm,此配置不需要设置 | `""` |
+
+#### 函数服务配置
+
+| 变量 | 说明 | 默认值 |
+| -------------------- | --------------------------- |------------------|
+| `FUNC_SVC_NAME` | 函数服务名称 | `0@jiuwen@swarm` |
+| `MGR_CPU` | 单实例 CPU 限制(单位:毫核,300=0.3 核) | `300` |
+| `MGR_MEMORY` | 单实例内存限制(单位:Mi) | `600` |
+| `MGR_MIN_INSTANCE` | 服务最小实例数 | `1` |
+| `MGR_MAX_INSTANCE` | 服务最大实例数 | `10` |
+| `MGR_CONCURRENT_NUM` | 服务并发处理数量/最大并发数 | `10` |
+
+#### Gateway 配置
+
+| 变量 | 说明 | 默认值 |
+| --------------------------- | -------------------------------------------------------------------------------------------------- | ------------------- |
+| `JIUWENSWARM_INSTANCE_NAME` | jiuwenswarm 实例名(留空则使用默认路径 `~/.jiuwenswarm`)。指定实例名后配置目录变为 `~/.jiuwenswarm-instances/<实例名>` | `""` |
+| `GATEWAY_CONCURRENCY` | 网关同时向后端发送的最大并发请求数 | `1` |
+| `GATEWAY_INVOKE_TIMEOUT` | 网关调用后端接口的超时时间(秒) | `60` |
+| `GATEWAY_SESSION_MAP_SCOPE` | SessionMap 会话映射策略。可选值:`per_chat_bot`(同聊天窗口+机器人共享会话)、`per_chat_bot_user`(按用户维度隔离会话) | `per_chat_bot_user` |
+| `EXTENSION_DIRS` | 扩展包搜索目录(远程主机上的路径,多个目录用分号 `;` 分隔)。留空则自动从 jiuwenswarm 安装路径推断:`<pip_location>/jiuwenswarm/extensions` | `""` |
+
+#### Gateway 独立部署配置
+
+以下配置仅在单独部署 gateway 时需要手动设置。如果先部署 jiuwenswarm 再部署 gateway,这些值会自动获取,无需手动设置。
+
+| 变量 | 说明 | 默认值 |
+| ---------------- | ----------------------------------------------- | ---- |
+| `MASTER_NODE_IP` | Master 节点 IP(单独部署 gateway 时需要指定) | `""` |
+| `FRONTEND_PORT` | 元戎 Frontend 端口(单独部署 gateway 时需要指定,默认 8888) | `""` |
+| `FUNCTION_ID` | 函数 ID(单独部署 gateway 时需要指定,由 jiuwenswarm 注册函数后返回) | `""` |
+
+#### 大模型接口配置
+
+| 变量 | 说明 | 默认值 |
+| ---------------- | ------------------ | ---- |
+| `MODEL_PROVIDER` | 模型厂商标识(如:OpenAI 等) | `""` |
+| `MODEL_NAME` | 大模型名称 | `""` |
+| `API_BASE` | 大模型 API 基础地址 | `""` |
+| `API_KEY` | 大模型鉴权密钥 | `""` |
+
+#### 向量模型接口配置
+
+| 变量 | 说明 | 默认值 |
+| ---------------- | ------------- | ---- |
+| `EMBED_MODEL` | 向量模型名称 | `""` |
+| `EMBED_API_BASE` | 向量模型 API 基础地址 | `""` |
+| `EMBED_API_KEY` | 向量模型鉴权密钥 | `""` |
+
+## 使用方法
+
+### 一键部署
+
+```
+# 部署所有模块(jiuwenswarm + gateway),默认本机
+./deploy.sh up
+
+# 指定主机部署所有模块
+./deploy.sh up --hosts 192.168.1.1
+
+# 仅部署 jiuwenswarm 模块(安装jiuwenswarm + 函数注册)
+./deploy.sh up jiuwenswarm --hosts 192.168.1.1
+
+# 仅部署 gateway 模块(需先部署 jiuwenswarm 或在 .env.custom 中配置 FUNCTION_ID 等参数)
+./deploy.sh up gateway --hosts 192.168.1.1
+
+# 多机部署(第一个IP为yr master,其余为agent)
+./deploy.sh up --hosts 192.168.1.1,192.168.1.2,192.168.1.3
+```
+
+### 一键卸载
+
+```
+# 卸载所有模块
+./deploy.sh down --hosts 192.168.1.1
+
+# 仅卸载 gateway
+./deploy.sh down gateway --hosts 192.168.1.1
+
+# 仅卸载 jiuwenswarm
+./deploy.sh down jiuwenswarm --hosts 192.168.1.1
+```
+
+### 一键重启
+
+```
+./deploy.sh restart --hosts 192.168.1.1
+```
+
+## 参数解析
+
+命令格式:
+
+```
+./deploy.sh [操作命令(必填)] [模块列表(选填)] [配置参数(选填)]
+```
+
+### 操作命令(必填)
+
+部署工具支持三种核心操作,用于管理服务生命周期:
+
+- `up`:部署并启动指定的业务模块
+- `down`:停止并卸载指定的业务模块
+- `restart`:重启指定的业务模块
+
+基础用法(无模块参数):
+
+```
+./deploy.sh up --hosts 192.168.1.1 # 部署所有模块(jiuwenswarm + gateway)
+./deploy.sh down --hosts 192.168.1.1 # 卸载所有模块
+./deploy.sh restart --hosts 192.168.1.1 # 重启所有模块
+```
+
+### 模块列表(选填)
+
+部署工具支持对以下两个独立模块进行精细化管理:
+
+- `jiuwenswarm`:在所有 host 上安装 jiuwenswarm + 在 yr master 节点注册函数
+- `gateway`:jiuwenswarm Gateway 服务(进程模式)
+
+单模块操作示例:
+
+```
+./deploy.sh [操作命令] jiuwenswarm --hosts 192.168.1.1 # 仅操作 jiuwenswarm 模块
+./deploy.sh [操作命令] gateway --hosts 192.168.1.1 # 仅操作 gateway 模块
+```
+
+当未指定模块参数时,默认按 `jiuwenswarm → gateway` 顺序依次部署两个模块。
+
+### 配置参数(选填)
+
+- `--hosts`:指定集群主机 IP 列表,逗号分隔。第一个 IP 为 yr master 节点,其余为 agent 节点。也可在 `.env.custom` 中通过 `CLUSTER_HOSTS` 配置,命令行参数优先级更高。不指定时默认使用本机 IP
+- `-h, --help`:显示帮助信息
+
+参数使用示例:
+
+```
+./deploy.sh up --hosts 192.168.1.1 # 单机部署所有模块
+./deploy.sh up --hosts 192.168.1.1,192.168.1.2,192.168.1.3 # 多机部署所有模块
+./deploy.sh up jiuwenswarm --hosts 192.168.1.1 # 单机仅部署 jiuwenswarm
+./deploy.sh down gateway --hosts 192.168.1.1 # 仅卸载 gateway
+./deploy.sh up # 默认本机部署所有模块
+```
+
+## 重要约束
+
+- **前置条件**:执行 deploy.sh 前需确保 openyuanrong 已在所有目标主机上正常安装并启动
+- **jiuwenswarm 模块**:在所有 host 上安装 jiuwenswarm,但函数注册只在 yr master 节点(第一个 IP)执行
+- **gateway 模块**:依赖 jiuwenswarm 模块部署后产生的 `FUNCTION_ID`、`FRONTEND_PORT` 等参数。如果单独部署 gateway,需在 `.env.custom` 中手动配置这些参数
+- **部署顺序**:同时部署时,jiuwenswarm 先于 gateway 部署;卸载时,gateway 先于 jiuwenswarm 卸载
+- **down jiuwenswarm**:仅删除 yr master 上注册的函数元信息,不卸载 jiuwenswarm pip 包、不停止 openyuanrong 集群
+
+## Gateway 实例配置
+
+通过 `.env.custom` 中的 `JIUWENSWARM_INSTANCE_NAME` 可配置 gateway 实例名:
+
+- 未设置实例名(默认):gateway 使用默认路径 `~/.jiuwenswarm/config/config.yaml`
+- 设置实例名(如 `JIUWENSWARM_INSTANCE_NAME=prod`):gateway 使用实例路径 `~/.jiuwenswarm-instances/prod/config/config.yaml`
+
+实例名配置后,`jiuwenswarm-init` 和 `jiuwenswarm-gateway` 命令会自动通过 `JIUWENSWARM_DATA_DIR` 环境变量指向对应的实例目录。
diff --git a/deploy/yuanrong/args_handler.sh b/deploy/yuanrong/args_handler.sh
new file mode 100755
index 0000000000..a64f404245
--- /dev/null
+++ b/deploy/yuanrong/args_handler.sh
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+parse_args() {
+ local i=0
+ local args=("$@")
+
+ while [ $i -lt ${#args[@]} ]; do
+ case "${args[$i]}" in
+ up|down|restart)
+ CMD="${args[$i]}"
+ i=$((i+1))
+ ;;
+ jiuwenswarm|gateway)
+ MODULES+=("${args[$i]}")
+ i=$((i+1))
+ ;;
+ --hosts)
+ DEPLOY_VARS["CLUSTER_HOSTS"]="${args[$((i+1))]}"
+ i=$((i+2))
+ ;;
+ -h|--help)
+ print_help
+ ;;
+ *)
+ error "Invalid Args: ${args[$i]}"
+ ;;
+ esac
+ done
+
+ if [ -z "${CMD:-}" ]; then
+ error "Command not specified! Use 'up' or 'down'"
+ exit 1
+ fi
+
+ if [ ${#MODULES[@]} -eq 0 ]; then
+ MODULES=("jiuwenswarm" "gateway")
+ fi
+
+ info "Executing command: $*"
+ info "CMD=${CMD}"
+ info "MODULES=${MODULES[@]}"
+ info "CLUSTER_HOSTS=${DEPLOY_VARS["CLUSTER_HOSTS"]}"
+}
+
+print_help() {
+ cat << EOF
+Usage: ./$(basename "$0") [COMMAND] [MODULES...] [OPTIONS]
+
+Commands (Required):
+ up Deploy and start specified modules
+ down Stop and uninstall specified modules
+ restart Restart specified modules
+
+Modules (Optional, default: jiuwenswarm gateway):
+ jiuwenswarm Install jiuwenswarm on all hosts + register function on yr master
+ gateway jiuwenswarm gateway service (process-mode)
+
+Options:
+ --hosts HOSTS Comma-separated IP list for cluster hosts (default: local machine IP)
+ Single machine: --hosts 192.168.1.1
+ Multi-machine: --hosts 192.168.1.1,192.168.1.2,192.168.1.3
+ First IP is yr master node, others are agent nodes
+ If not specified, defaults to local machine IP
+ Can also be set in .env.custom via CLUSTER_HOSTS
+ -h, --help Display this help message and exit
+
+Prerequisites:
+ yuanrong must be already deployed on all hosts (use yuanrong_deploy.sh up --hosts ...)
+
+Examples:
+ ./$(basename "$0") up --hosts 192.168.1.1 # Deploy all (jiuwenswarm + gateway)
+ ./$(basename "$0") up jiuwenswarm --hosts 192.168.1.1 # Deploy jiuwenswarm only
+ ./$(basename "$0") up gateway --hosts 192.168.1.1 # Deploy gateway only
+ ./$(basename "$0") up # Deploy all on local machine
+ ./$(basename "$0") down --hosts 192.168.1.1 # Stop all
+ ./$(basename "$0") down gateway --hosts 192.168.1.1 # Stop gateway only
+ ./$(basename "$0") restart --hosts 192.168.1.1 # Restart all
+EOF
+ exit 0
+}
diff --git a/deploy/yuanrong/check_handler.sh b/deploy/yuanrong/check_handler.sh
new file mode 100755
index 0000000000..a4b82997ca
--- /dev/null
+++ b/deploy/yuanrong/check_handler.sh
@@ -0,0 +1,112 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+check_cmd() {
+ if command -v "$1" >/dev/null 2>&1; then
+ success "$1 is OK."
+ else
+ error "$1 is not installed. Please install it first."
+ fi
+}
+
+detect_os() {
+ if [ "$(uname -s)" != "Linux" ]; then
+ error "Unsupported OS: $(uname -s)"
+ fi
+ DEPLOY_VARS["OS_TYPE"]="linux"
+}
+
+check_if_root() {
+ if [[ ${EUID} -ne 0 ]]; then
+ error "This script must be run as root (sudo)."
+ fi
+}
+
+get_local_ip() {
+ local local_ips
+ local_ips=$(hostname -I 2>/dev/null || echo "")
+ for ip in ${local_ips}; do
+ if [ "${ip}" != "127.0.0.1" ] && [ "${ip}" != "localhost" ]; then
+ echo "${ip}"
+ return 0
+ fi
+ done
+ echo "127.0.0.1"
+}
+
+check_cmds() {
+ for cmd in python3 jq; do
+ check_cmd ${cmd}
+ done
+
+ local hosts_str="${DEPLOY_VARS["CLUSTER_HOSTS"]:-}"
+ local need_ssh=false
+ if [ -n "${hosts_str}" ]; then
+ IFS=',' read -ra _host_list <<< "${hosts_str}"
+ for h in "${_host_list[@]}"; do
+ if [ "${h}" != "127.0.0.1" ] && [ "${h}" != "localhost" ]; then
+ local local_ips
+ local_ips=$(hostname -I 2>/dev/null || echo "")
+ local is_local=false
+ for ip in ${local_ips}; do
+ if [ "${h}" = "${ip}" ]; then
+ is_local=true
+ break
+ fi
+ done
+ if [ "${is_local}" = "false" ]; then
+ need_ssh=true
+ break
+ fi
+ fi
+ done
+ fi
+ if [ "${need_ssh}" = "true" ]; then
+ check_cmd ssh
+ fi
+}
+
+check_jiuwenswarm_up_dependency() {
+ local hosts_str="${DEPLOY_VARS["CLUSTER_HOSTS"]}"
+
+ if [ -z "${hosts_str}" ]; then
+ hosts_str=$(get_local_ip)
+ DEPLOY_VARS["CLUSTER_HOSTS"]="${hosts_str}"
+ warning "CLUSTER_HOSTS not set, using local IP: ${hosts_str}"
+ fi
+
+ IFS=',' read -ra HOST_LIST <<< "${hosts_str}"
+ if [ ${#HOST_LIST[@]} -eq 0 ]; then
+ error "CLUSTER_HOSTS is empty. Please specify at least one host IP"
+ fi
+
+ info "CLUSTER_HOSTS validated: ${hosts_str} (${#HOST_LIST[@]} host(s))"
+ info "Note: yuanrong is assumed to be already deployed on all hosts"
+}
+
+check_gateway_up_dependency() {
+ if [ -z "${DEPLOY_VARS["MASTER_NODE_IP"]:-}" ]; then
+ if [ -n "${DEPLOY_VARS["CLUSTER_HOSTS"]:-}" ]; then
+ IFS=',' read -ra _gw_host_list <<< "${DEPLOY_VARS["CLUSTER_HOSTS"]}"
+ DEPLOY_VARS["MASTER_NODE_IP"]="${_gw_host_list[0]}"
+ info "MASTER_NODE_IP inferred from CLUSTER_HOSTS: ${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ else
+ error "MASTER_NODE_IP is not set. Please set it in .env.custom or deploy jiuwenswarm first."
+ fi
+ fi
+
+ if [ -z "${DEPLOY_VARS["FRONTEND_PORT"]:-}" ]; then
+ DEPLOY_VARS["FRONTEND_PORT"]="8888"
+ warning "FRONTEND_PORT not set, using default: 8888"
+ fi
+
+ if [ -z "${DEPLOY_VARS["FUNCTION_ID"]:-}" ]; then
+ error "FUNCTION_ID is not set. Please deploy jiuwenswarm first or set FUNCTION_ID in .env.custom."
+ fi
+}
+
+check_dependency() {
+ detect_os
+ check_cmds
+ check_if_root
+}
diff --git a/deploy/yuanrong/cmd_handler.sh b/deploy/yuanrong/cmd_handler.sh
new file mode 100644
index 0000000000..3b69464d0c
--- /dev/null
+++ b/deploy/yuanrong/cmd_handler.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+# ===== Execute command with failure control: ====
+# ===== exit on error unless arg2 is 'false' (arg2 optional) ====
+exec_cmd() {
+ local fail_quit="true"
+ if [[ "${@: -1}" == "false" ]]; then
+ fail_quit="false"
+ set -- "${@:1:$#-1}"
+ fi
+ info "Executing: $*"
+
+ if [[ "${fail_quit}" == "false" ]]; then
+ "$@" || warning "Command failed (ignored)"
+ else
+ "$@" || error "Command failed"
+ fi
+}
\ No newline at end of file
diff --git a/deploy/yuanrong/common.sh b/deploy/yuanrong/common.sh
new file mode 100755
index 0000000000..dae1ada18c
--- /dev/null
+++ b/deploy/yuanrong/common.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+info() { echo -e "\033[36m=== $@ ===\033[0m"; }
+success() { echo -e "\033[32m✅ $@\033[0m"; }
+warning() { echo -e "\033[33m⚠️ $@\033[0m"; }
+error() { echo -e "\033[31m❌ $@\033[0m"; exit 1; }
+
+print_array() {
+ local array_name="$1"
+ local -n arr_ref="$1"
+
+ echo -e "\033[33m$ ${array_name}\033[0m"
+
+ if [[ ! "$(declare -p ${array_name})" =~ "declare -a" && ! "$(declare -p ${array_name})" =~ "declare -A" ]]; then
+ echo -e "\033[31m[ERROR] ${array_name} is not a bash array variable!\033[0m"
+ return 1
+ fi
+
+ for key in "${!arr_ref[@]}"; do
+ echo -e "\033[36m ├─ ${array_name}[${key}] = ${arr_ref[${key}]}\033[0m"
+ done
+
+ echo -e "\033[33m └─ Total elements count: ${#arr_ref[@]}\033[0m\n"
+}
diff --git a/deploy/yuanrong/conf/claw_meta_process.template.json b/deploy/yuanrong/conf/claw_meta_process.template.json
new file mode 100644
index 0000000000..d1a468a44e
--- /dev/null
+++ b/deploy/yuanrong/conf/claw_meta_process.template.json
@@ -0,0 +1,35 @@
+{
+ "name": "<<FUNC_SVC_NAME>>",
+ "runtime": "python<<YR_PYTHON_VERSION>>",
+ "description": "jiuwen swarm",
+ "handler": "clawee.handler",
+ "kind": "faas",
+ "cpu": <<MGR_CPU>>,
+ "memory": <<MGR_MEMORY>>,
+ "timeout": 600,
+ "customResources": {},
+ "environment": {
+ "MODEL_PROVIDER": "<<MODEL_PROVIDER>>",
+ "MODEL_NAME": "<<MODEL_NAME>>",
+ "API_BASE": "<<API_BASE>>",
+ "API_KEY": "<<API_KEY>>",
+ "EMBED_API_KEY": "<<EMBED_API_KEY>>",
+ "EMBED_API_BASE": "<<EMBED_API_BASE>>",
+ "EMBED_MODEL": "<<EMBED_MODEL>>"
+ },
+ "extendedHandler": {
+ "initializer": "clawee.init",
+ "pre_stop": "clawee.pre_stop"
+ },
+ "extendedTimeout": {
+ "initializer": 600,
+ "pre_stop": 10
+ },
+ "minInstance": "<<MGR_MIN_INSTANCE>>",
+ "maxInstance": "<<MGR_MAX_INSTANCE>>",
+ "concurrentNum": "<<MGR_CONCURRENT_NUM>>",
+ "storageType": "local",
+ "codePath": "<<YR_FUNC_CODE_DIR>>",
+ "s3CodePath": {},
+ "enableSessionCtx": true
+}
diff --git a/deploy/yuanrong/conf/gateway-config-yuanrong.template.yaml b/deploy/yuanrong/conf/gateway-config-yuanrong.template.yaml
new file mode 100644
index 0000000000..f489818103
--- /dev/null
+++ b/deploy/yuanrong/conf/gateway-config-yuanrong.template.yaml
@@ -0,0 +1,1048 @@
+# 前端显示语言:zh(中文)/ en(英文),与 Web 界面语言切换同步
+preferred_language: zh
+
+# auto-recap:用户空闲5分钟后自动生成会话摘要(TUI 端)
+auto_recap:
+ enabled: true
+
+a2ui:
+ enabled: false
+ protocol_version: "0.8"
+ stream_validation_enabled: true
+ non_web_fallback_enabled: false
+ dev_smoke_tools_enabled: false
+
+symphony:
+ enabled: false
+ paths:
+ skills_root: ""
+ score_dir: ""
+
+ fingerprint:
+ scan:
+ max_depth:
+ extraction:
+ workers: 4
+ batch_size: 2
+ body_limit:
+ normalization:
+ workers: 4
+ batch_size: 2
+ duplicate_name_similarity_threshold: 0.8
+ max_vocab_size:
+
+ build:
+ workers: 4
+ batch_size: 16
+ require_consensus: false
+ min_edge_confidence: 0.1
+
+ orchestration:
+ mode: fast
+ top_k: 3
+ max_depth: 4
+ min_edge_confidence: 0.3
+
+ skill_retrieval:
+ enabled: false
+ artifact_root: ${SYMPHONY_SKILL_RETRIEVAL_ROOT:-}
+ build:
+ branching_factor: 12
+ max_depth: 6
+ root_categories: ""
+ max_workers: 2
+ max_retries: 2
+ request_timeout_seconds: 420
+ classification_batch_limit: 32
+ discovery_seed: 42
+ postprocess_enabled: true
+ postprocess_max_passes: 1
+ postprocess_min_skills: 6
+ equivalence_enabled: false
+ retrieve:
+ compact_codes_enabled: false
+ flatten_tree: false
+ max_exposure_depth: 1
+
+# Auto Memory:对话结束后自动提取记忆,按项目隔离存储
+# 存储路径:~/.jiuwenswarm/projects/{sanitized-project-path}/memory/
+# 类似 Claude Code 的 auto-memory 功能
+auto_memory_enabled: false
+
+# 日志目录:~/.jiuwenswarm/agent/.logs/
+# gateway.log / channel.log / agent_server.log 按源码路径分流;full.log 为汇总。
+# level:未单独指定时的默认级别。console_level:控制台;可省略则用 level。
+# 环境变量 LOG_LEVEL 仅覆盖控制台级别(不覆盖各日志文件)。
+logging:
+ level: INFO
+ console_level: INFO
+ gateway: INFO
+ channel: INFO
+ agent_server: INFO
+ full: INFO
+
+memory:
+ # ============================================================
+ # 记忆系统配置
+ # ============================================================
+ # 两个正交开关:
+ # 1) engine — 挂载哪套 rail(内置 / 外接 / 都挂 / 都不挂)
+ # 2) mode — 内置记忆的存储位置(local | cloud),不影响外接
+ #
+ # 外接 rail 的启用 = (engine ∈ {external, both}) AND (external.provider 非空)
+ # 内置 rail 的启用 = (engine ∈ {builtin, both}) AND (mode=local)
+ # AND modes.agent.<当前 mode>.memory.enabled=true
+ # ============================================================
+
+ mode: ${MEMORY_MODE:-local} # 内置记忆存储位置:local | cloud
+ # 记忆引擎总开关:builtin | external | both | none
+ # builtin — 仅内置记忆(默认,兼容旧配置)
+ # external — 仅外接记忆(LTM / Mem0 / OpenViking / 插件)
+ # both — 内置 + 外接并存
+ # none — 全部关闭
+ engine: ${MEMORY_ENGINE:-builtin}
+ forbidden_memory_definition:
+ enabled: false
+ patterns: []
+ description:
+ zh: "以下内容禁止记忆:密码、API密钥、Secret、Token、信用卡号、身份证号、手机号等敏感信息"
+ en: "The following content is forbidden to remember: passwords, API keys, secrets, tokens, credit card numbers, ID numbers, phone numbers and other sensitive information"
+
+ # ------------------------------------------------------------
+ # 外接记忆(External Memory)
+ # ------------------------------------------------------------
+ # 启用方式(任选一种):
+ #
+ # 【方案 1:YAML 直接改】
+ # memory.engine: external # 或 both
+ # memory.external.provider: mem0 # 选一个:openjiuwen | mem0 | openviking
+ # # 然后在下方对应的 mem0/openjiuwen/openviking 子段填 api_key 或 endpoint
+ #
+ # 【方案 2:环境变量覆盖】
+ # export MEMORY_ENGINE=external
+ # export MEMORY_EXTERNAL_PROVIDER=mem0
+ # export MEM0_API_KEY=sk-xxx
+ #
+ # 【关闭外接记忆】
+ # 把 memory.engine 改回 builtin 或 none;
+ # 或把 memory.external.provider 留空(两者任一生效即可禁用)
+ #
+ # 【挂载模式常见组合】
+ # ┌─────────────┬───────────────┬──────────────────────────────────────┐
+ # │ engine │ provider │ 效果 │
+ # ├─────────────┼───────────────┼──────────────────────────────────────┤
+ # │ builtin │ * │ 只挂内置(默认;外接即使填了也不挂) │
+ # │ external │ openjiuwen │ 只挂外接 LTM │
+ # │ external │ mem0 │ 只挂外接 Mem0 │
+ # │ external │ openviking │ 只挂外接 OpenViking │
+ # │ external │ <plugin-name> │ 只挂用户安装的插件 │
+ # │ both │ 任一 │ 内置 + 外接同时挂(LLM 两套工具并列)│
+ # │ none │ * │ 全关,任何记忆 rail 都不挂 │
+ # └─────────────┴───────────────┴──────────────────────────────────────┘
+ #
+ # 说明:
+ # - 外接记忆 mode-independent:配置一次,plan / fast 模式全程生效,
+ # 跨 config 热重载持久存活(保留 prefetch 缓存、电路断路器、会话状态)
+ # - 单 provider 策略:同一时刻 provider 只能选一个
+ # - 失败降级:provider 构建失败或网络异常不阻塞主流程
+ external:
+ # 选哪家 provider。空字符串 = 禁用外接(等价于 engine=builtin)
+ provider: ${MEMORY_EXTERNAL_PROVIDER:-} # '' | openjiuwen | mem0 | openviking | lakebase | <plugin-name>
+ # 数据隔离标识(所有 provider 共用)
+ user_id: ${MEMORY_USER_ID:-__default__}
+ scope_id: ${MEMORY_SCOPE_ID:-__default__}
+
+ # -- OpenJiuwen LTM(本地长期记忆:KV + 向量 + DB)--
+ # 生效条件:provider='openjiuwen'
+ # 依赖顶层 embed 段提供 embedding 配置(不单独配置 api_key)
+ openjiuwen:
+ kv_type: shelve # shelve | in_memory | sqlite
+ kv_path: ${MEMORY_KV_PATH:-} # 默认 ~/.jiuwenswarm/memory/ltm/kv
+ vector_type: chroma # chroma
+ vector_persist_dir: ${MEMORY_VECTOR_DIR:-} # 默认 ~/.jiuwenswarm/memory/ltm/chroma
+ db_type: sqlite
+ db_path: ${MEMORY_DB_PATH:-} # 默认 ~/.jiuwenswarm/memory/ltm/ltm.db
+
+ # -- Mem0(云端事实抽取+语义检索)--
+ # 生效条件:provider='mem0'
+ # 必填:api_key(从 mem0.ai 获取)
+ mem0:
+ api_key: ${MEM0_API_KEY:-}
+ user_id: ${MEM0_USER_ID:-jiuwenswarm-user}
+ agent_id: ${MEM0_AGENT_ID:-jiuwenswarm}
+ rerank: true # 搜索结果重排序(更准但更慢)
+
+ # -- OpenViking(字节上下文数据库)--
+ # 生效条件:provider='openviking'
+ # 必填:endpoint 可访问
+ openviking:
+ endpoint: ${OPENVIKING_ENDPOINT:-http://127.0.0.1:1933}
+ api_key: ${OPENVIKING_API_KEY:-}
+ account: ${OPENVIKING_ACCOUNT:-root}
+ user: ${OPENVIKING_USER:-default}
+
+ lakebase:
+ api_key: ${LAKEBASE_API_KEY:-}
+ base_url: ${LAKEBASE_API_URL:-}
+ base_id: ${LAKEBASE_MEM_BASE_ID:-}
+ database_id: ${LAKEBASE_DATABASE_ID:-}
+
+models:
+ defaults:
+ - model_client_config:
+ api_base: ${API_BASE}
+ api_key: ${API_KEY}
+ model_name: ${MODEL_NAME:-xiaomi/mimo-v2-omni}
+ client_provider: ${MODEL_PROVIDER}
+ timeout: 1800
+ verify_ssl: false
+ custom_headers: {}
+ model_config_obj:
+ temperature: 0.95
+ is_default: true
+ video:
+ model_client_config:
+ api_base: ${VIDEO_API_BASE}
+ api_key: ${VIDEO_API_KEY}
+ model_name: ${VIDEO_MODEL_NAME:-xiaomi/mimo-v2-omni}
+ client_provider: ${VIDEO_PROVIDER}
+ timeout: 1800
+ verify_ssl: false
+ model_config_obj:
+ temperature: 0.95
+ audio:
+ model_client_config:
+ api_base: ${AUDIO_API_BASE}
+ api_key: ${AUDIO_API_KEY}
+ model_name: ${AUDIO_MODEL_NAME:-openai/gpt-4o-audio-preview}
+ client_provider: ${AUDIO_PROVIDER}
+ verify_ssl: false
+ timeout: 1800
+ model_config_obj:
+ temperature: 0.95
+ vision:
+ model_client_config:
+ api_base: ${VISION_API_BASE}
+ api_key: ${VISION_API_KEY}
+ model_name: ${VISION_MODEL_NAME:-bytedance-seed/seed-2.0-mini}
+ client_provider: ${VISION_PROVIDER}
+ verify_ssl: false
+ timeout: 1800
+ model_config_obj:
+ temperature: 0.95
+ image_gen:
+ model_client_config:
+ api_base: ${IMAGE_GEN_API_BASE:-https://dashscope.aliyuncs.com/api/v1}
+ api_key: ${IMAGE_GEN_API_KEY}
+ model_name: ${IMAGE_GEN_MODEL_NAME:-qwen-image-max}
+ client_provider: ${IMAGE_GEN_PROVIDER:-DashScope}
+ verify_ssl: false
+ timeout: 1800
+ model_config_obj:
+ temperature: 0.95
+
+# 外接 ACP Agent(stdio),供工具 acp_chat 使用。按需取消注释并填写;command/args 可指向任意兼容 ACP 的包(与 VS Code formulahendry.acp-client 预置列表一致)。
+acp_agents:
+ codex:
+ command: npx
+ args: ["@zed-industries/codex-acp@latest"]
+ cwd:
+ env:
+ OPENAI_API_KEY: ${OPENAI_API_KEY} # 仅由此 env 注入子进程(不读 workspace .env / 父进程)
+
+# ============================================================
+# Agent 配置(可被 team.agents / modes.team.<name>.agents 引用)
+# ============================================================
+# 每个 agent 定义一个可复用的 agent 配置模板,支持以下字段(均可选):
+#
+# model: # 不配则继承 models.default
+# model_client_config:
+# client_provider: OpenAI
+# api_base: https://api.deepseek.com
+# api_key: sk-xxx
+# timeout: 1800
+# verify_ssl: false
+# custom_headers: {}
+# model_request_config:
+# model: deepseek-chat
+# skills: # 不配则不自动填充
+# - skill_a
+# - skill_b
+# workspace: # 默认 {"stable_base": true}
+# stable_base: true
+# max_iterations: 200 # 默认 200
+# completion_timeout: 600.0 # 默认 600.0
+#
+# 示例:给不同 agent 配置不同模型和技能
+# agent_coder:
+# model:
+# model_client_config:
+# client_provider: OpenAI
+# api_base: https://api.deepseek.com
+# api_key: sk-xxx
+# model_request_config:
+# model: deepseek-chat
+# skills:
+# - code_review
+# - unit_test
+# max_iterations: 300
+#
+agents:
+ agent_leader:
+ workspace:
+ stable_base: true
+ max_iterations: 200
+ completion_timeout: 600.0
+
+ agent_teammate:
+ workspace:
+ stable_base: true
+ max_iterations: 200
+ completion_timeout: 600.0
+
+telemetry:
+ enabled: false # 总开关(环境变量 OTEL_ENABLED 优先)
+ exporter: otlp # otlp / console / none
+ endpoint: http://localhost:4317 # OTLP endpoint
+ protocol: grpc # grpc / http
+ headers: {} # 公共 OTLP headers,可被 traces/metrics 覆盖
+ log_messages: true # 是否在 span event 中记录完整消息内容
+ service_name: jiuwenswarm
+ provider_factory: # 自定义 provider factory,格式:module:function
+ traces:
+ exporter: # trace exporter,默认回退到 telemetry.exporter
+ endpoint: # trace endpoint,默认回退到 telemetry.endpoint
+ protocol: # trace protocol,默认回退到 telemetry.protocol
+ headers: {} # trace headers,默认回退到 telemetry.headers
+ metrics:
+ exporter: # metrics exporter,默认回退到 telemetry.exporter
+ endpoint: # metrics endpoint,默认回退到 telemetry.endpoint
+ protocol: # metrics protocol,默认回退到 telemetry.protocol
+ headers: {} # metrics headers,默认回退到 telemetry.headers
+
+# ============================================================
+# Team 可观测性配置(OTel + Langfuse)
+# ============================================================
+# 与 telemetry 不同,team_observability 专门用于 TeamAgent 的
+# 可观测性追踪,包括 team/member/task/message 级别的 span。
+# 启用后会自动将 OtelTeamMonitorHandler 注册到 TeamAgent,
+# 将事件转为 OTel span 导出到 Langfuse / OTLP Collector。
+#
+# 前置条件:
+# 1. 启动 OTel Collector + Langfuse
+# 2. 在用户配置中设置 team_observability.enabled: true
+# ============================================================
+team_observability:
+ enabled: false # Team observability 总开关
+ exporter: file # otlp_grpc / otlp_http / file
+ endpoint: http://localhost:4317 # OTLP gRPC endpoint(file 模式不需要)
+ service_name: jiuwenswarm # 服务名称(OTel resource service.name)
+ sample_rate: 1.0 # 采样率 (0.0-1.0)
+ redact_prompts: false # 是否脱敏 prompt 内容
+ redact_completions: false # 是否脱敏 completion 内容
+ attribute_value_max_length: 10240 # OTel attribute value 最大长度
+ langfuse_public_key: "" # Langfuse OTLP 认证 public key(可选)
+ langfuse_secret_key: "" # Langfuse OTLP 认证 secret key(可选)
+ traces_dir: "" # file exporter 输出目录,默认 ~/.jiuwenswarm/.trace
+ file_retention_days: 7 # file exporter 文件保留天数
+
+react:
+ agent_name: main_agent
+ enable_task_loop: false
+ max_iterations: 100
+ model_name: ${MODEL_NAME:-deepseek-chat}
+ skill_mode: all
+ # code_agent / research_agent 默认不启用;只有显式配置 enabled: true 才会显示并可被 task_tool 调用
+ # browser_agent: code.team 路径通过此 key 门控(单 agent 路径仍由 browser runtime 开关决定)
+ subagents:
+ general_agent:
+ enabled: true
+ code_agent:
+ enabled: false
+ # max_iterations: 15
+ research_agent:
+ enabled: false
+ # max_iterations: 15
+ browser_agent:
+ enabled: true
+ # max_iterations: 15
+ answer_chunk_size: 500
+ stream_chunk_threshold: 50
+ stream_character_threshold: 2000
+ context_engine_config:
+ enable_kv_cache_release: false
+ enable_openrouter_model_context_window_tokens: true
+ enable_reload: true
+ enabled: true
+ message_summary_offloader_config:
+ messages_threshold: null
+ large_message_threshold: 10000
+ offload_message_type: [ "tool" ]
+ protected_tool_names: ["read_file:*SKILL.md", "reload_original_context_messages"]
+ messages_to_keep: null
+ keep_last_round: false
+ customized_summary_prompt: null
+ enable_adaptive_compression: true
+ summary_max_tokens: 900
+ enable_precise_step: false
+ step_summary_max_context_messages: 8
+ content_max_chars_for_compression: 200000
+ dialogue_compressor_config:
+ messages_threshold: null
+ tokens_threshold: 100000
+ messages_to_keep: 10
+ keep_last_round: false
+ compression_target_tokens: 1800
+ offload_writeback_enabled: false
+ current_round_compressor_config:
+ tokens_threshold: 100000
+ messages_to_keep: 3
+ min_selected_tokens_for_compression: 20000
+ compression_target_tokens: 4000
+ summary_merge_target_tokens: 4000
+ accumulated_summary_token_limit: 20000
+ summary_merge_min_blocks: 3
+ prior_context_window_size: 10
+ offload_writeback_enabled: false
+ round_level_compressor_config:
+ rounds_threshold: 2
+ trigger_context_ratio: 0.9
+ target_total_tokens: 160000
+ compression_call_max_tokens: 250000
+ keep_last_round: true
+ keep_recent_messages: 6
+ messages_to_keep: 6
+ first_pass_target_tokens: 30000
+ second_pass_target_tokens: 20000
+ third_pass_target_tokens: 10000
+ truncate_head_ratio: 0.2
+ offload_writeback_enabled: false
+ # Skills 在线自演进配置
+ evolution:
+ enabled: true # true = 启用在线 Skills 自演进
+ auto_scan: false # true = 每轮对话后自动扫描(建议先用手动 /evolve)
+ auto_save: false # true = 自演进审批无需用户点击自动通过(内部开关)
+ skill_create: false # true = 注册 SkillCreateRail(单 agent)及 TeamSkillCreateRail(leader)
+ skill_base_dir: "agent/skills" # Skill 根目录
+ a2x_registry:
+ base_url: "http://127.0.0.1:8000"
+ timeout: 30.0
+ api_key: ""
+ # null uses the SDK default ownership store under the process HOME.
+ # Keep ownership persistent so teardown can call replace_agent_card safely.
+ ownership_file:
+ # Allowed values: teammate / teamleader
+ role: "teammate"
+ # When role=teammate, automatic blank-agent registration during agent
+ # initialization calls AsyncA2XRegistryClient.register_blank_agent(...).
+ # endpoint may be omitted in distributed mode; it defaults to
+ # team.transport.params.bootstrap_direct_addr when available.
+ dataset: "team_pool"
+ endpoint: ""
+
+tools:
+ - todo
+ - skill
+
+email_settings:
+ email_address: ${EMAIL_ADDRESS}
+ token: ${EMAIL_TOKEN}
+ smtp_server: ${SMTP_SERVER:-smtp.gmail.com}
+ port: ${EMAIL_PORT:-587}
+
+embed:
+ embed_api_key: ${EMBED_API_KEY}
+ embed_base_url: ${EMBED_API_BASE}
+ embed_model: ${EMBED_MODEL}
+
+task_memory:
+ # Set enabled: true to activate TaskMemoryService skill tools
+ # (experience_retrieve, experience_learn, experience_clear)
+ enabled: true
+ # Override defaults below if task memory uses a different model/key than the main agent
+ llm_model: ${TASK_MEMORY_LLM_MODEL}
+ embedding_model: ${TASK_MEMORY_EMBED_MODEL}
+ api_key: ${TASK_MEMORY_API_KEY}
+ api_base: ${TASK_MEMORY_API_BASE}
+ # Retrieval and summary algorithms: ACE | ReasoningBank | ReMe
+ retrieval_algo: ACE
+ summary_algo: ACE
+
+gateway:
+ # SessionMap 仅用于企业claw场景,如 feishu_enterprise 等通道:将平台身份映射为 Agent 的 session_id。
+ # 取值:per_chat_bot(默认,同 chat+bot 共享会话), per_chat_bot_user(按 user 分会话)
+ session_map_scope: <<GATEWAY_SESSION_MAP_SCOPE>>
+
+ # AgentClient 配置 - Gateway 连接到 AgentServer 的方式
+ # type: websocket(默认,WebSocket 连接) | yuanrong(openYuanRong 函数调用)
+ agent_client:
+ type: yuanrong # websocket | yuanrong
+ # yuanrong 函数模式配置下面参数
+ frontend_endpoint: http://<<MASTER_NODE_IP>>:<<FRONTEND_PORT>>
+ function_version_urn: <<FUNCTION_ID>>
+ concurrency: <<GATEWAY_CONCURRENCY>>
+ invoke_timeout_s: <<GATEWAY_INVOKE_TIMEOUT>>
+
+heartbeat:
+ # 心跳间隔(秒),默认 3600
+ every: 3600
+ # 心跳结果回传的 channel(如 "web"),
+ target: web
+ # 心跳生效时间段(本地时间),start <= now < end 时心跳生效
+ active_hours:
+ start: 08:00
+ end: 22:00
+
+# 执行护栏:工具循环检测与主动中断
+execution_guard:
+ # 断路器:检测工具重复/交替/无进展循环,critical 级会强制结束当次回答
+ circuit_breaker:
+ # 总开关。断路器会主动中断 agent(force-finish),默认关闭,需显式开启
+ enabled: false
+ # 相同工具+参数重复达到该次数时告警(仅日志,不中断)
+ warning_threshold: 10
+ # Ping-Pong 两工具交替且无进展达到该次数时中断
+ critical_threshold: 20
+ # 工具连续无进展(结果不变)达到该次数时兜底中断
+ global_breaker_threshold: 30
+ # 未知/错误工具连续调用达到该次数时停止重试并中断
+ unknown_tool_threshold: 10
+
+channels:
+ web:
+ send_file_allowed: true
+ feishu:
+ # 飞书应用配置
+ app_id:
+ app_secret:
+ encrypt_key:
+ verification_token:
+ allow_from:
+ enable_streaming: false
+ enabled: false
+ send_file_allowed: true
+ # 群聊数字分身(默认关闭)
+ group_digital_avatar: false
+ my_user_id: ""
+ bot_name: ""
+ enable_memory: false
+ feishu_enterprise:
+ # 企业飞书多 Bot 配置(每个 bot 会注册为独立 channel: feishu_enterprise:<app_id>)
+ # bot_a:
+ # app_id:
+ # app_secret:
+ # encrypt_key:
+ # verification_token:
+ # allow_from: []
+ # enable_streaming: true
+ # chat_id:
+ # enabled: false
+ xiaoyi:
+ # 华为小艺 A2A 配置
+ mode: xiaoyi_channel
+ ak:
+ sk:
+ api_id:
+ push_id:
+ agent_id:
+ ws_url1: wss://hag.cloud.huawei.com/openclaw/v1/ws/link
+ ws_url2: wss://116.63.174.231/openclaw/v1/ws/link
+ enable_streaming: true
+ enabled: false
+ # xiaoyi_claw配置
+ uid:
+ api_key:
+ push_url:
+ file_upload_url:
+ # 小艺手机端插件tools调用,会添加相关tools到系统提示词
+ phone_tools_enabled: false
+ send_file_allowed: true
+ dingtalk:
+ # 钉钉应用配置
+ client_id:
+ client_secret:
+ allow_from: []
+ enabled: false
+ send_file_allowed: true
+ telegram:
+ # Telegram Bot 配置
+ # 从 @BotFather 获取 bot_token
+ bot_token:
+ # 用户白名单(Telegram user_id),为空则允许所有用户
+ allow_from: []
+ # 消息解析模式: Markdown, HTML, None
+ parse_mode: Markdown
+ # 群聊模式: mention(仅响应@提及), reply(仅响应回复), all(响应所有), off(禁用群聊)
+ group_chat_mode: mention
+ enabled: false
+ discord:
+ # Discord Bot 配置(当前版本仅支持参数管理)
+ # 可与用户私聊(DM):仍受 allow_from 约束
+ # Bot Token(Discord Developer Portal -> Bot)
+ bot_token:
+ # Application ID(Discord Developer Portal -> General Information)
+ application_id:
+ # 目标服务器 ID(Guild ID)
+ guild_id:
+ # 目标频道 ID(Channel ID)
+ channel_id:
+ # 用户白名单(Discord user_id),为空则允许所有用户
+ allow_from: []
+ # 是否关闭私信功能
+ block_dm: false
+ enabled: false
+ whatsapp:
+ # WhatsApp 配置(通过本地 Baileys bridge)
+ bridge_ws_url: ws://127.0.0.1:19600/ws
+ default_jid:
+ allow_from: []
+ enable_streaming: true
+ auto_start_bridge: false
+ bridge_command: node scripts/whatsapp-bridge.js
+ bridge_workdir:
+ enabled: false
+ wechat:
+ # 个人微信 iLink Bot API 配置
+ enable_streaming: false
+ base_url: https://ilinkai.weixin.qq.com
+ bot_token:
+ ilink_bot_id:
+ ilink_user_id:
+ allow_from: []
+ auto_login: true
+ qrcode_poll_interval_sec: 2.0
+ long_poll_timeout_sec: 45
+ backoff_base_sec: 1.0
+ backoff_max_sec: 30.0
+ credential_file: ~/.wx-ai-bridge/credentials.json
+ enabled: false
+ wecom:
+ # 企业微信 AI 机器人配置
+ bot_id:
+ secret:
+ ws_url: wss://openws.work.weixin.qq.com
+ allow_from: []
+ enable_streaming: true
+ send_thinking_message: false
+ enabled: false
+ send_file_allowed: true
+ # 群聊数字分身(默认关闭)
+ group_digital_avatar: false
+ my_user_id: ""
+ bot_name: ""
+ enable_memory: false
+
+# ========== 细粒度权限管控(tiered_policy)==========
+#
+# schema: tiered_policy(或兼容 v_cc / v4.2)时由 tiered_policy.evaluate_tiered_policy 求值;
+# permission_mode: normal|strict 决定 severity 映射,见 agentserver/permissions/tiered_policy.py。
+# severity(normal):LOW/MEDIUM→allow,HIGH/CRITICAL→ask;strict 下 MEDIUM→ask、CRITICAL→deny。
+# rules[*].action: 可选显式动作 allow|ask|deny;配置后优先于 severity 映射,适合敏感文件读取、
+# 系统控制等不希望随 permission_mode 漂移的规则。
+# 内置参数规则 > 用户 rules;整工具存在则不用 defaults;详见 tiered_policy 模块说明。
+#
+# 三种动作: allow / ask / deny
+permissions:
+ enabled: false
+ schema: tiered_policy
+ permission_mode: normal
+
+ defaults:
+ "*": "allow"
+
+ tools:
+ bash: ask
+ mcp_exec_command: ask
+ create_terminal: ask
+ write: ask
+ write_file: ask
+ edit_file: ask
+ search_replace: ask
+ # ask_user 只向用户提问,不修改系统,自动放行避免权限中断阻塞问题选项呈现
+ ask_user: allow
+ write_memory: allow
+ edit_memory: allow
+ read_memory: allow
+ memory_search: allow
+ memory_get: allow
+ todo_create: allow
+ todo_insert: allow
+ todo_complete: allow
+ todo_remove: allow
+ todo_list: allow
+ # Coding Memory 工具权限
+ coding_memory_write: allow
+ coding_memory_edit: allow
+ coding_memory_read: allow
+ # 外接记忆工具(External Memory — OpenJiuwen / Mem0 / OpenViking)
+ ltm_search: allow
+ ltm_search_summary: allow
+ mem0_profile: allow
+ mem0_search: allow
+ mem0_conclude: allow
+ viking_search: allow
+ viking_read: allow
+ viking_browse: allow
+ viking_remember: allow
+ viking_add_resource: allow
+ mcp_free_search: allow
+ mcp_paid_search: allow
+ mcp_fetch_webpage: allow
+ cron_list_jobs: allow
+ cron_get_job: allow
+ cron_create_job: allow
+ cron_update_job: allow
+ cron_delete_job: allow
+ cron_toggle_job: allow
+ cron_preview_job: allow
+ acp_chat: ask
+
+ rules:
+ - id: shell_allow_dir
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "dir *"
+ severity: LOW
+ - id: shell_allow_ls
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "ls *"
+ severity: LOW
+ - id: shell_allow_pwd
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "pwd *"
+ severity: LOW
+ - id: shell_allow_cd
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "cd *"
+ severity: LOW
+ - id: shell_allow_echo
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "echo *"
+ severity: LOW
+ - id: shell_allow_cat
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "cat *"
+ severity: LOW
+ - id: shell_allow_type
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "type *"
+ severity: LOW
+ - id: shell_allow_head
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "head *"
+ severity: LOW
+ - id: shell_allow_tail
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "tail *"
+ severity: LOW
+ - id: shell_allow_git_status
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "git status *"
+ severity: LOW
+ - id: shell_allow_git_log
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "git log *"
+ severity: LOW
+ - id: shell_allow_git_diff
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "git diff *"
+ severity: LOW
+ - id: shell_allow_git_branch
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "git branch *"
+ severity: LOW
+ - id: shell_ask_rm
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "rm *"
+ severity: HIGH
+ - id: shell_ask_del
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "del *"
+ severity: HIGH
+ - id: shell_ask_rd
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "rd *"
+ severity: HIGH
+ - id: shell_ask_mv
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "mv *"
+ severity: HIGH
+ - id: shell_ask_cp
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "cp *"
+ severity: HIGH
+ - id: shell_ask_chmod
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "chmod *"
+ severity: HIGH
+ - id: shell_ask_chown
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: "chown *"
+ severity: HIGH
+ - id: shell_ask_sensitive_file_reads
+ tools: [bash, mcp_exec_command, create_terminal]
+ pattern: 're:(?i)(^|[\s;&|()])((cat|type|less|more|head|tail|grep|find|Get-Content|Select-String)\b[^;&|]*(id_rsa|id_ed25519|\.pem\b|\.pfx\b|\.key\b|\.kube/config|\.aws/(credentials|config)|\.npmrc\b|\.env(\.[A-Za-z0-9_-]+)?\b|authorized_keys|\.ssh/))'
+ severity: HIGH
+ - id: path_ask_ssh
+ tools: [read_file, write_file, edit_file, read_text_file, write_text_file, write, read, glob_file_search, glob, list_dir, list_files, grep, search_replace]
+ pattern: "**/.ssh/**"
+ severity: HIGH
+ - id: path_ask_env
+ tools: [read_file, write_file, edit_file, read_text_file, write_text_file, write, read, glob_file_search, glob, list_dir, list_files, grep, search_replace]
+ pattern: "**/.env*"
+ severity: HIGH
+
+ # 数字分身 owner-scoped 权限(默认空,不生效)
+ owner_scopes: {}
+ deny_guidance_message: ""
+
+ # 外部目录访问 (访问 workspace 外路径时的权限)
+ external_directory:
+ "*": "ask"
+
+browser:
+ # chrome_path can be a string or per-OS map.
+ # Example:
+ # chrome_path:
+ # windows: "C:\\Users\\YOUR_USER\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
+ # macos: "/Applications/Google Chrome.app"
+ # linux: "/usr/bin/google-chrome"
+ remote_debugging_address: "127.0.0.1"
+ remote_debugging_port: 9222
+ # empty means use launcher default profile path by OS
+ user_data_dir: ""
+ profile_directory: "Default"
+
+updater:
+ enabled: true
+ # 桌面端版本检查源类型:gitcode / github
+ desktop_release_api_type: "gitcode"
+ repo_owner: openJiuwen
+ repo_name: jiuwenswarm
+ release_api_url: ""
+ asset_name_pattern_windows: "JiuwenSwarm-setup-{version}.exe"
+ asset_name_pattern_macos: "JiuwenSwarm-{version}.dmg"
+ asset_name_pattern_linux: "JiuwenSwarm-{version}.tar.gz"
+ sha256_name_pattern: "JiuwenSwarm-setup-{version}.exe.sha256"
+ timeout_seconds: 20
+ pypi_mirror: "https://mirrors.aliyun.com/pypi"
+
+extensions:
+ # 扩展包搜索目录(字符串),用 ';' 分割多个目录:
+ # EXTENSION_DIRS="E:/a;D:/b"
+ extension_dirs: ${EXTENSION_DIRS:-jiuwenswarm/extensions}
+
+
+# ============================================================
+# Hooks 配置
+# 17 个事件类型,支持 command / prompt 两种 hook 类型
+# 字段说明:
+# - disable_all_hooks: 全局关闭所有 hooks
+# - <事件名>:
+# - matcher: 匹配表达式(工具名|管道OR|正则|"*")
+# - hooks:
+# - type: command | prompt
+# - command / prompt: 执行的命令或 prompt 模板
+# 支持 $ARGUMENTS(hook input JSON)和 $TOOL_NAME 变量
+# - timeout: 超时秒数(默认 30s)
+# - shell: bash | sh | zsh(仅 command 类型)
+# - model: LLM 模型名(仅 prompt 类型,空则用默认轻量模型)
+# - status_message: 执行时显示的提示信息
+# 退出码语义(command 类型):
+# 0 = 成功继续 2 = 阻止执行 其他 = 非阻塞错误
+# ============================================================
+hooks:
+ disable_all_hooks: false
+
+ # PreToolUse: 工具执行前拦截
+ # PreToolUse:
+ # - matcher: "Write|Edit"
+ # hooks:
+ # - type: command
+ # command: "echo 'about to write file'"
+ # timeout: 30
+ # shell: "bash"
+ # status_message: "Running pre-write hook..."
+
+ # PostToolUse: 工具执行后拦截
+ # PostToolUse:
+ # - matcher: "Bash"
+ # hooks:
+ # - type: prompt
+ # prompt: "审查命令输出安全性: $ARGUMENTS"
+ # timeout: 15
+
+ # SessionStart: 会话开始时
+ # SessionStart:
+ # - matcher: "*"
+ # hooks:
+ # - type: command
+ # command: "echo 'session started'"
+
+ # Stop: Agent 结束前
+ # Stop:
+ # - matcher: "*"
+ # hooks:
+ # - type: command
+ # command: "echo 'agent stopping'"
+
+
+team:
+ # 默认:单机 local + inprocess。双机 pyzmq 示例见 tmp/team-leader.yaml、tmp/team-teammate.yaml(与 .tmp/leader_home、.tmp/teammate_home 内 config 同步)。
+ runtime:
+ mode: local
+ role: leader
+
+ team_name: jiuwen_team
+ lifecycle: persistent
+ teammate_mode: build_mode
+ spawn_mode: inprocess
+
+ leader:
+ member_name: team_leader
+ display_name: 团队领导
+ persona: "天才项目管理专家,擅长任务分解和团队协调"
+
+ agents:
+ leader: $agent_leader
+ teammate: $agent_teammate
+
+ workspace:
+ enabled: true
+
+ transport:
+ type: inprocess
+
+ storage:
+ type: sqlite
+
+mcp:
+ servers: []
+ # 示例:
+ # servers:
+ # - name: playwright
+ # enabled: true
+ # transport: stdio
+ # command: python
+ # args: ["path/to/server.py", "--transport", "stdio"]
+ # cwd: .
+ # env:
+ # LOG_LEVEL: INFO
+ # - name: local-sse
+ # enabled: false
+ # transport: sse
+ # url: http://127.0.0.1:9000/sse
+ # headers:
+ # Authorization: Bearer ${MCP_TOKEN}
+ # timeout_s: 30
+
+modes:
+ # 一级模式 agent / code / team
+ agent:
+ # agent 模式支持 性能/规划/集群
+ fast:
+ memory:
+ enabled: true
+ is_proactive: false
+ rails:
+ tools:
+ plan:
+ memory:
+ enabled: true
+ is_proactive: true
+ rails:
+ tools:
+ code:
+ # 记忆开关 — 控制 CodingMemoryRail 和 ProjectMemoryRail 加载
+ # 关闭后,coding_memory_read/write/edit 工具不可用,项目记忆文件不自动加载
+ memory:
+ enabled: true
+
+ # 动态 Rails — 列表中出现的 = 启用;不出现的 = 不启用
+ # 固定 Rails(以下 Rails 已在代码中固定挂载,无需在此配置):
+ # RuntimePromptRail, ResponsePromptRail, JiuSwarmStreamEventRail, SecurityRail,
+ # PermissionInterruptRail, SysOperationRail(FileSystemRail), LspRail,
+ # AgentModeRail, StructuredAskUserRail, ConfirmInterruptRail, ContextProcessorRail
+ # 注意:ProjectMemoryRail, CodingMemoryRail 受 memory.enabled 开关控制,
+ # 开关关闭时不加载,开关开启时固定挂载。
+ rails:
+ - SkillUseRail
+ - WorktreeRail
+
+ # 动态 Tools — 列表中出现的 = 启用
+ # send_file_to_user 由运行时 _update_session_tools 注册,不在此配置
+ # coding_memory_read/write/edit 由 CodingMemoryRail 在 subagent 内部注册,不在此配置
+ tools:
+ - web_free_search
+ - web_fetch_webpage
+ - web_paid_search
+ - user_todos
+ - skill_toolkit
+ - skill_retrieval
+
+ embedding_config:
+ model_name: null
+ base_url: null
+ api_key: null
+ team:
+ jiuwen_team:
+ team_name: jiuwen_team
+ lifecycle: persistent
+ teammate_mode: build_mode
+ spawn_mode: inprocess
+ enable_swarmflow: true
+
+ # Team-specific permission control.
+ enable_permissions: false
+
+ leader:
+ member_name: team-leader
+ display_name: 团队领导
+ persona: "天才项目管理专家,擅长任务分解和团队协调"
+
+ agents:
+ leader: $agent_leader
+
+ workspace:
+ enabled: true
+
+ transport:
+ type: inprocess
+
+ storage:
+ type: sqlite
+
+ # ============================================================
+ # Team 级共享记忆(TeamMemoryConfig)
+ # ============================================================
+ # 与常规 Agent 的 per-session 记忆不同,Team 记忆是一个独立的、
+ # 跨成员的共享记忆系统,由 TeamMemoryManager 统一管理。
+ #
+ # 启用后,每个 Team 成员的记忆操作不再是孤立的个人记忆,
+ # 而是读写同一份 TEAM_MEMORY.md(位于 team_memory_dir 下)。
+ # 这允许成员之间通过记忆文件共享上下文(如项目背景、决策记录等)。
+ # ============================================================
+ memory:
+ # ---------- 总开关 ----------
+ # 关闭时 TeamMemoryManager 不创建,成员记忆回退到各自独立的 MemoryRail
+ enabled: false
+
+ # ---------- 场景标识 ----------
+ # "general" — 通用场景,记忆提取 prompt 偏重项目背景与决策
+ # "coding" — 编码场景,记忆提取 prompt 偏重技术方案与架构决策
+ scenario: "general"
+
+ # ---------- 自动提取 ----------
+ # true — 每轮对话结束后,后台自动总结并写入 TEAM_MEMORY.md
+ # false — 仅当 LLM 主动调用记忆工具时才写入
+ # 仅在 lifecycle=persistent 时生效;temporary 团队不触发自动提取
+ auto_extract: true
+
+ # ---------- 共享记忆 ----------
+ # true — 所有成员共享同一份 TEAM_MEMORY.md(默认)
+ # false — 每个成员维护独立记忆文件(按 member_name 分目录)
+ shared_memory: true
+
+ # ---------- 记忆注入模式 ----------
+ # 控制记忆内容如何注入到每个成员的 system prompt 中:
+ # "proactive" — 每轮对话开始时主动注入最新记忆摘要
+ member_memory_prompt_mode: "proactive"
diff --git a/deploy/yuanrong/deploy.sh b/deploy/yuanrong/deploy.sh
new file mode 100755
index 0000000000..092209ccb7
--- /dev/null
+++ b/deploy/yuanrong/deploy.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+source "global_vars.sh"
+source "common.sh"
+source "cmd_handler.sh"
+source "args_handler.sh"
+source "check_handler.sh"
+source "envfile_handler.sh"
+source "template_handler.sh"
+source "jiuwenswarm_handler.sh"
+source "gateway_handler.sh"
+
+process_up() {
+ for module in "${MODULES[@]}"; do
+ case "${module}" in
+ jiuwenswarm)
+ check_jiuwenswarm_up_dependency
+ deploy_jiuwenswarm
+ ;;
+ gateway)
+ check_gateway_up_dependency
+ deploy_gateway
+ ;;
+ esac
+ done
+}
+
+process_down() {
+ local reversed_modules=()
+ for ((i=${#MODULES[@]}-1; i>=0; i--)); do
+ reversed_modules+=("${MODULES[$i]}")
+ done
+
+ for module in "${reversed_modules[@]}"; do
+ case "${module}" in
+ jiuwenswarm)
+ uninstall_jiuwenswarm
+ ;;
+ gateway)
+ uninstall_gateway
+ ;;
+ esac
+ done
+}
+
+process_restart() {
+ process_down
+ process_up
+}
+
+main() {
+ read_env_from_file "${CUSTOM_ENV_FILE}" "DEPLOY_VARS"
+ parse_args "$@"
+ check_dependency
+ process_${CMD}
+}
+
+main "$@"
diff --git a/deploy/yuanrong/envfile_handler.sh b/deploy/yuanrong/envfile_handler.sh
new file mode 100644
index 0000000000..c026c8ffa1
--- /dev/null
+++ b/deploy/yuanrong/envfile_handler.sh
@@ -0,0 +1,83 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+# == read key-value pairs from file into array (for first start-up) ==
+read_env_from_file() {
+ local env_file="$1"
+ local -n target_array="$2"
+
+ if [ ! -f "${env_file}" ]; then
+ error "Config file not found: ${env_file}"
+ fi
+
+ info "Loading config: ${env_file}"
+
+ local key=""
+ local value=""
+ local buffer=""
+ local in_quote=0
+
+ while IFS= read -r line || [[ -n "$line" ]]; do
+ trimmed_line="${line#"${line%%[![:space:]]*}"}"
+ if [[ $in_quote -eq 0 && ($trimmed_line == \#* || -z "${trimmed_line}") ]]; then
+ continue
+ fi
+
+ if (( in_quote )); then
+ buffer+=$'\n'"$line"
+ else
+ buffer="$line"
+ fi
+
+ if [[ $in_quote -eq 0 && $buffer =~ ^([A-Za-z0-9_]+)=\"(.*) ]]; then
+ key="${BASH_REMATCH[1]}"
+ value="${BASH_REMATCH[2]}"
+
+ if [[ $value =~ (.*)\"[[:space:]]*$ ]]; then
+ target_array["$key"]="${BASH_REMATCH[1]}"
+ in_quote=0
+ else
+ buffer="$value"
+ in_quote=1
+ fi
+ continue
+ fi
+
+ if (( in_quote )); then
+ if [[ $buffer =~ (.*)\"[[:space:]]*$ ]]; then
+ target_array["$key"]="${BASH_REMATCH[1]}"
+ in_quote=0
+ key=""
+ buffer=""
+ fi
+ continue
+ fi
+
+ if [[ $buffer =~ ^([A-Za-z0-9_]+)=(.*) ]]; then
+ local k="${BASH_REMATCH[1]}"
+ local v="${BASH_REMATCH[2]}"
+ v="${v#\"}"
+ v="${v%\"}"
+ target_array["$k"]="$v"
+ fi
+
+ buffer=""
+ done < "$env_file"
+
+ success "Loaded config: ${env_file}"
+}
+
+# ===== Writes sorted key-value pairs to .env.<Instance ID> file =====
+write_env_to_file() {
+ local env_file=$1
+ local -n source_array=$2
+
+ info "Writing $2 to config file: ${env_file}"
+ > "${env_file}"
+ printf "%s\n" "${!source_array[@]}" | sort | while read -r key; do
+ if [ -n "${key}" ]; then
+ echo "${key}=${source_array[${key}]}" >> "${env_file}"
+ fi
+ done
+ success "Generated config file : ${env_file}"
+}
diff --git a/deploy/yuanrong/gateway_handler.sh b/deploy/yuanrong/gateway_handler.sh
new file mode 100755
index 0000000000..1f0ce28c6e
--- /dev/null
+++ b/deploy/yuanrong/gateway_handler.sh
@@ -0,0 +1,127 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+gateway_get_config_dir() {
+ local instance_name="${DEPLOY_VARS["JIUWENSWARM_INSTANCE_NAME"]}"
+ if [ -n "${instance_name}" ]; then
+ echo "/root/.jiuwenswarm-instances/${instance_name}/config"
+ else
+ echo "/root/.jiuwenswarm/config"
+ fi
+}
+
+gateway_compute_extension_dirs() {
+ if [ -n "${DEPLOY_VARS["EXTENSION_DIRS"]:-}" ]; then
+ info "EXTENSION_DIRS already set: ${DEPLOY_VARS["EXTENSION_DIRS"]}"
+ return 0
+ fi
+
+ local master_host="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ local python_version="${DEPLOY_VARS["YR_PYTHON_VERSION"]}"
+
+ local jiuwenswarm_location
+ jiuwenswarm_location=$(exec_on_host "${master_host}" "python${python_version} -m pip show jiuwenswarm 2>/dev/null | grep -i '^Location:' | awk '{print \$2}'" | tr -d '\r') || true
+
+ if [ -n "${jiuwenswarm_location}" ]; then
+ DEPLOY_VARS["EXTENSION_DIRS"]="${jiuwenswarm_location}/jiuwenswarm/extensions"
+ info "EXTENSION_DIRS inferred from jiuwenswarm install on ${master_host}: ${DEPLOY_VARS["EXTENSION_DIRS"]}"
+ else
+ warning "Could not infer EXTENSION_DIRS: jiuwenswarm not found on ${master_host}. You may set EXTENSION_DIRS in .env.custom manually."
+ fi
+}
+
+gateway_gen_config() {
+ gateway_compute_extension_dirs
+
+ info "Generating gateway config.yaml from template..."
+ render_config_template "${GATEWAY_CONFIG_TEMPLATE_FILE}" "${GATEWAY_CONFIG_FILE}" "DEPLOY_VARS"
+
+ info "Generating gateway .env from DEPLOY_VARS..."
+ write_env_to_file "${GATEWAY_ENV_FILE}" "DEPLOY_VARS"
+
+ local config_dir
+ config_dir=$(gateway_get_config_dir)
+ info "Gateway config will be deployed to: ${config_dir}/"
+ success "Gateway config files generated"
+}
+
+gateway_deploy_process() {
+ local master_host="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ local instance_name="${DEPLOY_VARS["JIUWENSWARM_INSTANCE_NAME"]}"
+
+ info "Deploying gateway in process mode on ${master_host}..."
+
+ gateway_gen_config
+
+ local config_dir
+ config_dir=$(gateway_get_config_dir)
+
+ local init_cmd="jiuwenswarm-init -f </dev/null"
+ local start_cmd="nohup jiuwenswarm-gateway </dev/null > /tmp/jiuwenswarm-gateway.log 2>&1 &"
+
+ if [ -n "${instance_name}" ]; then
+ init_cmd="JIUWENSWARM_DATA_DIR=/root/.jiuwenswarm-instances/${instance_name} jiuwenswarm-init -f </dev/null"
+ start_cmd="JIUWENSWARM_DATA_DIR=/root/.jiuwenswarm-instances/${instance_name} nohup jiuwenswarm-gateway </dev/null > /tmp/jiuwenswarm-gateway.log 2>&1 &"
+ fi
+
+ info "Running jiuwenswarm-init on ${master_host}..."
+ if exec_on_host "${master_host}" "${init_cmd}"; then
+ success "jiuwenswarm-init completed on ${master_host}"
+ else
+ error "Failed to run jiuwenswarm-init on ${master_host}"
+ fi
+
+ info "Copying gateway config.yaml and .env to ${master_host}:${config_dir}/..."
+ exec_on_host "${master_host}" "mkdir -p ${config_dir}"
+ copy_to_host "${master_host}" "${GATEWAY_CONFIG_FILE}" "${config_dir}/config.yaml"
+ copy_to_host "${master_host}" "${GATEWAY_ENV_FILE}" "${config_dir}/.env"
+
+ info "Starting jiuwenswarm-gateway on ${master_host}..."
+ exec_on_host "${master_host}" "bash -c '${start_cmd}'"
+
+ local retry=0
+ local max_retry=10
+ while [ ${retry} -lt ${max_retry} ]; do
+ sleep 2
+ if exec_on_host "${master_host}" "pgrep -f 'jiuwenswarm-gateway' >/dev/null 2>&1"; then
+ success "Gateway process is running on ${master_host}"
+ return 0
+ fi
+ retry=$((retry + 1))
+ info "Waiting for gateway to start... (${retry}/${max_retry})"
+ done
+
+ error "Gateway process failed to start on ${master_host}, check /tmp/jiuwenswarm-gateway.log"
+}
+
+gateway_undeploy_process() {
+ local master_host="${DEPLOY_VARS["MASTER_NODE_IP"]}"
+ local instance_name="${DEPLOY_VARS["JIUWENSWARM_INSTANCE_NAME"]}"
+
+ if [ -z "${master_host}" ]; then
+ if [ -n "${DEPLOY_VARS["CLUSTER_HOSTS"]:-}" ]; then
+ IFS=',' read -ra _gw_host_list <<< "${DEPLOY_VARS["CLUSTER_HOSTS"]}"
+ master_host="${_gw_host_list[0]}"
+ else
+ error "MASTER_NODE_IP is not set. Cannot determine which host to stop gateway on."
+ fi
+ fi
+
+ info "Stopping gateway on ${master_host}..."
+
+ if [ -n "${instance_name}" ]; then
+ exec_on_host "${master_host}" "pkill -f 'JIUWENSWARM_DATA_DIR=/root/.jiuwenswarm-instances/${instance_name}.*jiuwenswarm-gateway' || true"
+ else
+ exec_on_host "${master_host}" "pkill -f 'jiuwenswarm-gateway' || true"
+ fi
+
+ success "Gateway stopped on ${master_host}"
+}
+
+deploy_gateway() {
+ gateway_deploy_process
+}
+
+uninstall_gateway() {
+ gateway_undeploy_process
+}
diff --git a/deploy/yuanrong/global_vars.sh b/deploy/yuanrong/global_vars.sh
new file mode 100755
index 0000000000..0a819e50d5
--- /dev/null
+++ b/deploy/yuanrong/global_vars.sh
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+CUSTOM_ENV_FILE="${SCRIPT_DIR}/.env.custom"
+ENV_FILE="${SCRIPT_DIR}/.env"
+
+CLAW_META_PROCESS_TEMPLATE_FILE="${SCRIPT_DIR}/conf/claw_meta_process.template.json"
+CLAW_META_PROCESS_FILE="${SCRIPT_DIR}/conf/claw_meta_process.json"
+
+GATEWAY_CONFIG_TEMPLATE_FILE="${SCRIPT_DIR}/conf/gateway-config-yuanrong.template.yaml"
+GATEWAY_CONFIG_FILE="${SCRIPT_DIR}/conf/gateway-config.yaml"
+GATEWAY_ENV_FILE="${SCRIPT_DIR}/conf/gateway.env"
+
+REG_FUNC_FILE="${SCRIPT_DIR}/../../jiuwenswarm/extensions/clawee.py"
+
+META_PORT=""
+CMD=""
+
+declare -ga MODULES=()
+
+declare -A DEPLOY_VARS=(
+ ["FUNC_SVC_NAME"]="0@jiuwen@swarm"
+ ["MGR_CPU"]="300"
+ ["MGR_MEMORY"]="600"
+ ["MGR_MIN_INSTANCE"]="1"
+ ["MGR_MAX_INSTANCE"]="10"
+ ["MGR_CONCURRENT_NUM"]="10"
+ ["CLUSTER_HOSTS"]=""
+ ["YR_PYTHON_VERSION"]="3.11"
+ ["YR_FUNC_CODE_DIR"]=""
+ ["YR_SESSION_DIR"]=""
+ ["JIUWENSWARM_PACKAGE_URL"]=""
+ ["JIUWENSWARM_INSTANCE_NAME"]=""
+ ["GATEWAY_CONCURRENCY"]="1"
+ ["GATEWAY_INVOKE_TIMEOUT"]="60"
+ ["GATEWAY_SESSION_MAP_SCOPE"]="per_chat_bot_user"
+ ["MODEL_PROVIDER"]=""
+ ["MODEL_NAME"]=""
+ ["API_BASE"]=""
+ ["API_KEY"]=""
+ ["EMBED_API_KEY"]=""
+ ["EMBED_API_BASE"]=""
+ ["EMBED_MODEL"]=""
+ ["FRONTEND_PORT"]=""
+ ["FUNCTION_ID"]=""
+ ["MASTER_NODE_IP"]=""
+ ["OS_TYPE"]=""
+ ["EXTENSION_DIRS"]=""
+)
diff --git a/deploy/yuanrong/jiuwenswarm_handler.sh b/deploy/yuanrong/jiuwenswarm_handler.sh
new file mode 100644
index 0000000000..a4a3c48fb2
--- /dev/null
+++ b/deploy/yuanrong/jiuwenswarm_handler.sh
@@ -0,0 +1,302 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10"
+
+is_local_host() {
+ local host="$1"
+ if [ "${host}" = "127.0.0.1" ] || [ "${host}" = "localhost" ]; then
+ return 0
+ fi
+ local local_ips
+ local_ips=$(hostname -I 2>/dev/null || echo "")
+ for ip in ${local_ips}; do
+ if [ "${host}" = "${ip}" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+exec_on_host() {
+ local host="$1"
+ shift
+ if is_local_host "${host}"; then
+ bash -c "$*"
+ else
+ ssh ${SSH_OPTS} root@${host} "$*"
+ fi
+}
+
+copy_to_host() {
+ local host="$1"
+ local src="$2"
+ local dst="$3"
+ if is_local_host "${host}"; then
+ local src_real
+ src_real=$(realpath "${src}" 2>/dev/null || echo "${src}")
+ local dst_real
+ if [[ "${dst}" == */ ]]; then
+ dst_real=$(realpath "${dst}" 2>/dev/null || echo "${dst}")
+ dst_real="${dst_real}/$(basename "${src}")"
+ else
+ dst_real=$(realpath "${dst}" 2>/dev/null || echo "${dst}")
+ fi
+ if [ "${src_real}" = "${dst_real}" ]; then
+ return 0
+ fi
+ cp -r "${src}" "${dst}"
+ else
+ scp ${SSH_OPTS} -r "${src}" "root@${host}:${dst}"
+ fi
+}
+
+jiuwenswarm_check_ssh() {
+ local host="$1"
+ if is_local_host "${host}"; then
+ return 0
+ fi
+ if ssh ${SSH_OPTS} root@${host} "echo ok" >/dev/null 2>&1; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+jiuwenswarm_install() {
+ local host="$1"
+ local python_version="${DEPLOY_VARS["YR_PYTHON_VERSION"]}"
+
+ info "Checking jiuwenswarm on ${host}..."
+ local check_result
+ check_result=$(exec_on_host "${host}" "python${python_version} -m pip show jiuwenswarm 2>/dev/null | grep -i '^Version:' | awk '{print \$2}'" | tr -d '\r') || true
+
+ if [ -n "${check_result}" ]; then
+ success "jiuwenswarm already installed on ${host}: ${check_result}"
+ return 0
+ fi
+
+ local package_url="${DEPLOY_VARS["JIUWENSWARM_PACKAGE_URL"]}"
+ if [ -z "${package_url}" ]; then
+ error "jiuwenswarm is not installed on ${host} and JIUWENSWARM_PACKAGE_URL is not set. Please set JIUWENSWARM_PACKAGE_URL in .env.custom to provide the install package URL."
+ fi
+
+ info "Installing jiuwenswarm from ${package_url} on ${host}..."
+ if exec_on_host "${host}" "python${python_version} -m pip install ${package_url} --quiet"; then
+ success "jiuwenswarm installed on ${host}"
+ else
+ error "Failed to install jiuwenswarm on ${host}"
+ fi
+}
+
+jiuwenswarm_infer_func_code_dir() {
+ local host="$1"
+ local python_version="${DEPLOY_VARS["YR_PYTHON_VERSION"]}"
+
+ local jiuwenswarm_location
+ jiuwenswarm_location=$(exec_on_host "${host}" "python${python_version} -m pip show jiuwenswarm 2>/dev/null | grep -i '^Location:' | awk '{print \$2}'" | tr -d '\r') || true
+
+ if [ -z "${jiuwenswarm_location}" ]; then
+ error "Failed to infer YR_FUNC_CODE_DIR: jiuwenswarm not found on ${host}. Please set YR_FUNC_CODE_DIR in .env.custom."
+ fi
+
+ local inferred_dir="${jiuwenswarm_location}/jiuwenswarm/extensions"
+
+ if [ -n "${DEPLOY_VARS["YR_FUNC_CODE_DIR"]:-}" ]; then
+ if [ "${DEPLOY_VARS["YR_FUNC_CODE_DIR"]}" != "${inferred_dir}" ]; then
+ warning "YR_FUNC_CODE_DIR on ${host} (${inferred_dir}) differs from configured value (${DEPLOY_VARS["YR_FUNC_CODE_DIR"]})"
+ else
+ success "YR_FUNC_CODE_DIR verified on ${host}: ${inferred_dir}"
+ fi
+ else
+ DEPLOY_VARS["YR_FUNC_CODE_DIR"]="${inferred_dir}"
+ info "YR_FUNC_CODE_DIR inferred from jiuwenswarm install on ${host}: ${DEPLOY_VARS["YR_FUNC_CODE_DIR"]}"
+ fi
+}
+
+jiuwenswarm_ensure_func_code() {
+ local host="$1"
+ local func_dir="${DEPLOY_VARS["YR_FUNC_CODE_DIR"]}"
+ local func_file="${func_dir}/clawee.py"
+
+ info "Checking function code on ${host}:${func_dir}..."
+
+ if exec_on_host "${host}" "test -f '${func_file}'" 2>/dev/null; then
+ success "Function code already exists on ${host}: ${func_file}, skip sync"
+ return 0
+ fi
+
+ info "Function code missing on ${host}, syncing from local..."
+ exec_on_host "${host}" "mkdir -p ${func_dir}"
+ if copy_to_host "${host}" "${REG_FUNC_FILE}" "${func_dir}/"; then
+ success "Function code synced to ${host}"
+ else
+ error "Failed to sync function code to ${host}"
+ fi
+}
+
+jiuwenswarm_detect_session_dir() {
+ local master_host="$1"
+
+ DEPLOY_VARS["YR_SESSION_DIR"]=$(exec_on_host "${master_host}" "readlink /tmp/yr_sessions/latest 2>/dev/null || echo ''" | tr -d '\r')
+
+ if [ -z "${DEPLOY_VARS["YR_SESSION_DIR"]}" ]; then
+ error "Could not detect yuanrong session dir on ${master_host}. Please ensure yuanrong is deployed and started (run yuanrong_deploy.sh up first)."
+ fi
+
+ info "Detected yuanrong session dir on ${master_host}: ${DEPLOY_VARS["YR_SESSION_DIR"]}"
+}
+
+jiuwenswarm_get_meta_port() {
+ local master_host="$1"
+ local session_dir="${DEPLOY_VARS["YR_SESSION_DIR"]}"
+
+ if [ -n "${session_dir}" ]; then
+ META_PORT=$(exec_on_host "${master_host}" "cat ${session_dir}/metaservice_config.json 2>/dev/null" | jq -r '.server.port // empty' 2>/dev/null | tr -d '\r')
+ fi
+
+ if [ -z "${META_PORT}" ]; then
+ META_PORT="31182"
+ warning "Could not detect meta_service port, using default ${META_PORT}"
+ fi
+
+ info "META_PORT: ${META_PORT}"
+}
+
+jiuwenswarm_get_frontend_port() {
+ local master_host="$1"
+ local session_dir="${DEPLOY_VARS["YR_SESSION_DIR"]}"
+
+ if [ -n "${session_dir}" ]; then
+ DEPLOY_VARS["FRONTEND_PORT"]=$(exec_on_host "${master_host}" "cat ${session_dir}/frontend_init_args.json 2>/dev/null" | jq -r '.http.serverListenPort // empty' 2>/dev/null | tr -d '\r')
+ fi
+
+ if [ -z "${DEPLOY_VARS["FRONTEND_PORT"]:-}" ]; then
+ DEPLOY_VARS["FRONTEND_PORT"]="8888"
+ warning "Could not detect frontend port, using default ${DEPLOY_VARS["FRONTEND_PORT"]}"
+ fi
+
+ info "FRONTEND_PORT: ${DEPLOY_VARS["FRONTEND_PORT"]}"
+}
+
+jiuwenswarm_register_func() {
+ local master_host="$1"
+
+ jiuwenswarm_get_meta_port "${master_host}"
+ jiuwenswarm_get_frontend_port "${master_host}"
+
+ DEPLOY_VARS["MASTER_NODE_IP"]="${master_host}"
+
+ info "Registering jiuwenswarm function on process-mode openyuanrong..."
+ render_config_template "${CLAW_META_PROCESS_TEMPLATE_FILE}" "${CLAW_META_PROCESS_FILE}" "DEPLOY_VARS"
+
+ info "curl -X POST -H \"Content-Type: application/json\" -H \"x-storage-type: local\" http://${master_host}:${META_PORT}/serverless/v1/functions -d @${CLAW_META_PROCESS_FILE}"
+ local res
+ res=$(curl -s -X POST -H "Content-Type: application/json" -H "x-storage-type: local" "http://${master_host}:${META_PORT}/serverless/v1/functions" -d @"${CLAW_META_PROCESS_FILE}")
+ info "Function registration result: ${res}"
+
+ local code
+ code=$(echo "${res}" | jq -r '.code' 2>/dev/null || echo "-1")
+ if [[ "${code}" != "0" ]]; then
+ error "Failed to register serverless function"
+ fi
+
+ DEPLOY_VARS["FUNCTION_ID"]=$(echo "${res}" | jq -r '.function.id')
+ success "Serverless function registered successfully! function_id: ${DEPLOY_VARS["FUNCTION_ID"]}"
+}
+
+deploy_jiuwenswarm() {
+ local hosts_str="${DEPLOY_VARS["CLUSTER_HOSTS"]}"
+ local master_host
+
+ IFS=',' read -ra JIUWENSWARM_HOST_LIST <<< "${hosts_str}"
+ master_host="${JIUWENSWARM_HOST_LIST[0]}"
+
+ info "Deploying jiuwenswarm"
+ info "Master host (yr master): ${master_host}"
+ info "Total hosts: ${#JIUWENSWARM_HOST_LIST[@]}"
+ info "Assuming yuanrong is already deployed on all hosts"
+
+ info "Checking connectivity to all hosts..."
+ for host in "${JIUWENSWARM_HOST_LIST[@]}"; do
+ if is_local_host "${host}"; then
+ success "${host} is local host, skip SSH check"
+ elif jiuwenswarm_check_ssh "${host}"; then
+ success "SSH to ${host} OK"
+ else
+ error "SSH to ${host} failed! Please configure SSH key authentication first."
+ fi
+ done
+
+ for host in "${JIUWENSWARM_HOST_LIST[@]}"; do
+ jiuwenswarm_install "${host}"
+ jiuwenswarm_infer_func_code_dir "${host}"
+ jiuwenswarm_ensure_func_code "${host}"
+ done
+
+ info "Registering function on yr master node (${master_host})..."
+ jiuwenswarm_detect_session_dir "${master_host}"
+ jiuwenswarm_register_func "${master_host}"
+
+ success "jiuwenswarm deployment completed!"
+ echo ""
+ echo "=========================================="
+ success "Deployment Summary"
+ echo "=========================================="
+ echo " YR Master: ${master_host}"
+ echo " Function ID: ${DEPLOY_VARS["FUNCTION_ID"]}"
+ echo " Meta Port: ${META_PORT}"
+ echo " Frontend Port: ${DEPLOY_VARS["FRONTEND_PORT"]}"
+ echo " Func Code Dir: ${DEPLOY_VARS["YR_FUNC_CODE_DIR"]}"
+ echo ""
+ echo " Next step: deploy gateway"
+ echo " ./$(basename "$0") up gateway --hosts ${hosts_str}"
+ echo "=========================================="
+}
+
+uninstall_jiuwenswarm() {
+ local hosts_str="${DEPLOY_VARS["CLUSTER_HOSTS"]}"
+
+ if [ -z "${hosts_str}" ]; then
+ error "CLUSTER_HOSTS is not set. Cannot determine master host."
+ fi
+
+ IFS=',' read -ra JIUWENSWARM_HOST_LIST <<< "${hosts_str}"
+ local master_host="${JIUWENSWARM_HOST_LIST[0]}"
+
+ local func_svc_name="${DEPLOY_VARS["FUNC_SVC_NAME"]}"
+ if [ -z "${func_svc_name}" ]; then
+ error "FUNC_SVC_NAME is not set. Please set it in .env.custom."
+ fi
+
+ info "Unregistering jiuwenswarm function on yr master (${master_host})..."
+
+ # 复用 up 流程的检测逻辑,获取 session dir 和 meta port
+ jiuwenswarm_detect_session_dir "${master_host}"
+ jiuwenswarm_get_meta_port "${master_host}"
+
+ local delete_url="http://${master_host}:${META_PORT}/serverless/v1/functions/${func_svc_name}"
+ info "curl -H \"Content-type: application/json\" -X DELETE ${delete_url}"
+
+ local res
+ res=$(curl -s -H "Content-type: application/json" -X DELETE "${delete_url}")
+ info "Function unregistration result: ${res}"
+
+ # DELETE 成功返回 {}(无 code 字段)或 code=0;其他视为失败
+ local code
+ code=$(echo "${res}" | jq -r '.code // "none"' 2>/dev/null || echo "error")
+ if [[ "${code}" == "0" || "${code}" == "none" ]]; then
+ success "Serverless function unregistered successfully: ${func_svc_name}"
+ else
+ warning "Failed to unregister serverless function (may not exist): ${res}"
+ fi
+
+ echo ""
+ echo "=========================================="
+ success "jiuwenswarm uninstall completed!"
+ echo "=========================================="
+ echo " YR Master: ${master_host}"
+ echo " Function: ${func_svc_name}"
+ echo " Meta Port: ${META_PORT}"
+ echo "=========================================="
+}
diff --git a/deploy/yuanrong/template_handler.sh b/deploy/yuanrong/template_handler.sh
new file mode 100644
index 0000000000..802a03f512
--- /dev/null
+++ b/deploy/yuanrong/template_handler.sh
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+set -euo >/dev/null 2>&1
+
+# === Extracts and deduplicates <<variable>> placeholders from template ===
+extract_placeholders() {
+ local templatefile="$1"
+ local -a placeholders=($(grep -oE '<<[^>]+>>' "${templatefile}" | sort -u))
+ echo "${placeholders[@]}"
+}
+
+# ==== Replaces <<variable>> placeholder with its value ===
+replace_placeholder() {
+ local placeholder="$1"
+ local destfile="$2"
+ local vars_arr_name=$3
+ local var_name=$(echo "${placeholder}" | sed -e 's/^<<//' -e 's/>>$//')
+ local arr_key_ref="${vars_arr_name}[${var_name}]"
+ local var_value="${!arr_key_ref:-}"
+ local os_type=${DEPLOY_VARS["OS_TYPE"]}
+
+ #info " Replacing placeholder: ${placeholder} → ${var_value}"
+ if [ "${os_type}" == "macos" ]; then
+ # macOS sed requires backup extension with -i
+ sed -i.bak "s|${placeholder}|${var_value}|g" "${destfile}"
+ rm -f "${destfile}.bak"
+ else
+ # Linux/Windows: use awk
+ awk -v ph="${placeholder}" -v val="${var_value}" '
+ { gsub(ph, val); print }
+ ' "${destfile}" > "${destfile}.tmp" && mv -f "${destfile}.tmp" "${destfile}"
+ fi
+}
+
+# ==== Renders configuration from template and replaces variables ===
+render_config_template(){
+ local templatefile=$1
+ local destfile=$2
+ local var_name=$3
+ # Verify template file exists
+ if [ ! -f "${templatefile}" ]; then
+ error "Template file does not exist: ${templatefile}"
+ fi
+ info "Using template file: ${templatefile}"
+
+ # Extract all placeholders
+ local -a placeholders=($(extract_placeholders "${templatefile}"))
+ if [ ${#placeholders[@]} -eq 0 ]; then
+ warning "No <<variable_name>> format placeholders found in template file"
+ fi
+
+ # Copy template as target file
+ exec_cmd cp -f ${templatefile} ${destfile}
+
+ # Loop to replace each placeholder
+ info "Starting placeholder replacement..."
+ for placeholder in "${placeholders[@]}"; do
+ replace_placeholder "${placeholder}" "${destfile}" "${var_name}"
+ done
+
+ success "Generated config file: ${destfile}"
+}
+
+
diff --git a/jiuwenswarm/extensions/agent_client/__init__.py b/jiuwenswarm/extensions/agent_client/__init__.py
new file mode 100644
index 0000000000..34215209b9
--- /dev/null
+++ b/jiuwenswarm/extensions/agent_client/__init__.py
@@ -0,0 +1,3 @@
+from .extension import register_extensions
+
+__all__ = ["register_extensions"]
diff --git a/deploy/extensions/agent_client/extension.py b/jiuwenswarm/extensions/agent_client/extension.py
similarity index 100%
rename from deploy/extensions/agent_client/extension.py
rename to jiuwenswarm/extensions/agent_client/extension.py
diff --git a/deploy/extensions/agent_client/extension.yaml b/jiuwenswarm/extensions/agent_client/extension.yaml
similarity index 100%
rename from deploy/extensions/agent_client/extension.yaml
rename to jiuwenswarm/extensions/agent_client/extension.yaml
diff --git a/deploy/func/clawee.py b/jiuwenswarm/extensions/clawee.py
similarity index 100%
rename from deploy/func/clawee.py
rename to jiuwenswarm/extensions/clawee.py