diff --git a/.gitignore b/.gitignore index 6aeb1ca2..0dc04b45 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ ### python gitignore __pycache__/ *.pyc +.venv +.ruff_cache ### Vue gitignore dist diff --git a/pyproject.toml b/pyproject.toml index 54d57ed4..ba115c79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ description = "Add your description here" readme = "README.md" requires-python = ">=3.11" dependencies = [ + "arxiv>=2.2.0", "asyncpg>=0.30.0", "chromadb>=1.0.15", "colorlog>=6.9.0", @@ -14,6 +15,7 @@ dependencies = [ "langchain-community>=0.3.22", "langchain-deepseek>=0.1.3", "langchain-huggingface>=0.2.0", + "langchain-mcp-adapters>=0.1.9", "langchain-openai>=0.3.14", "langchain-tavily>=0.2.3", "langchain-together>=0.3.0", @@ -24,6 +26,7 @@ dependencies = [ "lightrag-hku>=1.3.9", "llama-index>=0.12.33", "llama-index-readers-file>=0.4.7", + "mcp>=1.12.0", "mineru>=2.0.6", "neo4j>=5.28.1", "networkx>=3.5", diff --git a/src/agents/__init__.py b/src/agents/__init__.py index bf565b90..6051dff2 100644 --- a/src/agents/__init__.py +++ b/src/agents/__init__.py @@ -1,6 +1,7 @@ import asyncio -from src.agents.chatbot import ChatbotAgent -from src.agents.react import ReActAgent + +from .chatbot import ChatbotAgent +from .react import ReActAgent class AgentManager: def __init__(self): @@ -32,7 +33,7 @@ class AgentManager: agent_manager = AgentManager() agent_manager.register_agent(ChatbotAgent) -agent_manager.register_agent(ReActAgent) # 暂时屏蔽 ReActAgent +agent_manager.register_agent(ReActAgent) agent_manager.init_all_agents() __all__ = ["agent_manager"] diff --git a/src/agents/chatbot/configuration.py b/src/agents/chatbot/configuration.py index 2180311e..2b4259f1 100644 --- a/src/agents/chatbot/configuration.py +++ b/src/agents/chatbot/configuration.py @@ -13,13 +13,13 @@ class ChatbotConfiguration(Configuration): metadata 中 configurable 为 True 的配置项可以被用户配置, configurable 为 False 的配置项不能被用户配置,只能由开发者预设。 + 除非显示配置为 False,否则所有配置项都默认可配置。 """ system_prompt: str = field( default="You are a helpful assistant.", metadata={ "name": "系统提示词", - "configurable": True, "description": "用来描述智能体的角色和行为" }, ) @@ -28,7 +28,6 @@ class ChatbotConfiguration(Configuration): default="zhipu/glm-4-plus", metadata={ "name": "智能体模型", - "configurable": True, "options": [], "description": "智能体的驱动模型" }, @@ -38,7 +37,6 @@ class ChatbotConfiguration(Configuration): default_factory=list, metadata={ "name": "工具", - "configurable": True, "options": list(get_all_tools().keys()), # 这里的选择是所有的工具 "description": "工具列表" }, diff --git a/src/agents/registry.py b/src/agents/registry.py index 5ef21964..2b401eca 100644 --- a/src/agents/registry.py +++ b/src/agents/registry.py @@ -4,7 +4,7 @@ import os import yaml import uuid from pathlib import Path -from typing import Annotated, TypedDict +from typing import Annotated, TypedDict, Optional, Any from abc import abstractmethod from dataclasses import dataclass, fields, field @@ -30,6 +30,24 @@ class Configuration(dict): 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 def from_runnable_config( cls, config: RunnableConfig | None = None, agent_name: str | None = None @@ -127,7 +145,7 @@ class Configuration(dict): else: confs[f.name] = value - if f.metadata.get("configurable"): + if f.metadata.get("configurable", True): configurable_items[f.name] = { "type": f.type.__name__, "name": f.metadata.get("name", f.name), @@ -139,23 +157,6 @@ class Configuration(dict): 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: diff --git a/web/src/views/AgentView.vue b/web/src/views/AgentView.vue index ac3b1517..8d154cc4 100644 --- a/web/src/views/AgentView.vue +++ b/web/src/views/AgentView.vue @@ -11,7 +11,7 @@
- 智能体:{{ agent.name }} - +
+

{{ agent.name }}

+

{{ agent.description }}

+
+
@@ -59,7 +62,7 @@ + - + + {{ option.label || option }} + - +
已选择 {{ getSelectedCount(key) }} 项 @@ -152,6 +158,22 @@
+ + + + + agents.value[selectedAgentId.value] || {}); 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({}); @@ -467,7 +500,7 @@ onMounted(async () => { // 获取配置标签 const getConfigLabel = (key, value) => { // 根据配置项属性选择合适的显示文本 - if (value.description) { + if (value.description && value.name !== key) { return `${value.name}(${key})`; } return key; @@ -655,11 +688,28 @@ const toggleConf = () => { .agent-option { display: flex; 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 { color: #faad14; font-size: 14px; + margin-left: 4px; } } @@ -752,6 +802,7 @@ const toggleConf = () => { max-height: 60vh; } } + @@ -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; + } +} \ No newline at end of file