feat: AI 控制台会话化 + 视觉优化——①多轮对话连续性(后端 history 持久化 12 轮,Agent 注入历史上下文,DeepSeek 式会话:新建会话才清空);②聊天区改浅色(DeepSeek 风格,图片文字清晰);③截图点击放大查看
This commit is contained in:
+8
-3
@@ -132,9 +132,11 @@ class Agent:
|
||||
|
||||
# ---------- 主循环(流式) ----------
|
||||
async def run_stream(self, prompt: str, serial: str = "",
|
||||
on_delta=None, on_tool=None):
|
||||
history=None, on_delta=None, on_tool=None):
|
||||
"""流式执行一轮指令,返回最终完整文本。
|
||||
|
||||
history:上一轮的 [{"role": "user"|"assistant", "content": 文本}] 列表,
|
||||
用于多轮对话保持上下文(截图/工具消息不入历史,控制 token)。
|
||||
on_delta(text, kind):content/reasoning 文本增量(实时推给前端)
|
||||
on_tool(step):工具调用完成(实时显示 MCP 步骤)
|
||||
"""
|
||||
@@ -144,8 +146,11 @@ class Agent:
|
||||
sys_txt = SYSTEM_PROMPT
|
||||
if target:
|
||||
sys_txt += f"\n\n本次默认目标设备 serial:{target}(未指定设备时用它)。"
|
||||
self.messages = [{"role": "system", "content": sys_txt},
|
||||
{"role": "user", "content": prompt}]
|
||||
self.messages = [{"role": "system", "content": sys_txt}]
|
||||
for h in (history or []):
|
||||
if h.get("role") in ("user", "assistant") and h.get("content"):
|
||||
self.messages.append({"role": h["role"], "content": h["content"]})
|
||||
self.messages.append({"role": "user", "content": prompt})
|
||||
|
||||
for _step in range(self.s.max_steps):
|
||||
content_parts = []
|
||||
|
||||
Reference in New Issue
Block a user