feat(v3): T27 会话式智能体(多轮上下文/停止/对话式 UI,对齐 dsh 范式)

- ToolLoop 增 history 参数(既往轮次折叠为对话上下文,近 6 轮)
- 会话制:AgentSession/SessionStore 持久化 agent_runs/sessions/{sid}.json,
  /agent/sessions CRUD + /agent 带 session_id(继承会话工作区与执行者配置,busy 并发控制)
- POST /agent/{id}/cancel:取消运行中任务
- AgentView 重构为对话式:会话列表 + 居中消息流(用户蓝气泡/助手白卡)+ 底部 composer
  (工作区/执行者/命令 chips,Enter 发送,运行中红色停止钮),工具过程折叠收纳
- 工具步数统计统一至事件写入层并透出 status.tool_calls
- fix(tests): 会话存储测试隔离,防测试数据泄漏进真实 sessions 目录
- 测试 +4,全量 281 passed
This commit is contained in:
tzt
2026-09-01 22:30:26 +08:00
parent 943eecc5ef
commit 7d11ae2644
20 changed files with 973 additions and 473 deletions
+8 -2
View File
@@ -435,11 +435,17 @@ class ToolLoop:
def _total_tokens(self, usage: Dict[str, int]) -> int:
return int(usage.get("prompt_tokens", 0)) + int(usage.get("completion_tokens", 0))
async def run(self, task: str, system: str = "") -> Dict[str, Any]:
"""执行任务直到模型给出最终答复或触顶。返回最终结果与账目。"""
async def run(self, task: str, system: str = "",
history: Optional[List[Dict[str, Any]]] = None) -> Dict[str, Any]:
"""执行任务直到模型给出最终答复或触顶。
history 为既往对话消息(user/assistant,不含工具细节),用于会话式多轮上下文。
"""
messages: List[Dict[str, Any]] = []
if system:
messages.append({"role": "system", "content": system})
if history:
messages.extend(history)
messages.append({"role": "user", "content": task})
total_in = 0