fix(multi-agent): web模式支持加载预设角色,多智能体面板显示活跃子智能体
This commit is contained in:
parent
69e3ef51b6
commit
4f3ba722a1
@ -31,6 +31,7 @@ try:
|
|||||||
WORKSPACE_MEMORY_DIRNAME,
|
WORKSPACE_MEMORY_DIRNAME,
|
||||||
WORKSPACE_REVIEW_DIRNAME,
|
WORKSPACE_REVIEW_DIRNAME,
|
||||||
)
|
)
|
||||||
|
from config.paths import WEB_PRESET_ROLES_DIR
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import sys
|
import sys
|
||||||
project_root = Path(__file__).resolve().parents[2]
|
project_root = Path(__file__).resolve().parents[2]
|
||||||
@ -57,6 +58,7 @@ except ImportError:
|
|||||||
WORKSPACE_MEMORY_DIRNAME,
|
WORKSPACE_MEMORY_DIRNAME,
|
||||||
WORKSPACE_REVIEW_DIRNAME,
|
WORKSPACE_REVIEW_DIRNAME,
|
||||||
)
|
)
|
||||||
|
from config.paths import WEB_PRESET_ROLES_DIR
|
||||||
|
|
||||||
from modules.file_manager import FileManager
|
from modules.file_manager import FileManager
|
||||||
from modules.search_engine import SearchEngine
|
from modules.search_engine import SearchEngine
|
||||||
@ -1748,9 +1750,9 @@ class MainTerminalToolsExecutionMixin:
|
|||||||
from modules.multi_agent.prompts import build_multi_agent_sub_agent_prompt
|
from modules.multi_agent.prompts import build_multi_agent_sub_agent_prompt
|
||||||
_data_dir = str(getattr(self, "data_dir", ""))
|
_data_dir = str(getattr(self, "data_dir", ""))
|
||||||
_custom_dir = infer_custom_roles_dir(_data_dir)
|
_custom_dir = infer_custom_roles_dir(_data_dir)
|
||||||
# host模式下 custom_dir 就是 runtime_dir;web模式下 custom_dir 是用户个人目录
|
# host模式下 custom_dir 就是 runtime_dir;web模式下 runtime_dir 指向 web 预设目录
|
||||||
_is_web = '/web/users/' in _data_dir
|
_is_web = '/web/users/' in _data_dir
|
||||||
_runtime_dir = None if _is_web else _custom_dir
|
_runtime_dir = WEB_PRESET_ROLES_DIR if _is_web else _custom_dir
|
||||||
role = load_preset_role(role_id, runtime_dir=_runtime_dir, custom_dir=_custom_dir)
|
role = load_preset_role(role_id, runtime_dir=_runtime_dir, custom_dir=_custom_dir)
|
||||||
if not role:
|
if not role:
|
||||||
result = {"success": False, "error": f"角色不存在: {role_id}"}
|
result = {"success": False, "error": f"角色不存在: {role_id}"}
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
@ -398,11 +399,28 @@ def list_active_sub_agents_api():
|
|||||||
if not sub_agent_manager:
|
if not sub_agent_manager:
|
||||||
return jsonify({"success": False, "error": "子智能体管理器未就绪"}), 503
|
return jsonify({"success": False, "error": "子智能体管理器未就绪"}), 503
|
||||||
state = sub_agent_manager.get_multi_agent_state(conversation_id)
|
state = sub_agent_manager.get_multi_agent_state(conversation_id)
|
||||||
|
agents: List[Dict[str, Any]] = []
|
||||||
|
if state:
|
||||||
|
for a in state.list_all():
|
||||||
|
d = a.to_dict()
|
||||||
|
task = sub_agent_manager.tasks.get(a.task_id)
|
||||||
|
if isinstance(task, dict):
|
||||||
|
d["last_tool"] = task.get("last_tool")
|
||||||
|
stats_file = Path(task.get("stats_file", ""))
|
||||||
|
if stats_file.exists():
|
||||||
|
try:
|
||||||
|
stats = json.loads(stats_file.read_text(encoding="utf-8"))
|
||||||
|
d["current_context_tokens"] = stats.get("current_context_tokens", 0)
|
||||||
|
except Exception:
|
||||||
|
d["current_context_tokens"] = 0
|
||||||
|
else:
|
||||||
|
d["current_context_tokens"] = 0
|
||||||
|
agents.append(d)
|
||||||
if not state:
|
if not state:
|
||||||
return jsonify({"success": True, "agents": []})
|
return jsonify({"success": True, "agents": []})
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"success": True,
|
"success": True,
|
||||||
"agents": [a.to_dict() for a in state.list_all()],
|
"agents": agents,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { useUiStore } from './ui';
|
import { useUiStore } from './ui';
|
||||||
|
import { useConversationStore } from './conversation';
|
||||||
|
|
||||||
interface SubAgent {
|
interface SubAgent {
|
||||||
task_id: string;
|
task_id: string;
|
||||||
@ -49,13 +50,22 @@ export const useSubAgentStore = defineStore('subAgent', {
|
|||||||
actions: {
|
actions: {
|
||||||
async fetchSubAgents() {
|
async fetchSubAgents() {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch('/api/sub_agents');
|
const conversationStore = useConversationStore();
|
||||||
|
let resp;
|
||||||
|
if (conversationStore.multiAgentMode && conversationStore.currentConversationId) {
|
||||||
|
resp = await fetch(`/api/multiagent/active_sub_agents?conversation_id=${encodeURIComponent(conversationStore.currentConversationId)}`);
|
||||||
|
} else {
|
||||||
|
resp = await fetch('/api/sub_agents');
|
||||||
|
}
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
throw new Error(await resp.text());
|
throw new Error(await resp.text());
|
||||||
}
|
}
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
this.subAgents = Array.isArray(data.data) ? data.data : [];
|
const agents = conversationStore.multiAgentMode
|
||||||
|
? (Array.isArray(data.agents) ? data.agents : [])
|
||||||
|
: (Array.isArray(data.data) ? data.data : []);
|
||||||
|
this.subAgents = agents;
|
||||||
const activeTaskId = this.activeAgent?.task_id;
|
const activeTaskId = this.activeAgent?.task_id;
|
||||||
if (activeTaskId) {
|
if (activeTaskId) {
|
||||||
const latest = this.subAgents.find((item) => item.task_id === activeTaskId);
|
const latest = this.subAgents.find((item) => item.task_id === activeTaskId);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user