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
support to start agent-runtime in deploy tool
chen-hui-zhe-xi398caff66455
diff --git a/deploy/enterprise/.env.example b/deploy/enterprise/.env.exampleindex 19c18e6eb4..4deeb7811f 100644--- a/deploy/enterprise/.env.example+++ b/deploy/enterprise/.env.example@@ -77,14 +77,16 @@ DB_HOST="" # 外部数据服务的连接地址, 不设置则使用本工具内DB_PORT="" # 数据服务的连接端口(本工具内置部署的数据库服务时设置端口,外部数据库服务填写对应端口)MANAGER_DB_NAME="" # Manager 业务模块对应的数据库实例名称,未设置则使用默认值"manager"GATEWAY_DB_NAME="" # Gateway 网关服务对应的数据库实例名称,未设置则使用默认值"gateway"-IDENTITY_DB_NAME="" # Identity 服务对应的数据库实例名称,未设置则使用默认值"identity+IDENTITY_DB_NAME="" # Identity 服务对应的数据库实例名称,未设置则使用默认值"identity"WEB_DB_NAME="" # 企业 Web 会话历史库名称,未设置则使用默认值"web"+AGENT_RUNTIME_DB_NAME="" # Agent Runtime 服务对应的数据库实例名称,未设置则使用默认值"runtime"+# 仅 DB_TYPE 取值为 postgresql / mysql 且使用外部独立数据库服务时,本段账号配置生效,账号权限区分规则:-# 1. 分库独立账号配置:分别定义 MANAGER_DB_USER / MANAGER_DB_PASSWORD、GATEWAY_DB_USER / GATEWAY_DB_PASSWORD、WEB_DB_USER / WEB_DB_PASSWORD-# 2. 全局统一账号配置:仅配置 DB_USER、DB_PASSWORD,Manager、Gateway、Web 共用同一套数据库访问凭证-# 地址/端口与 Manager、Gateway 一样使用上面的 DB_HOST / DB_PORT-# 未单独配 WEB_DB_USER/PASSWORD 时,部署脚本回退到全局 DB_USER / DB_PASSWORD(与 Manager/Gateway 相同规则)+# 1. 分库独立账号配置:分别定义 MANAGER_DB_USER / MANAGER_DB_PASSWORD、GATEWAY_DB_USER / GATEWAY_DB_PASSWORD、WEB_DB_USER / WEB_DB_PASSWORD、RUNTIME_DB_USER / RUNTIME_DB_PASSWORD+# 2. 全局统一账号配置:仅配置 DB_USER、DB_PASSWORD,Manager、Gateway、Web、Agent Runtime 共用同一套数据库访问凭证+# 地址/端口使用上面的 DB_HOST / DB_PORT+# 未单独配时,部署脚本回退到全局 DB_USER / DB_PASSWORD(与 Manager/Gateway 相同规则)# 优先级规则:分库专属账号变量优先级 > 全局通用账号变量;若两类变量同时配置,以分库专属账号为准,全局账号配置自动失效DB_USER=""DB_PASSWORD=""@@ -96,6 +98,9 @@ IDENTITY_DB_USER=""IDENTITY_DB_PASSWORD=""WEB_DB_USER=""WEB_DB_PASSWORD=""+RUNTIME_DB_USER=""+RUNTIME_DB_PASSWORD=""+# Gateway / AgentServer 访问 MySQL、PostgreSQL 时的 SQLAlchemy 连接池参数# 会写入 Gateway 环境并通过 Runtime Management 下发给 AgentServer Pod@@ -474,8 +479,6 @@ MANAGER_WEB_CPU_LIMIT=500m# MANAGER_WEB 服务的容器最大可用 内存:1Gi,超过会被 K8s OOM kill 杀死重启MANAGER_WEB_MEMORY_LIMIT=1Gi--# Identity(身份中心 / idp) 镜像地址IDENTITY_IMAGE=""@@ -484,7 +487,21 @@ IDENTITY_SEED_ADMIN=trueIDENTITY_SEED_USER1=true+# ====================== Agent Runtime 服务配置 ======================+# Agent Runtime 服务镜像地址+AGENT_RUNTIME_IMAGE=""++# Agent Runtime 副本实例数量,控制部署运行的 Pod 个数+AGENT_RUNTIME_REPLICAS=1++# 服务端单次请求处理超时秒数,0 表示不限制+AGENT_RUNTIME_REQUEST_TIMEOUT=300++# scope 满载时等待队列超时秒数+AGENT_RUNTIME_SCOPE_FULL_TIMEOUT=8+# 日志输出级别,可选: DEBUG, INFO, WARNING, ERROR, CRITICAL+AGENT_RUNTIME_LOG_LEVEL=INFO# ====================== 大模型接口配置 ======================# 模型厂商标识(如:OpenAI等)diff --git a/deploy/enterprise/args_handler.sh b/deploy/enterprise/args_handler.shindex 2ada7baa37..55c8c8c778 100755--- a/deploy/enterprise/args_handler.sh+++ b/deploy/enterprise/args_handler.sh@@ -12,7 +12,7 @@ parse_args() {CMD="${args[$i]}"i=$((i+1));;- nfs|nfs-sc|rabbitmq|mysql|redis|postgresql|minio|log|jina|gateway|web|manager)+ nfs|nfs-sc|rabbitmq|mysql|redis|postgresql|minio|log|jina|gateway|web|manager|runtime)MODULES+=("${args[$i]^^}")i=$((i+1));;@@ -51,7 +51,7 @@ parse_args() {}process_modules() {- MODULES=("GATEWAY" "WEB" "MANAGER")+ MODULES=("GATEWAY" "WEB" "MANAGER" "RUNTIME")}# Print help info and exitdiff --git a/deploy/enterprise/check_handler.sh b/deploy/enterprise/check_handler.shindex 23f1e6e209..edbd29a0cf 100755--- a/deploy/enterprise/check_handler.sh+++ b/deploy/enterprise/check_handler.sh@@ -171,7 +171,7 @@ check_if_db_up() {mysql)DEPLOY_VARS["DB_HOST"]="${name}-headless.default"DEPLOY_VARS["DB_PORT"]="3306"- for module in GATEWAY WEB MANAGER IDENTITY+ for module in GATEWAY WEB MANAGER IDENTITY RUNTIMEdoDEPLOY_VARS["${module}_DB_USER"]="root"DEPLOY_VARS["${module}_DB_PASSWORD"]=${DEPLOY_VARS["MYSQL_ROOT_PASSWORD"]}@@ -180,7 +180,7 @@ check_if_db_up() {postgresql)DEPLOY_VARS["DB_HOST"]="${name}-headless.default"DEPLOY_VARS["DB_PORT"]="5432"- for module in GATEWAY WEB MANAGER IDENTITY+ for module in GATEWAY WEB MANAGER IDENTITY RUNTIMEdoDEPLOY_VARS["${module}_DB_USER"]="postgres"DEPLOY_VARS["${module}_DB_PASSWORD"]=${DEPLOY_VARS["POSTGRESQL_PASSWORD"]}@@ -199,7 +199,7 @@ check_if_db_up() {error "Please define DB_PORT in .env.custom"fi- for module in GATEWAY WEB MANAGER IDENTITY+ for module in GATEWAY WEB MANAGER IDENTITY RUNTIMEdoif [ -z "${DEPLOY_VARS["${module}_DB_USER"]:-}" ]; thenDEPLOY_VARS["${module}_DB_USER"]=${DEPLOY_VARS["DB_USER"]}@@ -238,14 +238,15 @@ check_if_obs_up() {}check_if_redis_up() {- local mode="${DEPLOY_VARS["DEPLOYMENT_MODE"]:-standalone}"- local name="${DEPLOY_VARS["REDIS_NAME"]}"-- if [[ "${mode}" != "active-standby" ]]; then- info "DEPLOYMENT_MODE=${mode}, skip Redis check"+ # 已经执行过检查,直接返回,避免重复校验+ if [[ "${DEPLOY_VARS["REDIS_CHECKED"]:-}" == "true" ]]; thenreturnfi+ local mode="${DEPLOY_VARS["DEPLOYMENT_MODE"]}"+ local name="${DEPLOY_VARS["REDIS_NAME"]}"++ DEPLOY_VARS["REDIS_CHECKED"]="true"if [ -n "${DEPLOY_VARS["REDIS_HOST"]:-}" ]; theninfo "Use external Redis server"DEPLOY_VARS["ENABLE_EXTERNAL_REDIS"]="true"@@ -258,7 +259,7 @@ check_if_redis_up() {fiinfo "Use built-in Redis server"- DEPLOY_VARS["REDIS_HOST"]="${name}.default.svc.cluster.local"+ DEPLOY_VARS["REDIS_HOST"]="${name}.default"DEPLOY_VARS["REDIS_PORT"]="6379"}@@ -469,3 +470,8 @@ check_manager_up_dependency(){#check_if_rabbitmq_upcheck_if_db_up}++check_runtime_up_dependency(){+ check_if_db_up+ check_if_redis_up+}diff --git a/deploy/enterprise/configmap_secret_handler.sh b/deploy/enterprise/configmap_secret_handler.shindex f2ed30b5a0..c65ad90326 100755--- a/deploy/enterprise/configmap_secret_handler.sh+++ b/deploy/enterprise/configmap_secret_handler.sh@@ -17,6 +17,7 @@ render_secret_configmap() {"MANAGER_DB_PASSWORD""IDENTITY_DB_PASSWORD""WEB_DB_PASSWORD"+ "RUNTIME_DB_PASSWORD""REDIS_PASSWORD""OBS_SECRET_KEY""API_KEY"@@ -53,10 +54,11 @@ uninstall_secret_configmap() {"${DEPLOY_VARS["GATEWAY_NAME"]}""${DEPLOY_VARS["MANAGER_SERVER_NAME"]}""${DEPLOY_VARS["WEB_NAME"]}"+ "${DEPLOY_VARS["AGENT_RUNTIME_NAME"]}")local file="${CONFIG["SECRET_CM_FILE"]}"- # Gateway、Web、Manager这三个组件都依赖于本资源,检查三者是否存在,若存在不能删除本资源+ # Gateway、Web、Manager、AgentRuntime这些组件都依赖于本资源,检查它们是否存在,若存在不能删除本资源for cname in "${component_names[@]}"; doif check_k8s_resource_exists "deployment" "${cname}" "${namespace}"; thenwarning "Deployment ${namespace}/${cname} exists, skip deleting ${namespace}/${name}."diff --git a/deploy/enterprise/deploy.sh b/deploy/enterprise/deploy.shindex ccb8765f68..cfbf5b785e 100755--- a/deploy/enterprise/deploy.sh+++ b/deploy/enterprise/deploy.sh@@ -22,6 +22,7 @@ source "configmap_secret_handler.sh"source "gateway_handler.sh"source "manager_handler.sh"source "web_handler.sh"+source "runtime_handler.sh"process_up() {# MODULES是ALL_MODULES的子集,启动顺序正着来diff --git a/deploy/enterprise/global_vars.sh b/deploy/enterprise/global_vars.shindex e0ecd60266..c7af596299 100755--- a/deploy/enterprise/global_vars.sh+++ b/deploy/enterprise/global_vars.sh@@ -56,6 +56,9 @@ declare -A CONFIG=(["MANAGER_WEB_TEMPLATE_FILE"]="${TEMPLATE_DIR}/manager-web.template.yaml"["MANAGER_WEB_FILE"]="${CONFIG_DIR}/manager-web.yaml"+ ["RUNTIME_TEMPLATE_FILE"]="${TEMPLATE_DIR}/runtime.template.yaml"+ ["RUNTIME_FILE"]="${CONFIG_DIR}/runtime.yaml"+["IDENTITY_TEMPLATE_FILE"]="${TEMPLATE_DIR}/identity.template.yaml"["IDENTITY_FILE"]="${CONFIG_DIR}/identity.yaml"@@ -79,7 +82,7 @@ declare -A ARGS=(# ==== All available modules ====-declare -ga ALL_MODULES=("NFS" "NFS-SC" "RABBITMQ" "MYSQL" "REDIS" "POSTGRESQL" "MINIO" "LOG" "JINA" "GATEWAY" "WEB" "MANAGER")+declare -ga ALL_MODULES=("NFS" "NFS-SC" "RABBITMQ" "MYSQL" "REDIS" "POSTGRESQL" "MINIO" "LOG" "JINA" "GATEWAY" "WEB" "MANAGER" "RUNTIME")declare -ga MODULES=()@@ -213,6 +216,15 @@ declare -A DEPLOY_VARS=(["WEB_NAME"]="jiuwenclaw-web"["WEB_WS_PORT"]="19000"["WEB_HTTP_PORT"]="5173"+ ["AGENT_RUNTIME_NAME"]="jiuwenclaw-agent-runtime"+ ["AGENT_RUNTIME_IMAGE"]=""+ ["AGENT_RUNTIME_REPLICAS"]="1"+ ["AGENT_RUNTIME_PORT"]="8091"+ ["AGENT_RUNTIME_DB_NAME"]="runtime"+ ["AGENT_RUNTIME_REDIS_DB"]="2"+ ["AGENT_RUNTIME_REQUEST_TIMEOUT"]="300"+ ["AGENT_RUNTIME_SCOPE_FULL_TIMEOUT"]="8"+ ["AGENT_RUNTIME_LOG_LEVEL"]="INFO"["WS_ALLOWED_ORIGINS"]=""["WS_ORIGIN_CHECK_ENABLED"]="false")diff --git a/deploy/enterprise/runtime_handler.sh b/deploy/enterprise/runtime_handler.shnew file mode 100755index 0000000000..f1b5896338--- /dev/null+++ b/deploy/enterprise/runtime_handler.sh@@ -0,0 +1,56 @@+#!/usr/bin/env bash+set -euo >/dev/null 2>&1++gen_runtime_file() {+ local template_file="${CONFIG["RUNTIME_TEMPLATE_FILE"]}"+ local file="${CONFIG["RUNTIME_FILE"]}"++ render_config_template "${template_file}" "${file}" "DEPLOY_VARS"+ enable_dev_mode_if_needed ${file} runtime++ add_resource_if_set "RUNTIME" "${file}"+}++render_runtime_files() {+ render_secret_configmap+ gen_runtime_file+}++deploy_runtime() {+ local namespace="${DEPLOY_VARS["NAMESPACE"]}"+ local name="${DEPLOY_VARS["AGENT_RUNTIME_NAME"]}"+ local file="${CONFIG["RUNTIME_FILE"]}"++ ensure_secret_configmap+ exec_cmd kubectl apply -f ${file}+ wait_k8s_resource_ready "deployment" "${name}" "${namespace}"+ success "AGENT_RUNTIME_PORT: ${DEPLOY_VARS["AGENT_RUNTIME_PORT"]}"+}++uninstall_runtime() {+ local namespace="${DEPLOY_VARS["NAMESPACE"]}"+ local name="${DEPLOY_VARS["AGENT_RUNTIME_NAME"]}"+ local file="${CONFIG["RUNTIME_FILE"]}"++ # 先删 Deployment(保持 ServiceAccount 不删),等 Pod 优雅退出+ # runtime.yaml 含 ServiceAccount / Role / Deployment 等同文件资源。+ # 不可 kubectl delete -f 一次性删:SA 被删后 Pod 仍在 Terminating 窗口内,+ # in-cluster token 立即失效 → runtime shutdown 删 AgentServer Pod 会 401。+ info "Deleting Runtime Deployment first (keep ServiceAccount for graceful shutdown)"+ exec_cmd kubectl delete deployment "${name}" -n "${namespace}" --ignore-not-found=true+ wait_pod_terminated "${name}" "${namespace}"++ # 兜底清理 runtime 动态创建的 agentserver pod(按 label)+ local orphan_pods+ orphan_pods=$(kubectl get pods -n "${namespace}" -l jiuwenclaw-component=agentserver -o name 2>/dev/null || true)+ if [ -n "${orphan_pods}" ]; then+ info "Cleaning up orphan agentserver pods created by runtime (label: jiuwenclaw-component=agentserver)"+ exec_cmd kubectl delete pod -n "${namespace}" -l jiuwenclaw-component=agentserver --ignore-not-found=true+ else+ info "No orphan agentserver pods to clean up."+ fi++ info "Deleting remaining Runtime resources (ServiceAccount, Role, Service, ...)"+ exec_cmd kubectl delete -f "${file}" --ignore-not-found=true+ uninstall_secret_configmap+}diff --git a/deploy/enterprise/template_handler.sh b/deploy/enterprise/template_handler.shindex 3ccefd4a34..77ce34591a 100755--- a/deploy/enterprise/template_handler.sh+++ b/deploy/enterprise/template_handler.sh@@ -163,6 +163,9 @@ enable_dev_mode_if_needed() {manager-server)mount_runtime_code "${file}";;+ runtime)+ mount_runtime_code "${file}"+ ;;identity)mount_runtime_code "${file}";;diff --git a/deploy/enterprise/templates/configmap-secret.template.yaml b/deploy/enterprise/templates/configmap-secret.template.yamlindex fbab0887fb..7a29687ae5 100644--- a/deploy/enterprise/templates/configmap-secret.template.yaml+++ b/deploy/enterprise/templates/configmap-secret.template.yaml@@ -9,6 +9,7 @@ data:MANAGER_DB_PASSWORD: "<<MANAGER_DB_PASSWORD_ENCODED>>"IDENTITY_DB_PASSWORD: "<<IDENTITY_DB_PASSWORD_ENCODED>>"WEB_DB_PASSWORD: "<<WEB_DB_PASSWORD_ENCODED>>"+ OPENJIUWEN_SERVICE_DB_PASSWORD: "<<RUNTIME_DB_PASSWORD_ENCODED>>"REDIS_PASSWORD: "<<REDIS_PASSWORD_ENCODED>>"JIUWENCLAW_MINIO_SECRET_KEY: "<<OBS_SECRET_KEY_ENCODED>>"API_KEY: "<<API_KEY_ENCODED>>"diff --git a/deploy/enterprise/templates/runtime.template.yaml b/deploy/enterprise/templates/runtime.template.yamlnew file mode 100644index 0000000000..00ec1a4914--- /dev/null+++ b/deploy/enterprise/templates/runtime.template.yaml@@ -0,0 +1,139 @@+# ServiceAccount+apiVersion: v1+kind: ServiceAccount+metadata:+ name: <<AGENT_RUNTIME_NAME>>-sa+ namespace: <<NAMESPACE>>++---+# RBAC:agent-runtime 需要 CRUD AgentServer Pod(与 gateway 的 agentserver-creator 同面)+apiVersion: rbac.authorization.k8s.io/v1+kind: Role+metadata:+ name: <<AGENT_RUNTIME_NAME>>-agentserver-creator+ namespace: <<NAMESPACE>>+rules:+ - apiGroups: [""]+ resources: ["pods"]+ verbs: ["get", "list", "watch", "create", "delete"]+ - apiGroups: [""]+ resources: ["pods/log"]+ verbs: ["get"]+---+apiVersion: rbac.authorization.k8s.io/v1+kind: RoleBinding+metadata:+ name: <<AGENT_RUNTIME_NAME>>-agentserver-binding+ namespace: <<NAMESPACE>>+subjects:+ - kind: ServiceAccount+ name: <<AGENT_RUNTIME_NAME>>-sa+ namespace: <<NAMESPACE>>+roleRef:+ kind: Role+ name: <<AGENT_RUNTIME_NAME>>-agentserver-creator+ apiGroup: rbac.authorization.k8s.io++---+# Deployment+apiVersion: apps/v1+kind: Deployment+metadata:+ name: <<AGENT_RUNTIME_NAME>>+ namespace: <<NAMESPACE>>+ labels:+ app: <<AGENT_RUNTIME_NAME>>+spec:+ replicas: <<AGENT_RUNTIME_REPLICAS>>+ selector:+ matchLabels:+ app: <<AGENT_RUNTIME_NAME>>+ template:+ metadata:+ labels:+ app: <<AGENT_RUNTIME_NAME>>+ spec:+ serviceAccountName: <<AGENT_RUNTIME_NAME>>-sa+ affinity:+ podAntiAffinity:+ preferredDuringSchedulingIgnoredDuringExecution:+ - weight: 100+ podAffinityTerm:+ labelSelector:+ matchExpressions:+ - key: app+ operator: In+ values:+ - <<AGENT_RUNTIME_NAME>>+ topologyKey: "kubernetes.io/hostname"+ containers:+ - name: agent-runtime+ image: <<AGENT_RUNTIME_IMAGE>>+ imagePullPolicy: IfNotPresent+ ports:+ - name: rest+ containerPort: <<AGENT_RUNTIME_PORT>>+ readinessProbe:+ httpGet:+ path: /healthz+ port: rest+ initialDelaySeconds: 5+ periodSeconds: 5+ livenessProbe:+ httpGet:+ path: /healthz+ port: rest+ initialDelaySeconds: 10+ periodSeconds: 10+ envFrom:+ - secretRef:+ name: <<SECRET_CM_NAME>>+ env:+ - name: AGENT_RUNTIME_MODE+ value: "server"+ - name: OPENJIUWEN_SERVICE_HOST+ value: "0.0.0.0"+ - name: OPENJIUWEN_SERVICE_PORT+ value: "<<AGENT_RUNTIME_PORT>>"+ - name: OPENJIUWEN_SERVICE_REDIS_URL+ value: "redis://<<REDIS_HOST>>:<<REDIS_PORT>>/<<AGENT_RUNTIME_REDIS_DB>>"+ - name: OPENJIUWEN_SERVICE_REQUEST_TIMEOUT_SECONDS+ value: "<<AGENT_RUNTIME_REQUEST_TIMEOUT>>"+ - name: OPENJIUWEN_SERVICE_DB_TYPE+ value: "<<DB_TYPE>>"+ - name: OPENJIUWEN_SERVICE_DB_HOST+ value: "<<DB_HOST>>"+ - name: OPENJIUWEN_SERVICE_DB_PORT+ value: "<<DB_PORT>>"+ - name: OPENJIUWEN_SERVICE_DB_NAME+ value: "<<AGENT_RUNTIME_DB_NAME>>"+ - name: OPENJIUWEN_SERVICE_DB_USER+ value: "<<RUNTIME_DB_USER>>"+ - name: OPENJIUWEN_SERVICE_DEPLOY_REPLICAS+ value: "1"+ - name: AGENT_RUNTIME_KUBECONFIG+ value: ""+ - name: AGENT_RUNTIME_DEFAULT_NAMESPACE+ value: "<<NAMESPACE>>"+ - name: AGENT_RUNTIME_SCOPE_FULL_TIMEOUT+ value: "<<AGENT_RUNTIME_SCOPE_FULL_TIMEOUT>>"+ - name: AGENT_RUNTIME_LOG_LEVEL+ value: "<<AGENT_RUNTIME_LOG_LEVEL>>"+ - name: TZ+ value: "<<TIMEZONE>>"++---+# Service:ClusterIP(gateway / 其它服务经此访问 agent-runtime)+apiVersion: v1+kind: Service+metadata:+ name: <<AGENT_RUNTIME_NAME>>+ namespace: <<NAMESPACE>>+spec:+ selector:+ app: <<AGENT_RUNTIME_NAME>>+ ports:+ - name: rest+ port: <<AGENT_RUNTIME_PORT>>+ targetPort: <<AGENT_RUNTIME_PORT>>+ type: ClusterIP