From 6adeb9b371ff06bbd645575274cc1522cf390c19 Mon Sep 17 00:00:00 2001
From: hubian <908234780@qq.com>
Date: Sun, 12 Apr 2026 17:06:39 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=87=E6=8D=A2=E5=AF=B9=E8=AF=9D?=
=?UTF-8?q?=E6=97=B6=E6=81=A2=E5=A4=8D=E5=AF=B9=E5=BA=94=E7=9A=84Agent?=
=?UTF-8?q?=E6=98=BE=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
main_v2.py | 6 ++++++
templates/index.html | 26 ++++++++++++++++++++++----
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/main_v2.py b/main_v2.py
index 4986ee9..8242760 100644
--- a/main_v2.py
+++ b/main_v2.py
@@ -546,14 +546,20 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str):
if conversation:
messages = conv_service.get_messages(conversation.id)
+
+ # 获取对话使用的Agent ID
+ conv_agent_id = conversation.current_agent_id
+
await websocket.send_json({
"type": "history",
"conversation_id": current_conversation_id,
+ "agent_id": conv_agent_id, # 返回对话的Agent ID
"messages": [
{
"role": m.role,
"content": m.content,
"thinking_content": m.thinking_content,
+ "agent_id": m.agent_id, # 每条消息的Agent ID
"source": m.source,
"created_at": m.created_at.isoformat()
}
diff --git a/templates/index.html b/templates/index.html
index 56259fc..484cf39 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -192,10 +192,7 @@
const data = await res.json();
agents = data.agents || [];
- const select = document.getElementById('agentSelect');
- select.innerHTML = agents.filter(a => a.is_active).map(a =>
- ``
- ).join('');
+ renderAgentSelect();
// 设置当前Agent
const defaultAgent = agents.find(a => a.is_default) || agents[0];
@@ -206,6 +203,22 @@
}
}
+ // 渲染Agent下拉框
+ function renderAgentSelect(selectedId = null) {
+ const select = document.getElementById('agentSelect');
+ const selected = selectedId || currentAgentId;
+ select.innerHTML = agents.filter(a => a.is_active).map(a =>
+ ``
+ ).join('');
+ }
+
+ // 更新Agent选择框显示
+ function updateAgentSelect(agentId) {
+ const select = document.getElementById('agentSelect');
+ select.value = agentId;
+ currentAgentId = agentId;
+ }
+
// 切换Agent - 自动创建新对话
async function switchAgent() {
const newAgentId = document.getElementById('agentSelect').value;
@@ -336,6 +349,11 @@
switch (data.type) {
case 'history':
displayHistory(data.messages);
+ // 更新Agent选择框为该对话使用的Agent
+ if (data.agent_id) {
+ currentAgentId = data.agent_id;
+ updateAgentSelect(data.agent_id);
+ }
break;
case 'conversation_created':
currentConversationId = data.conversation_id;