feat: v2.0 配置驱动版 - 新增工具/技能/MCP无需改源码

重构内容:
- agent.py 替代 agent_v3.py,所有配置从 config.yaml 加载
- tools/ 目录自动扫描,丢.py文件即注册新工具
- skills/ 目录自动扫描,丢.yaml文件即注册新技能
- config.yaml 统一管理模型参数、MCP服务器、路由关键词
- MCP支持多服务器配置 + 确定性路由关键词
- 删除旧版 step1_basic_fc.py 和 agent_v3.py
This commit is contained in:
2026-04-23 23:16:08 +08:00
parent 451e9a12ed
commit 1c42ba0812
12 changed files with 848 additions and 643 deletions

2
tools/__init__.py Normal file
View File

@@ -0,0 +1,2 @@
# tools/ 目录的 __init__.py
# 自动扫描注册所有工具模块

15
tools/calculator.py Normal file
View File

@@ -0,0 +1,15 @@
"""计算工具"""
from langchain_core.tools import tool
@tool
def calculate(expression: str) -> str:
"""计算数学表达式,输入如 '2+3*4'"""
try:
result = eval(expression, {"__builtins__": {}}, {})
return f"计算结果: {expression} = {result}"
except Exception as e:
return f"计算错误: {e}"
TOOLS = [calculate]

19
tools/knowledge.py Normal file
View File

@@ -0,0 +1,19 @@
"""知识库搜索工具"""
from langchain_core.tools import tool
@tool
def search_knowledge(query: str) -> str:
"""搜索知识库(模拟)"""
kb = {
"黄庄三号": "黄庄三号是AI助手严肃认真听话聪明",
"LangGraph": "LangGraph是Agent框架支持状态图、循环、持久化",
"MCP": "MCP是Model Context ProtocolAI工具互操作标准协议",
}
for key, val in kb.items():
if key in query:
return val
return f"未找到关于'{query}'的信息"
TOOLS = [search_knowledge]

18
tools/weather.py Normal file
View File

@@ -0,0 +1,18 @@
"""天气查询工具"""
from langchain_core.tools import tool
@tool
def get_weather(city: str) -> str:
"""查询指定城市的天气信息"""
weather_data = {
"北京": "晴天气温22°C北风3级",
"上海": "多云气温25°C东风2级",
"深圳": "阵雨气温28°C南风4级",
"黄庄": "晴转多云气温23°C微风",
}
return weather_data.get(city, f"暂无{city}的天气数据")
# 暴露工具列表供自动扫描
TOOLS = [get_weather]