fix: delete agent 500 error + dynamic personality + deployment guide
- Fix delete agent 500: clean up FK records (agent_llm_logs, permissions, schedules, executions, team_members) and unbind goals/tasks before delete - Remove hardcoded personality templates in Android, replace with dynamic system prompt generation from name + description - Set promptSectionsEnabled=false to bypass PromptComposer for personality - Add Tencent Cloud Linux deployment guide (Docker Compose) - Accumulated backend service updates, frontend UI fixes, Android app changes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
90
backend/scripts/fix_agent_permission.py
Normal file
90
backend/scripts/fix_agent_permission.py
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
修复 Agent 权限级别: 将目标 Agent 的 permission_level 改为 acceptEdits
|
||||
避免每次文件写入都需要弹窗确认
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from app.core.database import SessionLocal
|
||||
from app.models.agent import Agent
|
||||
import json
|
||||
|
||||
|
||||
def fix_agent_permission(agent_name: str = None):
|
||||
"""将指定 Agent 的 permission_level 设为 acceptEdits"""
|
||||
db = SessionLocal()
|
||||
|
||||
try:
|
||||
agents = db.query(Agent).all()
|
||||
|
||||
if not agents:
|
||||
print("[ERROR] No agents found")
|
||||
return
|
||||
|
||||
print(f"[INFO] Found {len(agents)} agents:\n")
|
||||
for a in agents:
|
||||
wc = a.workflow_config or {}
|
||||
nodes = wc.get("nodes", [])
|
||||
perm = "default"
|
||||
for n in nodes:
|
||||
if n.get("type") in ("agent", "llm", "template"):
|
||||
perm = n.get("data", {}).get("permission_level", "default")
|
||||
break
|
||||
print(f" [{a.status}] {a.name} (id={a.id}) -- permission_level={perm}")
|
||||
|
||||
if agent_name:
|
||||
target = db.query(Agent).filter(Agent.name == agent_name).first()
|
||||
if not target:
|
||||
target = db.query(Agent).filter(Agent.name.like(f"%{agent_name}%")).first()
|
||||
if not target:
|
||||
print(f"\n[ERROR] No agent matching '{agent_name}' found")
|
||||
return
|
||||
agents_to_fix = [target]
|
||||
else:
|
||||
agents_to_fix = agents
|
||||
|
||||
print(f"\n[INFO] Fixing permission_level...")
|
||||
fixed = 0
|
||||
for agent in agents_to_fix:
|
||||
wc = agent.workflow_config or {}
|
||||
nodes = wc.get("nodes", [])
|
||||
|
||||
updated = False
|
||||
for node in nodes:
|
||||
if node.get("type") in ("agent", "llm", "template"):
|
||||
data = node.get("data") or {}
|
||||
old_perm = data.get("permission_level", "default")
|
||||
if old_perm != "acceptEdits":
|
||||
data["permission_level"] = "acceptEdits"
|
||||
node["data"] = data
|
||||
updated = True
|
||||
print(f" [FIXED] [{agent.name}] permission_level: {old_perm} -> acceptEdits")
|
||||
|
||||
if updated:
|
||||
agent.workflow_config = wc
|
||||
fixed += 1
|
||||
|
||||
if fixed > 0:
|
||||
db.commit()
|
||||
print(f"\n[DONE] Fixed {fixed} agent(s), permission_level set to acceptEdits")
|
||||
print(f" File write/edit operations will no longer require confirmation")
|
||||
else:
|
||||
print(f"\n[INFO] No agents need fixing (already acceptEdits)")
|
||||
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
print(f"[ERROR] Fix failed: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description="Fix Agent permission level")
|
||||
parser.add_argument("-n", "--name", type=str, help="Agent name (fuzzy match)")
|
||||
args = parser.parse_args()
|
||||
fix_agent_permission(agent_name=args.name)
|
||||
Reference in New Issue
Block a user