feat: 更新依赖项,添加新的配置字段,优化智能体管理和视图组件

This commit is contained in:
Wenjie Zhang 2025-07-22 04:12:55 +08:00
parent 24e3937aa2
commit 44b6dfdbc0
6 changed files with 101 additions and 35 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
### python gitignore ### python gitignore
__pycache__/ __pycache__/
*.pyc *.pyc
.venv
.ruff_cache
### Vue gitignore ### Vue gitignore
dist dist

View File

@ -5,6 +5,7 @@ description = "Add your description here"
readme = "README.md" readme = "README.md"
requires-python = ">=3.11" requires-python = ">=3.11"
dependencies = [ dependencies = [
"arxiv>=2.2.0",
"asyncpg>=0.30.0", "asyncpg>=0.30.0",
"chromadb>=1.0.15", "chromadb>=1.0.15",
"colorlog>=6.9.0", "colorlog>=6.9.0",
@ -14,6 +15,7 @@ dependencies = [
"langchain-community>=0.3.22", "langchain-community>=0.3.22",
"langchain-deepseek>=0.1.3", "langchain-deepseek>=0.1.3",
"langchain-huggingface>=0.2.0", "langchain-huggingface>=0.2.0",
"langchain-mcp-adapters>=0.1.9",
"langchain-openai>=0.3.14", "langchain-openai>=0.3.14",
"langchain-tavily>=0.2.3", "langchain-tavily>=0.2.3",
"langchain-together>=0.3.0", "langchain-together>=0.3.0",
@ -24,6 +26,7 @@ dependencies = [
"lightrag-hku>=1.3.9", "lightrag-hku>=1.3.9",
"llama-index>=0.12.33", "llama-index>=0.12.33",
"llama-index-readers-file>=0.4.7", "llama-index-readers-file>=0.4.7",
"mcp>=1.12.0",
"mineru>=2.0.6", "mineru>=2.0.6",
"neo4j>=5.28.1", "neo4j>=5.28.1",
"networkx>=3.5", "networkx>=3.5",

View File

@ -1,6 +1,7 @@
import asyncio import asyncio
from src.agents.chatbot import ChatbotAgent
from src.agents.react import ReActAgent from .chatbot import ChatbotAgent
from .react import ReActAgent
class AgentManager: class AgentManager:
def __init__(self): def __init__(self):
@ -32,7 +33,7 @@ class AgentManager:
agent_manager = AgentManager() agent_manager = AgentManager()
agent_manager.register_agent(ChatbotAgent) agent_manager.register_agent(ChatbotAgent)
agent_manager.register_agent(ReActAgent) # 暂时屏蔽 ReActAgent agent_manager.register_agent(ReActAgent)
agent_manager.init_all_agents() agent_manager.init_all_agents()
__all__ = ["agent_manager"] __all__ = ["agent_manager"]

View File

@ -13,13 +13,13 @@ class ChatbotConfiguration(Configuration):
metadata configurable True 的配置项可以被用户配置 metadata configurable True 的配置项可以被用户配置
configurable False 的配置项不能被用户配置只能由开发者预设 configurable False 的配置项不能被用户配置只能由开发者预设
除非显示配置为 False否则所有配置项都默认可配置
""" """
system_prompt: str = field( system_prompt: str = field(
default="You are a helpful assistant.", default="You are a helpful assistant.",
metadata={ metadata={
"name": "系统提示词", "name": "系统提示词",
"configurable": True,
"description": "用来描述智能体的角色和行为" "description": "用来描述智能体的角色和行为"
}, },
) )
@ -28,7 +28,6 @@ class ChatbotConfiguration(Configuration):
default="zhipu/glm-4-plus", default="zhipu/glm-4-plus",
metadata={ metadata={
"name": "智能体模型", "name": "智能体模型",
"configurable": True,
"options": [], "options": [],
"description": "智能体的驱动模型" "description": "智能体的驱动模型"
}, },
@ -38,7 +37,6 @@ class ChatbotConfiguration(Configuration):
default_factory=list, default_factory=list,
metadata={ metadata={
"name": "工具", "name": "工具",
"configurable": True,
"options": list(get_all_tools().keys()), # 这里的选择是所有的工具 "options": list(get_all_tools().keys()), # 这里的选择是所有的工具
"description": "工具列表" "description": "工具列表"
}, },

View File

@ -4,7 +4,7 @@ import os
import yaml import yaml
import uuid import uuid
from pathlib import Path from pathlib import Path
from typing import Annotated, TypedDict from typing import Annotated, TypedDict, Optional, Any
from abc import abstractmethod from abc import abstractmethod
from dataclasses import dataclass, fields, field from dataclasses import dataclass, fields, field
@ -30,6 +30,24 @@ class Configuration(dict):
3. 类默认配置最低优先级类中定义的默认值 3. 类默认配置最低优先级类中定义的默认值
""" """
thread_id: str = field(
default_factory=lambda: str(uuid.uuid4()),
metadata={
"name": "线程ID",
"configurable": False,
"description": "用来描述智能体的角色和行为"
},
)
user_id: str = field(
default_factory=lambda: str(uuid.uuid4()),
metadata={
"name": "用户ID",
"configurable": False,
"description": "用来描述智能体的角色和行为"
},
)
@classmethod @classmethod
def from_runnable_config( def from_runnable_config(
cls, config: RunnableConfig | None = None, agent_name: str | None = None cls, config: RunnableConfig | None = None, agent_name: str | None = None
@ -127,7 +145,7 @@ class Configuration(dict):
else: else:
confs[f.name] = value confs[f.name] = value
if f.metadata.get("configurable"): if f.metadata.get("configurable", True):
configurable_items[f.name] = { configurable_items[f.name] = {
"type": f.type.__name__, "type": f.type.__name__,
"name": f.metadata.get("name", f.name), "name": f.metadata.get("name", f.name),
@ -139,23 +157,6 @@ class Configuration(dict):
return confs return confs
thread_id: str = field(
default_factory=lambda: str(uuid.uuid4()),
metadata={
"name": "线程ID",
"configurable": False,
"description": "用来描述智能体的角色和行为"
},
)
user_id: str = field(
default_factory=lambda: str(uuid.uuid4()),
metadata={
"name": "用户ID",
"configurable": False,
"description": "用来描述智能体的角色和行为"
},
)
class BaseAgent: class BaseAgent:

View File

@ -11,7 +11,7 @@
<a-select <a-select
v-model:value="selectedAgentId" v-model:value="selectedAgentId"
class="agent-list" class="agent-list"
style="width: 200px" style="width: 300px"
@change="selectAgent" @change="selectAgent"
> >
<a-select-option <a-select-option
@ -20,8 +20,11 @@
:value="name" :value="name"
> >
<div class="agent-option"> <div class="agent-option">
智能体{{ agent.name }} <div class="agent-option-content">
<StarFilled v-if="name === defaultAgentId" class="default-icon" /> <p class="agent-option-name">{{ agent.name }} <StarFilled v-if="name === defaultAgentId" class="default-icon" /></p>
<p class="agent-option-description">{{ agent.description }}</p>
</div>
</div> </div>
</a-select-option> </a-select-option>
</a-select> </a-select>
@ -59,7 +62,7 @@
<a-modal <a-modal
v-model:open="state.agentConfOpen" v-model:open="state.agentConfOpen"
title="智能体详细配置" title="智能体详细配置"
:width="600" :width="800"
:footer="null" :footer="null"
:maskClosable="false" :maskClosable="false"
class="conf-modal" class="conf-modal"
@ -117,13 +120,16 @@
v-else-if="typeof agentConfig[key] === 'boolean'" v-else-if="typeof agentConfig[key] === 'boolean'"
v-model:checked="agentConfig[key]" v-model:checked="agentConfig[key]"
/> />
<!-- 单选 -->
<a-select <a-select
v-else-if="value?.options && value?.type === 'str'" v-else-if="value?.options && (value?.type === 'str' || value?.type === 'select')"
v-model:value="agentConfig[key]" v-model:value="agentConfig[key]"
> >
<a-select-option v-for="option in value.options" :key="option" :value="option"></a-select-option> <a-select-option v-for="option in value.options" :key="option" :value="option">
{{ option.label || option }}
</a-select-option>
</a-select> </a-select>
<!-- 多选标签卡片 --> <!-- 多选 -->
<div v-else-if="value?.options && value?.type === 'list'" class="multi-select-cards"> <div v-else-if="value?.options && value?.type === 'list'" class="multi-select-cards">
<div class="multi-select-label"> <div class="multi-select-label">
<span>已选择 {{ getSelectedCount(key) }} </span> <span>已选择 {{ getSelectedCount(key) }} </span>
@ -152,6 +158,22 @@
</div> </div>
</div> </div>
</div> </div>
<!-- 数字 -->
<a-input-number
v-else-if="value?.type === 'number'"
v-model:value="agentConfig[key]"
:placeholder="getPlaceholder(key, value)"
/>
<!-- 滑块 -->
<a-slider
v-else-if="value?.type === 'slider'"
v-model:value="agentConfig[key]"
:min="value.min"
:max="value.max"
:step="value.step"
style="max-width: 300px;"
/>
<!-- 其他类型 -->
<a-input <a-input
v-else v-else
v-model:value="agentConfig[key]" v-model:value="agentConfig[key]"
@ -228,7 +250,18 @@ const state = reactive({
const selectedAgent = computed(() => agents.value[selectedAgentId.value] || {}); const selectedAgent = computed(() => agents.value[selectedAgentId.value] || {});
const configSchema = computed(() => selectedAgent.value.config_schema || {}); const configSchema = computed(() => selectedAgent.value.config_schema || {});
const configurableItems = computed(() => configSchema.value.configurable_items || {}); const configurableItems = computed(() => {
const items = configSchema.value.configurable_items || {};
// x_oap_ui_config
Object.keys(items).forEach(key => {
const item = items[key];
if (item.x_oap_ui_config) {
items[key] = { ...item, ...item.x_oap_ui_config };
delete items[key].x_oap_ui_config;
}
});
return items;
});
// //
const agentConfig = ref({}); const agentConfig = ref({});
@ -467,7 +500,7 @@ onMounted(async () => {
// //
const getConfigLabel = (key, value) => { const getConfigLabel = (key, value) => {
// //
if (value.description) { if (value.description && value.name !== key) {
return `${value.name}${key}`; return `${value.name}${key}`;
} }
return key; return key;
@ -655,11 +688,28 @@ const toggleConf = () => {
.agent-option { .agent-option {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: flex-start;
.agent-option-content {
display: flex;
flex-direction: column;
gap: 2px;
p {
margin: 0;
}
.agent-option-description {
font-size: 12px;
color: var(--gray-700);
word-break: break-word;
white-space: pre-wrap;
}
}
.default-icon { .default-icon {
color: #faad14; color: #faad14;
font-size: 14px; font-size: 14px;
margin-left: 4px;
} }
} }
@ -752,6 +802,7 @@ const toggleConf = () => {
max-height: 60vh; max-height: 60vh;
} }
} }
</style> </style>
@ -787,4 +838,14 @@ const toggleConf = () => {
} }
} }
} }
// Ant Design Select
:deep(.ant-select-item-option-content) {
.agent-option-name {
color: var(--main-color);
font-size: 14px;
font-weight: 500;
}
}
</style> </style>