From f98293d4e8d3a0ebf466983fe17dd35c0dd4411a Mon Sep 17 00:00:00 2001 From: root Date: Mon, 4 May 2026 20:28:27 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=20agent=20=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E6=A8=A1=E6=9D=BF=E7=A7=BB=E5=88=B0=20config/agent-te?= =?UTF-8?q?mplates/=EF=BC=8C=E5=9C=A8=20Step=206=20=E9=9B=86=E6=88=90?= =?UTF-8?q?=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了顶层 agent-templates/ 目录 - 角色模板移到 config/agent-templates/,属于 agent 配置范畴 - Step 6 新增 6.2 子步:复制角色模板 + 替换占位符 - Step 7.4 验证也覆盖角色模板的占位符 - config/agent-templates/README.md 更新为引用 Step 6.2 --- README.md | 41 ++++++++++++++++++- .../agent-templates}/AGENTS.md | 0 .../agent-templates}/HEARTBEAT.md | 0 .../agent-templates}/IDENTITY.md | 0 .../agent-templates}/README.md | 19 ++++++--- .../agent-templates}/SOUL.md | 0 .../agent-templates}/TOOLS.md | 0 .../agent-templates}/USER.md | 0 8 files changed, 52 insertions(+), 8 deletions(-) rename {agent-templates => config/agent-templates}/AGENTS.md (100%) rename {agent-templates => config/agent-templates}/HEARTBEAT.md (100%) rename {agent-templates => config/agent-templates}/IDENTITY.md (100%) rename {agent-templates => config/agent-templates}/README.md (73%) rename {agent-templates => config/agent-templates}/SOUL.md (100%) rename {agent-templates => config/agent-templates}/TOOLS.md (100%) rename {agent-templates => config/agent-templates}/USER.md (100%) diff --git a/README.md b/README.md index 8306dff..f119771 100644 --- a/README.md +++ b/README.md @@ -529,6 +529,43 @@ else: " ``` +#### 6.2 部署角色定义文件(AGENTS.md / SOUL.md 等) + +将角色模板文件复制到 agent workspace。这些文件定义 agent 的人设、安全红线、越狱防护和内容审查规则。 + +```bash +source /tmp/env_vars.sh + +# 模板目录在本仓库 config/agent-templates/ +TEMPLATES_DIR="/opt/chatrebot_aireply_plug/config/agent-templates" + +if [ -d "$TEMPLATES_DIR" ]; then + # 复制模板文件(不覆盖已有文件) + for f in AGENTS.md SOUL.md IDENTITY.md USER.md TOOLS.md HEARTBEAT.md; do + if [ ! -f "${AGENT_WORKSPACE}/${f}" ]; then + cp "${TEMPLATES_DIR}/${f}" "${AGENT_WORKSPACE}/${f}" + echo "created: ${f}" + else + echo "跳过(已存在): ${f}" + fi + done + + # ─── 替换占位符 ─── + cd "${AGENT_WORKSPACE}" + sed -i "s/ADMIN_QQ/${ADMIN_QQ}/g" *.md + sed -i "s|ADMIN_NAME|${ADMIN_NAME}|g" *.md + sed -i "s|ADMIN_GAME_ID|${ADMIN_GAME_ID}|g" *.md + sed -i "s|AGENT_WORKSPACE|${AGENT_WORKSPACE}|g" *.md + + echo "✅ 角色文件已部署,占位符已替换" +else + echo "⚠️ 模板目录不存在:$TEMPLATES_DIR,请确认仓库已克隆到 /opt/chatrebot_aireply_plug" +fi +``` + +> ⚡ 这些模板文件从 `config/agent-templates/` 复制到 agent workspace 后,sed 自动将 `ADMIN_QQ`、`ADMIN_NAME`、`AGENT_WORKSPACE` 替换为实际值。 +> 如需自定义人设,可直接编辑 agent workspace 中的对应 `.md` 文件。 + --- ### 第7步:将脚本和 Skills 部署到 agent workspace @@ -592,10 +629,10 @@ source /tmp/env_vars.sh echo "scripts: $(ls "${AGENT_WORKSPACE}/scripts/" | wc -l) 个" echo "skills: $(ls "${AGENT_WORKSPACE}/skills/" | wc -l) 个" -if grep -r "YOUR_ADMIN_QQ\|YOUR_WORKSPACE_PATH\|YOUR_NAPCAT_HOST\|YOUR_SHARED_DIR" "${AGENT_WORKSPACE}/"; then +if grep -r "YOUR_ADMIN_QQ\|YOUR_WORKSPACE_PATH\|YOUR_NAPCAT_HOST\|YOUR_SHARED_DIR\|ADMIN_QQ\|AGENT_WORKSPACE" "${AGENT_WORKSPACE}/"; then echo "⚠️ 还有未替换的占位符!" else - echo "✅ 占位符全部替换完毕" + echo "✅ 占位符全部替换完毕(含角色模板)" fi ``` diff --git a/agent-templates/AGENTS.md b/config/agent-templates/AGENTS.md similarity index 100% rename from agent-templates/AGENTS.md rename to config/agent-templates/AGENTS.md diff --git a/agent-templates/HEARTBEAT.md b/config/agent-templates/HEARTBEAT.md similarity index 100% rename from agent-templates/HEARTBEAT.md rename to config/agent-templates/HEARTBEAT.md diff --git a/agent-templates/IDENTITY.md b/config/agent-templates/IDENTITY.md similarity index 100% rename from agent-templates/IDENTITY.md rename to config/agent-templates/IDENTITY.md diff --git a/agent-templates/README.md b/config/agent-templates/README.md similarity index 73% rename from agent-templates/README.md rename to config/agent-templates/README.md index 6390582..c7555a0 100644 --- a/agent-templates/README.md +++ b/config/agent-templates/README.md @@ -27,18 +27,25 @@ ## 使用方式 -部署流程已将 `agent-templates/` 目录复制到 workspace,安装过程中自动执行 `sed` 替换所有占位符。 +本仓库的 README 第 6.2 步会自动将本目录文件复制到 agent workspace 并替换占位符。 如需手动应用: ```bash -# 复制到 agent workspace -cp -r agent-templates/* /home/program/qq-workspace/ +# 确定仓库克隆路径 +REPO_DIR="/opt/chatrebot_aireply_plug" +AGENT_WORKSPACE="/home/program/qq-workspace" +ADMIN_QQ="你的QQ号" +ADMIN_NAME="你的昵称" + +# 复制模板文件 +cp "${REPO_DIR}/config/agent-templates/"*.md "${AGENT_WORKSPACE}/" # 替换占位符 -sed -i 's/ADMIN_QQ/2198972886/g' /home/program/qq-workspace/*.md -sed -i 's/ADMIN_NAME/—\//g' /home/program/qq-workspace/*.md -sed -i 's|AGENT_WORKSPACE|/home/program/qq-workspace|g' /home/program/qq-workspace/*.md +cd "${AGENT_WORKSPACE}" +sed -i "s/ADMIN_QQ/${ADMIN_QQ}/g" *.md +sed -i "s|ADMIN_NAME|${ADMIN_NAME}|g" *.md +sed -i "s|AGENT_WORKSPACE|${AGENT_WORKSPACE}|g" *.md ``` ## 安全说明(重要) diff --git a/agent-templates/SOUL.md b/config/agent-templates/SOUL.md similarity index 100% rename from agent-templates/SOUL.md rename to config/agent-templates/SOUL.md diff --git a/agent-templates/TOOLS.md b/config/agent-templates/TOOLS.md similarity index 100% rename from agent-templates/TOOLS.md rename to config/agent-templates/TOOLS.md diff --git a/agent-templates/USER.md b/config/agent-templates/USER.md similarity index 100% rename from agent-templates/USER.md rename to config/agent-templates/USER.md