feat: 自进化经验记忆——任务成功后用模型把工具序列提炼成「操作配方」存入 agent_experience 表;下次相似任务(bigram 相似度检索 top2)自动注入 system prompt 参考,AI 越用越聪明(同类操作不再摸索)
This commit is contained in:
+4
-1
@@ -135,7 +135,7 @@ class Agent:
|
||||
# ---------- 主循环(流式) ----------
|
||||
async def run_stream(self, prompt: str, serial: str = "",
|
||||
history=None, on_delta=None, on_tool=None,
|
||||
should_stop=None):
|
||||
should_stop=None, extra_context=None):
|
||||
"""流式执行一轮指令,返回最终完整文本。
|
||||
|
||||
history:上一轮的 [{"role": "user"|"assistant", "content": 文本}] 列表,
|
||||
@@ -143,6 +143,7 @@ class Agent:
|
||||
on_delta(text, kind):content/reasoning 文本增量(实时推给前端)
|
||||
on_tool(step):工具调用完成(实时显示 MCP 步骤)
|
||||
should_stop:可调用 fn() -> bool,每轮模型调用前检查(用户中断用)
|
||||
extra_context:附加文本(经验记忆注入,放在 system prompt 末尾)
|
||||
"""
|
||||
self.on_delta = on_delta
|
||||
self.on_tool = on_tool
|
||||
@@ -150,6 +151,8 @@ class Agent:
|
||||
sys_txt = SYSTEM_PROMPT
|
||||
if target:
|
||||
sys_txt += f"\n\n本次默认目标设备 serial:{target}(未指定设备时用它)。"
|
||||
if extra_context:
|
||||
sys_txt += f"\n\n## 过往成功经验参考(同类任务,可参考其中的操作套路,但要根据当前界面灵活调整)\n{extra_context}"
|
||||
self.messages = [{"role": "system", "content": sys_txt}]
|
||||
for h in (history or []):
|
||||
if h.get("role") in ("user", "assistant") and h.get("content"):
|
||||
|
||||
Reference in New Issue
Block a user