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:
@@ -44,6 +44,7 @@ class AgentMemory:
|
||||
team_share_enabled: bool = False,
|
||||
memory_dir_enabled: bool = False,
|
||||
memory_dir_path: str = "",
|
||||
parent_agent_id: Optional[str] = None,
|
||||
):
|
||||
self.scope_kind = scope_kind
|
||||
self.scope_id = scope_id or "default"
|
||||
@@ -54,6 +55,7 @@ class AgentMemory:
|
||||
self.vector_memory_top_k = vector_memory_top_k
|
||||
self.vector_memory_rerank = vector_memory_rerank
|
||||
self.memory_type_filter = memory_type_filter # None = 全部类型
|
||||
self.parent_agent_id = parent_agent_id # 父 Agent ID(继承经验)
|
||||
self.team_id = team_id # 团队共享 ID
|
||||
self.team_share_enabled = team_share_enabled # 是否自动发布到团队池
|
||||
# 文件式记忆
|
||||
@@ -138,6 +140,12 @@ class AgentMemory:
|
||||
if global_text:
|
||||
parts.append(global_text)
|
||||
|
||||
# 5. 父 Agent 知识继承:加载父级经验
|
||||
if self.parent_agent_id and self.scope_id:
|
||||
parent_text = await self._parent_knowledge_search(query)
|
||||
if parent_text:
|
||||
parts.append(parent_text)
|
||||
|
||||
return "\n\n".join(parts) if parts else ""
|
||||
|
||||
async def _vector_search(self, query: str = "") -> str:
|
||||
@@ -341,6 +349,65 @@ class AgentMemory:
|
||||
logger.warning("LLM Rerank 失败,使用向量排序: %s", e)
|
||||
return candidates[: self.vector_memory_top_k]
|
||||
|
||||
async def _parent_knowledge_search(self, query: str = "") -> str:
|
||||
"""从父 Agent 的知识库中检索相关经验。"""
|
||||
from app.models.knowledge_entry import KnowledgeEntry
|
||||
from app.models.agent import Agent
|
||||
|
||||
db: Optional[Session] = None
|
||||
try:
|
||||
db = SessionLocal()
|
||||
|
||||
# 向上追溯祖先 Agent(最多 3 层)
|
||||
ancestor_ids: List[str] = []
|
||||
current_id = self.parent_agent_id
|
||||
for _ in range(3):
|
||||
if not current_id:
|
||||
break
|
||||
agent = db.query(Agent).filter(Agent.id == current_id).first()
|
||||
if not agent:
|
||||
break
|
||||
ancestor_ids.append(current_id)
|
||||
current_id = getattr(agent, "parent_agent_id", None)
|
||||
if current_id in ancestor_ids:
|
||||
break
|
||||
|
||||
if not ancestor_ids:
|
||||
return ""
|
||||
|
||||
# 查询祖先的知识条目
|
||||
entries = (
|
||||
db.query(KnowledgeEntry)
|
||||
.filter(
|
||||
KnowledgeEntry.agent_id.in_(ancestor_ids),
|
||||
KnowledgeEntry.is_active == True,
|
||||
KnowledgeEntry.confidence >= 0.5,
|
||||
)
|
||||
.order_by(KnowledgeEntry.retrieval_count.desc())
|
||||
.limit(8)
|
||||
.all()
|
||||
)
|
||||
|
||||
if not entries:
|
||||
return ""
|
||||
|
||||
lines = [f"## 父级 Agent 经验(来自 {len(ancestor_ids)} 个祖先 Agent)"]
|
||||
for i, entry in enumerate(entries, 1):
|
||||
cat = entry.category or "经验"
|
||||
title = entry.title or ""
|
||||
sol = (entry.solution or entry.situation or "")[:300]
|
||||
caveat = f" 注意: {entry.caveats[:100]}" if entry.caveats else ""
|
||||
lines.append(f"{i}. [{cat}] {title}: {sol}{caveat}")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
except Exception as e:
|
||||
logger.warning("父级知识检索失败: %s", e)
|
||||
return ""
|
||||
finally:
|
||||
if db:
|
||||
db.close()
|
||||
|
||||
async def _global_knowledge_search(self, query: str = "") -> str:
|
||||
"""从 GlobalKnowledge 表检索相关的全局知识条目。"""
|
||||
from datetime import datetime
|
||||
|
||||
Reference in New Issue
Block a user