智能体研讨案例(初步设计)
# 信贷产品快速上线规划智能体 - 落地实施方案
# 一、项目概述
# 1.1 场景说明
本方案针对商业银行信贷领域中的"信贷产品快速上线规划"场景,设计一个具备自主规划、自我反思、学习进化能力的智能体。该智能体能够:
- 将模糊的信贷产品需求转化为结构化实施计划
- 自主决策执行各步骤并调用必要工具
- 分析执行结果并反思改进
- 从历史经验中学习并优化后续规划
# 1.2 智能体能力特点
- 自主规划:生成包含业务与技术细节的完整实施路径
- 自我反思:深度分析执行失败原因,提出具体改进建议
- 学习进化:从历史项目中提取模式,持续优化规划质量
- 业务闭环:严格遵循监管要求,确保产品合规上线
# 1.3 教学价值
- 展示智能体如何解决真实业务问题
- 演示"规划-执行-反思-学习"闭环实现
- 教授提示词工程、MCP工具集成等关键技能
- 提供可复用的智能体设计模式
# 二、前期准备工作
# 2.1 环境准备
确认平台版本:
- 源启智能体平台AgentOps v1.5.0 或更高
- 已集成MySQL MCP Server(系统自带)
创建会话变量: 在工作流开始前,配置以下会话变量:
变量名 类型 初始值 说明 iteration_count
int 0 当前迭代次数 max_iterations
int 5 最大迭代次数 target_achieved
bool false 目标是否达成 planning_history
对象数组 [] 规划历史记录 reflection_history
对象数组 [] 反思历史记录 execution_results
对象数组 [] 执行结果记录 current_plan
对象 null 当前执行的计划 historical_patterns
对象 {} 从数据库获取的历史模式 product_name
string "" 产品名称 target_amount
number 0 目标放款额 deadline
string "" 上线截止日期 target_customer
string "" 目标客户群体 special_requirements
string "" 特殊要求 resource_constraints
string "产品团队2人、技术团队4人、风控团队2人、测试团队2人" 资源约束
# 2.2 数据库表创建
通过"代码"节点执行以下SQL创建必要的表:
# 创建学习知识库表
execute(
"""CREATE TABLE IF NOT EXISTS learning_knowledge (
id INT AUTO_INCREMENT PRIMARY KEY,
issue VARCHAR(255) NOT NULL,
root_cause VARCHAR(255) NOT NULL,
solution TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)"""
)
# 创建规划历史表
execute(
"""CREATE TABLE IF NOT EXISTS planning_history (
id INT AUTO_INCREMENT PRIMARY KEY,
iteration INT NOT NULL,
plan JSON NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)"""
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 2.3 知识库准备
- 创建"信贷合规知识库":
- 上传《银保监会小微企业贷款管理办法》
- 添加历史信贷产品案例文档
- 包含常见合规问题及解决方案
- 知识库内容示例:
- 监管文件:《小微企业贷款管理办法》《普惠金融政策指引》
- 历史案例:3个成功/失败的信贷产品上线案例
- 最佳实践:信贷产品技术实施指南、合规检查清单
# 三、MCP Server创建指南
# 3.1 创建信贷业务MCP Server
- 进入MCP管理界面:
- 在智能体平台中,导航至"MCP管理" → "MCP Server管理"
- 点击"新建MCP Server"按钮
- 配置基本信息:
- 名称:
信贷业务MCP Server
- 描述:
提供信贷产品规划所需的业务工具
- 类型:
Python
- 执行环境:
本地
- 名称:
- 保存并激活:点击"保存"按钮,使新MCP Server生效
# 3.2 注册业务工具
# (1) 合规检查工具 (compliance_check
)
工具配置:
{ "name": "compliance_check", "description": "检查信贷产品规划是否符合监管要求", "parameters": [ { "name": "plan_step", "type": "string", "required": true, "description": "需要检查的规划步骤描述" }, { "name": "regulation", "type": "string", "required": false, "default": "小微企业贷款管理办法", "description": "适用的监管规定" } ], "return_type": { "success": "boolean", "issues": "array", "suggested_fix": "string" } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24工具实现:
def compliance_check(plan_step, regulation="小微企业贷款管理办法"): """模拟合规检查API""" if "审批时限" in plan_step and "5个工作日" not in plan_step: return { "success": False, "issues": ["审批时限不符合《小微企业贷款管理办法》第15条规定"], "suggested_fix": "将审批时限调整为不超过5个工作日" } if "利率" in plan_step and "LPR+150BP" not in plan_step: return { "success": False, "issues": ["利率设置不符合监管上限要求"], "suggested_fix": "确保利率不超过LPR+150BP" } return {"success": True, "issues": [], "suggested_fix": ""}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# (2) 风险评估工具 (risk_assessment
)
工具配置:
{ "name": "risk_assessment", "description": "评估信贷产品风险水平", "parameters": [ { "name": "product_type", "type": "string", "required": true, "description": "产品类型" }, { "name": "target_amount", "type": "number", "required": true, "description": "目标放款额" } ], "return_type": { "success": "boolean", "issues": "array", "suggestions": "array" } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23工具实现:
def risk_assessment(product_type, target_amount): """模拟风险评估API""" if product_type == "闪电贷" and target_amount > 30000000: return { "success": False, "issues": ["目标放款额超过风控模型验证范围"], "suggestions": ["建议分阶段实施,首期目标设为3000万"] } return {"success": True, "issues": [], "suggestions": []}
1
2
3
4
5
6
7
8
9
10
# (3) 资源调度工具 (resource_scheduler
)
工具配置:
{ "name": "resource_scheduler", "description": "检查技术资源可用性", "parameters": [ { "name": "team", "type": "string", "required": true, "description": "需要协调的团队" }, { "name": "required_tasks", "type": "string", "required": true, "description": "需要完成的任务" }, { "name": "start_date", "type": "string", "required": true, "description": "计划开始日期" } ], "return_type": { "success": "boolean", "available_date": "string", "conflicts": "array" } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29工具实现:
def resource_scheduler(team, required_tasks, start_date): """模拟资源调度系统""" if team == "技术团队" and "系统改造" in required_tasks and start_date < "2023-11-10": return { "success": False, "available_date": "2023-11-10", "conflicts": ["核心系统升级项目占用资源"] } return {"success": True, "available_date": None, "conflicts": []}
1
2
3
4
5
6
7
8
9
10
# (4) 系统依赖分析工具 (system_dependency
)
工具配置:
{ "name": "system_dependency", "description": "分析系统改造的依赖关系", "parameters": [ { "name": "system_changes", "type": "array", "required": true, "description": "计划进行的系统变更" } ], "return_type": { "success": "boolean", "critical_path": "array", "historical_issues": "array" } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17工具实现:
def system_dependency(system_changes): """模拟系统依赖分析服务""" dependency_graph = { "核心系统改造": ["风控模型集成", "渠道接口开发"], "征信接口对接": ["反欺诈系统对接"], "风控模型集成": ["数据中台对接"] } critical_path = [] for change in system_changes: if change in dependency_graph: critical_path.extend(dependency_graph[change]) return { "success": True, "critical_path": list(set(critical_path)), "historical_issues": ["核心系统改造常因表结构调整影响其他模块"] if "核心系统改造" in system_changes else [] }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 四、工作流详细设计与配置
# 4.1 工作流概览
flowchart LR
A([开始]) --> B[输入节点<br>表单收集产品信息]
B --> C{参数验证节点}
C -->|参数完整| D[LLM规划节点]
C -->|参数不完整| E[补充询问节点]
E --> B
D --> F[解析规划结果]
F --> G{有待执行步骤?}
G -->|是| H[助手节点<br>自主执行步骤]
H --> G
G -->|否| I[反思LLM节点]
I --> J[反思结果处理]
J --> K{目标达成?}
K -->|是| L[输出成功消息]
K -->|否| M{需重新规划?}
M -->|是| N[学习进化节点<br>使用MySQL MCP Server]
M -->|否| O[输出失败消息]
N --> D
L --> Z([结束])
O --> Z
classDef startend fill:#f0f8ff,stroke:#2e8b57,stroke-width:2px
classDef process fill:#e6f7ff,stroke:#1890ff,stroke-width:1.5px
classDef decision fill:#f6ffed,stroke:#52c41a,stroke-width:1.5px
classDef special fill:#fff7e6,stroke:#fa8c16,stroke-width:1.5px
class A,Z startend
class B,D,E,F,H,I,J,L,O process
class C,G,K,M decision
class N special
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 4.2 详细节点配置指南
# (1) 开始节点
- 配置:
- 开场白:
"您好!我是信贷产品规划助手,可以帮助您快速规划新产品上线。请填写以下产品信息:"
- 引导问题:
"请描述您需要上线的信贷产品,包括产品名称、目标放款额、上线时间等关键信息。"
- 系统自动创建:
current_time
(工作流启动时间)、chat_history
(最近10轮聊天记录)
- 开场白:
# (2) 输入节点(表单输入)
配置:
{ "type": "form", "title": "信贷产品规划信息收集", "description": "请填写以下必要信息,以便我们为您生成产品上线规划", "fields": [ { "name": "product_name", "label": "产品名称", "type": "text", "required": true, "placeholder": "例如:闪电贷", "description": "产品的正式名称" }, { "name": "target_amount", "label": "目标放款额(元)", "type": "number", "required": true, "placeholder": "例如:50000000", "description": "产品上线首月的目标放款金额" }, { "name": "deadline", "label": "上线截止日期", "type": "date", "required": true, "description": "产品必须上线的最后日期" }, { "name": "target_customer", "label": "目标客户群体", "type": "select", "required": true, "options": [ {"value": "小微企业", "label": "小微企业"}, {"value": "个体工商户", "label": "个体工商户"}, {"value": "其他", "label": "其他"} ], "description": "产品主要服务的客户类型" }, { "name": "special_requirements", "label": "特殊要求", "type": "textarea", "required": false, "placeholder": "例如:需要与现有信贷系统无缝对接", "description": "产品设计的特殊要求或约束条件" } ] }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# (3) 参数验证节点(代码节点)
配置:
# 检查必要参数是否完整 required_params = ["product_name", "target_amount", "deadline", "target_customer"] missing_params = [param for param in required_params if not globals().get(param)] return { "params_valid": len(missing_params) == 0, "missing_params": missing_params }
1
2
3
4
5
6
7
8连接:
- 条件1:
params_valid == true
→ LLM规划节点 - 条件2:
params_valid == false
→ 补充询问节点
- 条件1:
# (4) 补充询问节点(输出节点)
配置:
# 检查必要参数是否完整 required_params = ["product_name", "target_amount", "deadline", "target_customer"] missing_params = [param for param in required_params if not globals().get(param)] return { "params_valid": len(missing_params) == 0, "missing_params": missing_params }
1
2
3
4
5
6
7
8连接:下一步 → 输入节点(形成参数收集循环)
# (5) LLM规划节点
配置:
- 模型选择:
Qwen3-32B-AWQ
(本地部署,保障数据安全) - 温度:
0.3
(确保输出稳定) - 最大Token:
2000
- JSON模式:
启用
(确保格式正确)
- 模型选择:
系统提示词:
# 角色 你是一个专业的信贷产品规划专家,擅长将模糊目标转化为可执行、可验证的详细计划。 # 工作原则 1. 采用"目标-障碍-资源-验证"四维框架思考 2. 每个步骤必须包含执行主体、时间节点和成功标准 3. 识别关键风险并提供备选方案 4. 考虑历史规划失败原因进行针对性优化 5. 严格遵守银保监会《小微企业贷款管理办法》 6. 你可以使用的工具严格限制在如下4个范围内:complianceCheck(检查信贷产品规划是否符合监管要求)、riskAssessment(评估信贷产品风险)、resourceScheduler(检查技术资源可用性)、systemDependency(分析系统改造的依赖关系),因为系统只提供了这4个工具 7. 在规划的执行步骤中严格使用提供的4个工具(1个或多个),绝对不要使用其他工具 # 输出格式(严格JSON) { "planning_meta": { "objective": "清晰目标", "time_constraint": "时间限制", "resource_constraint": "资源限制" }, "execution_steps": [ { "step_id": "S1", "description": "步骤描述", "responsible": "执行主体", "deadline": "YYYY-MM-DD", "success_criteria": "可验证标准", "required_tools": ["complianceCheck", "riskAssessment"], "status": "pending" } ], "risk_analysis": [ { "risk_id": "R1", "description": "风险描述", "probability": 3, "impact": 4, "mitigation": "应对措施", "fallback": "备选方案" } ] }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39用户提示词:
# 产品需求 - 产品名称:输入/product_name - 目标放款额:输入/target_amount元 - 上线截止日期:输入/deadline - 目标客户:输入/target_customer - 特殊要求:输入/special_requirements # 历史信息 - 上次迭代结果: {CONVERSATION/execution_results[-1]['details'] if CONVERSATION/execution_results else '无历史'} - 之前失败原因: {CONVERSATION/reflection_history[-1]['reflection']['key_issues'] if CONVERSATION/reflection_history else '无'} # 当前约束 - 剩余迭代次数: {CONVERSATION/max_iterations - CONVERSATION/iteration_count} - 历史学习模式: {json.dumps(CONVERSATION/historical_patterns) if CONVERSATION/historical_patterns else '无'} # 合规要求 - 必须符合: 银保监会《小微企业贷款管理办法》 - 特别注意: {retrieve_complianceCheck(输入/product_name)}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15连接:下一步 → 变量赋值(解析规划)节点
# (6) 变量赋值(解析规划)节点
配置:
import json # 解析LLM输出 plan = json.loads(output) # output来自LLM节点 # 初始化所有步骤状态 for step in plan["execution_steps"]: step["status"] = "pending" # 更新规划历史 planning_history.append({ "iteration": iteration_count, "plan": plan, "timestamp": current_time }) # 存储到数据库 if iteration_count > 0: # 非初始规划 execute( "INSERT INTO planning_history (iteration, plan) VALUES (%s, %s)", (iteration_count, json.dumps(plan)) ) return { "current_plan": plan, "planning_history": planning_history }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27连接:下一步 → 有待执行步骤判断节点
在智能体中运行后的plan是类似于如下的值:
{
"planning_meta": {
"objective": "完成闪电贷产品规划并实现与现有信贷系统无缝对接,达成5000000000元目标放款额",
"time_constraint": "2023-12-02前完成产品上线",
"resource_constraint": "技术团队需同时支持3个其他项目,合规部门仅能提供2名专员"
},
"execution_steps": [
{
"step_id": "S1",
"description": "完成产品合规性审查",
"responsible": "合规部",
"deadline": "2023-11-05",
"success_criteria": "获得银保监会《小微企业贷款管理办法》合规批文",
"required_tools": ["complianceCheck"],
"status": "pending"
},
{
"step_id": "S2",
"description": "开展专项风险评估",
"responsible": "风险管理部",
"deadline": "2023-11-10",
"success_criteria": "完成客户画像分析并建立风险定价模型",
"required_tools": ["riskAssessment"],
"status": "pending"
},
{
"step_id": "S3",
"description": "确定系统对接方案",
"responsible": "技术部",
"deadline": "2023-11-15",
"success_criteria": "输出包含API接口规范和数据迁移方案的技术文档",
"required_tools": ["systemDependency"],
"status": "pending"
},
{
"step_id": "S4",
"description": "确认资源调配计划",
"responsible": "项目经理",
"deadline": "2023-11-20",
"success_criteria": "完成跨部门资源分配表并获得CTO签批",
"required_tools": ["resourceScheduler"],
"status": "pending"
}
],
"risk_analysis": [
{
"risk_id": "R1",
"description": "合规审批延迟",
"probability": 3,
"impact": 4,
"mitigation": "建立监管沟通双通道机制",
"fallback": "启动应急备案流程"
},
{
"risk_id": "R2",
"description": "系统对接异常",
"probability": 3,
"impact": 5,
"mitigation": "实施灰度上线机制",
"fallback": "启用备用接口方案"
},
{
"risk_id": "R3",
"description": "客户资质不符",
"probability": 2,
"impact": 3,
"mitigation": "建立动态授信评估模型",
"fallback": "启动人工复核机制"
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# (7) 有待执行步骤判断节点(条件分支)
配置:
条件表达式:
current_plan and any(step['status'] == 'pending' for step in current_plan['execution_steps'])s
1真路径 → 执行下一个步骤节点
假路径 → 反思LLM节点
# (8) 助手节点(核心执行能力)
配置:
- 模型选择:
Qwen3-32B-AWQ
- 温度:
0.3
- 挂接知识库:
信贷合规知识库
- 添加工具:
信贷业务MCP Server
中的4个工具 - 批量执行:
否
- 模型选择:
系统提示词(关键配置):
# 角色 你是一个专业的信贷实施专家助手,负责自主执行信贷产品规划中的具体步骤。 # 工作原则 1. **深度思考**:分析当前步骤需求,选择最合适的工具 2. **精准调用**:根据步骤描述确定需要调用的MCP工具及参数 3. **结果验证**:检查工具调用结果,判断是否达到成功标准 4. **问题处理**:如遇失败,尝试分析原因并提出解决方案 5. **状态更新**:及时更新步骤执行状态和结果 # 工具调用指南 - 当步骤涉及"合规"、"监管"、"审批"时 → 调用`compliance_check` - 当步骤涉及"风险"、"评估"、"模型"时 → 调用`risk_assessment` - 当步骤涉及"资源"、"排期"、"团队"时 → 调用`resource_scheduler` - 当步骤涉及"系统"、"依赖"、"改造"时 → 调用`system_dependency` # 输出要求 1. 必须先分析需要调用的工具及理由 2. 明确指定工具名称和参数 3. 模拟工具调用并解释结果 4. 判断步骤是否成功完成 5. 如失败,提供具体改进建议 # 禁止行为 - 不得编造不存在的工具 - 不得跳过必要的工具调用 - 遇到模糊需求时必须请求澄清
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27用户提示词:
# 当前执行上下文 - 产品名称:{product_name} - 规划目标:{current_plan['planning_meta']['objective'] if current_plan else ''} - 当前迭代:第{iteration_count+1}轮 # 待执行步骤 { "step_id": "{next_step['step_id']}", "description": "{next_step['description']}", "responsible": "{next_step['responsible']}", "deadline": "{next_step['deadline']}", "success_criteria": "{next_step['success_criteria']}", "required_tools": {json.dumps(next_step['required_tools'])} } # 历史执行结果 {json.dumps(execution_results[-3:], indent=2) if execution_results else '无历史执行'} # 业务约束 - 必须符合:银保监会《小微企业贷款管理办法》 - 可用资源:{resource_constraints}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21连接:下一步 → 有待执行步骤判断节点(形成执行循环)
# (9) 反思LLM节点
配置:
- 模型选择:
Qwen-Max
(或Qwen3-32B-AWQ) - 温度:
0.2
(确保反思深度) - 最大Token:
1500
- 模型选择:
系统提示词:
# 角色 你是一个专业的信贷反思分析专家,专注于从执行结果中提取经验教训。 # 分析框架 1. 目标达成度分析:对比预期与实际结果 2. 根本原因分析:使用5Why方法追溯问题源头 3. 模式识别:检查是否与历史问题重复 4. 改进建议:提出具体、可操作的优化方案 5. 合规性审查:确保所有步骤符合监管要求 # 输出格式(严格JSON) { "reflection_summary": "整体评估", "key_issues": ["问题1", "问题2"], "root_causes": ["根本原因1", "根本原因2"], "improvement_suggestions": [ { "suggestion_id": "I1", "description": "改进建议", "impact_level": 3, "implementation_complexity": 2 } ], "replanning_needed": true, "compliance_status": "fully_compliant/partially_compliant/non_compliant" }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26用户提示词:
# 执行回顾 - 计划目标: {current_plan['planning_meta']['objective'] if current_plan else ''} - 实际结果: {', '.join([f"{r['step_id']}: {'成功' if r['success'] else '失败'}" for r in execution_results[-5:]])} # 关键数据 - 成功步骤: {len([r for r in execution_results if r['success']])}/{len(current_plan['execution_steps']) if current_plan else 0} - 失败步骤: {', '.join([r['step_id'] for r in execution_results if not r['success']][-3:])} # 历史对比 - 之前迭代: {iteration_count}次尝试 - 常见失败模式: {json.dumps(historical_patterns) if historical_patterns else '无'}
1
2
3
4
5
6
7
8
9
10
11连接:下一步 → 反思结果处理节点
# (10) 反思结果处理节点(变量赋值)
配置:
import json # 解析反思结果 reflection = json.loads(output) # output来自反思LLM节点 # 保存反思结果 reflection_history.append({ "iteration": iteration_count, "reflection": reflection, "timestamp": current_time }) # 检查目标是否达成 all_steps_completed = all(step['status'] == 'completed' for step in current_plan['execution_steps']) target_achieved = all_steps_completed and not any(not r['success'] for r in execution_results) return { "reflection_history": reflection_history, "target_achieved": target_achieved, "replanning_needed": reflection['replanning_needed'] }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21连接:
- 下一步 → 目标达成判断节点
# (11) 目标达成判断节点(条件分支)
- 配置:
- 条件表达式:
target_achieved
- 真路径 → 输出成功消息节点
- 假路径 → 需重新规划判断节点
- 条件表达式:
# (12) 需重新规划判断节点(条件分支)
- 配置:
- 条件表达式:
replanning_needed and iteration_count < max_iterations
- 真路径 → 学习进化节点
- 假路径 → 输出失败消息节点
- 条件表达式:
# (13) 学习进化节点(代码节点)
配置:
import json # 从反思中提取学习点 learning_points = [] reflection = reflection_history[-1]['reflection'] for i, issue in enumerate(reflection['key_issues']): if i < len(reflection['root_causes']): learning_points.append({ "issue": issue, "root_cause": reflection['root_causes'][i], "solution": next( (s['description'] for s in reflection['improvement_suggestions'] if s['impact_level'] > 2), "" ) }) # 存储到学习知识库 for point in learning_points: # 使用MySQL MCP Server的execute工具 execute( """INSERT INTO learning_knowledge (issue, root_cause, solution) VALUES (%s, %s, %s)""", (point['issue'], point['root_cause'], point['solution']) ) # 从数据库获取历史模式 historical_patterns = query( """SELECT issue, root_cause, solution FROM learning_knowledge ORDER BY created_at DESC LIMIT 10""" ) # 增加迭代计数 iteration_count += 1 return { "historical_patterns": historical_patterns, "iteration_count": iteration_count }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41连接:下一步 → LLM规划节点(形成学习进化循环)
# (14) 输出成功消息节点
配置:
✅ 产品规划成功!{current_plan['planning_meta']['objective']} 📊 执行结果: - 完成步骤:{len([r for r in execution_results if r['success']])}/{len(current_plan['execution_steps'])} - 首月目标:{current_plan['planning_meta'].get('target_amount', '未知')} - 实际达成:{sum(r['details'].get('amount', 0) for r in execution_results if r['success'] and 'amount' in r['details'])} 💡 关键经验: {chr(10).join([f"• {p['issue']}: {p['solution']}" for p in historical_patterns[:3]]) if historical_patterns else '无历史经验'} 📈 建议:{reflection_history[-1]['reflection']['improvement_suggestions'][0]['description'] if reflection_history and 'improvement_suggestions' in reflection_history[-1]['reflection'] and reflection_history[-1]['reflection']['improvement_suggestions'] else ''}
1
2
3
4
5
6
7
8
9
10
11
# (15) 输出失败消息节点
配置:
❌ 规划未能达成目标,请检查以下问题: {chr(10).join([f"• {r['step_id']}: {r['details'].get('issues', ['未知问题'])[0]}" for r in execution_results if not r['success']])} 🔁 已尝试{iteration_count}次,最大尝试次数为{max_iterations}次。 💡 建议:{reflection_history[-1]['reflection']['improvement_suggestions'][0]['description'] if reflection_history and 'improvement_suggestions' in reflection_history[-1]['reflection'] and reflection_history[-1]['reflection']['improvement_suggestions'] else '无建议'}
1
2
3
4
5
6
7
8
# (16) 结束节点
- 配置:无(仅标识工作流结束)
# 五、教学演示指南
# 5.1 演示准备
清理环境:
- 清空
learning_knowledge
表:TRUNCATE TABLE learning_knowledge
- 重置会话变量:确保
iteration_count=0
- 清空
准备演示数据:
- 用户输入:
"需要在6周内推出面向小微企业的'闪电贷'产品,目标是实现首月5000万放款额。当前已有风控模型基础,但缺乏完整的端到端产品规划。"
- 用户输入:
开启调试模式:
- 在工作流设置中启用"显示节点执行详情"
- 配置助手节点显示"思考过程"
# 5.2 演示流程
# (1) 第一轮迭代
- 用户输入:提供完整产品信息
- 关键观察点:
- LLM规划节点生成的初始计划(10个步骤)
- 助手节点如何自主决策调用合规检查工具
- 执行结果:S3(合规检查)失败、S5(资源调度)失败
- 教学重点:
- 展示AI如何分析步骤并选择工具
- 强调完整信息收集的重要性
# (2) 第二轮迭代
- 关键观察点:
- 反思LLM节点如何分析失败原因
- 学习进化节点如何将经验存入数据库
- LLM规划节点如何利用历史经验优化新计划
- 教学重点:
- 5Why分析法在反思中的应用
- 历史经验如何影响新规划
# (3) 第三轮迭代
- 关键观察点:
- 所有步骤成功执行
- 首月放款5280万元(超出目标5.6%)
- 输出中展示的历史经验应用
- 教学重点:
- 学习进化的实际效果
- 闭环价值的量化展示
# 5.3 互动实验设计
# (1) 初级实验:提示词调整
- 任务:修改助手节点的系统提示词,优化工具选择逻辑
- 步骤:
- 在系统提示词中添加:"当不确定时,优先调用合规检查工具"
- 重新运行工作流
- 观察AI决策变化
- 教学目标:理解提示词对AI行为的影响
# (2) 中级实验:知识库增强
- 任务:向信贷合规知识库添加新监管文档
- 步骤:
- 上传《2023年小微企业贷款新政策》
- 修改产品需求,包含新政策相关内容
- 观察AI如何利用新知识做出决策
- 教学目标:理解知识库对AI决策的支持作用
# (3) 高级实验:工具扩展
- 任务:在信贷业务MCP Server中添加新工具
- 步骤:
- 添加"贷后管理评估"工具
- 修改系统提示词,使AI能够使用新工具
- 设计测试用例验证新功能
- 教学目标:掌握MCP工具扩展方法
# 5.4 教学要点
# (1) 核心概念教学
- 自主规划:
- 演示LLM如何将模糊需求转化为结构化计划
- 强调JSON输出格式对后续处理的重要性
- 自我反思:
- 展示反思节点如何进行5Why分析
- 分析反思质量与提示词设计的关系
- 学习进化:
- 演示历史经验如何影响新规划
- 量化展示学习效果(如:规划质量提升百分比)
# (2) 技术要点教学
- 提示词工程:
- 系统提示词的角色定义技巧
- 用户提示词的动态变量注入
- JSON格式输出的约束方法
- MCP集成:
- MCP Server创建流程
- 工具描述对AI使用的影响
- 挡板工具开发技巧
- 工作流设计:
- 循环结构的实现方法
- 状态管理的最佳实践
- 错误处理机制设计
# 六、常见问题与解决方案
# 6.1 配置问题
# 问题:助手节点无法找到MCP工具
- 原因:MCP Server未正确注册或工具配置错误
- 解决方案:
- 检查MCP Server是否已激活
- 确认工具名称与配置完全一致
- 检查工具参数是否匹配调用需求
# 问题:JSON解析错误
原因:LLM输出不符合预期JSON格式
解决方案:
在系统提示词中强化JSON格式要求
在变量赋值节点添加错误处理:
try: plan = json.loads(output) except json.JSONDecodeError: plan = {"error": "JSON解析失败", "raw_output": output}
1
2
3
4
# 6.2 执行问题
# 问题:无限循环
原因:条件判断错误导致无法退出循环
解决方案:
确保
max_iterations
设置合理在学习进化节点中添加:
if iteration_count >= max_iterations: replanning_needed = False
1
2
# 问题:助手节点决策质量低
- 原因:提示词设计不佳或知识库不足
- 解决方案:
- 优化系统提示词,增加决策指导
- 丰富信贷合规知识库内容
- 调整模型温度参数(建议0.2-0.4)
# 6.3 教学问题
# 问题:学员难以理解循环结构
- 解决方案:
- 使用可视化流程图展示数据流
- 分步演示,先展示单次执行,再展示完整循环
- 使用颜色标记不同迭代的数据
# 问题:难以展示学习进化效果
- 解决方案:
- 创建对比演示:有学习 vs 无学习
- 展示
learning_knowledge
表中的历史记录 - 量化展示规划质量提升(如:成功率、执行时间)
# 七、附录
# 7.1 完整流程图
flowchart LR
A([开始]) --> B[输入节点<br>表单收集产品信息]
B --> C{参数验证节点}
C -->|参数完整| D[LLM规划节点]
C -->|参数不完整| E[补充询问节点]
E --> B
D --> F[解析规划结果]
F --> G{有待执行步骤?}
G -->|是| H[助手节点<br>自主执行步骤]
H --> G
G -->|否| I[反思LLM节点]
I --> J[反思结果处理]
J --> K{目标达成?}
K -->|是| L[输出成功消息]
K -->|否| M{需重新规划?}
M -->|是| N[学习进化节点<br>使用MySQL MCP Server]
M -->|否| O[输出失败消息]
N --> D
L --> Z([结束])
O --> Z
classDef startend fill:#f0f8ff,stroke:#2e8b57,stroke-width:2px
classDef process fill:#e6f7ff,stroke:#1890ff,stroke-width:1.5px
classDef decision fill:#f6ffed,stroke:#52c41a,stroke-width:1.5px
classDef special fill:#fff7e6,stroke:#fa8c16,stroke-width:1.5px
class A,Z startend
class B,D,E,F,H,I,J,L,O process
class C,G,K,M decision
class N special
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 7.2 示例数据
# 成功的反思结果示例
{
"reflection_summary": "成功识别并解决了技术依赖问题",
"key_issues": ["系统依赖关系分析不充分"],
"root_causes": ["未使用系统依赖分析工具"],
"improvement_suggestions": [
{
"suggestion_id": "I3",
"description": "在规划阶段调用系统依赖分析工具",
"impact_level": 5,
"implementation_complexity": 1
}
],
"replanning_needed": false,
"compliance_status": "fully_compliant"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 学习知识库记录示例
INSERT INTO learning_knowledge (issue, root_cause, solution)
VALUES (
'审批时限不符合监管要求',
'未详细查阅《小微企业贷款管理办法》具体条款',
'增加监管条款详细解读步骤,并提前进行监管预沟通'
);
1
2
3
4
5
6
2
3
4
5
6
# 7.3 扩展建议
# 业务场景扩展
- 贷后管理策略优化:复用相同工作流模式,仅替换MCP工具和提示词
- 风险事件应急处置:调整规划目标为风险处置,增加风险监测工具
# 技术能力扩展
- 多模型协同:为不同节点配置不同模型(规划用Qwen3-32B-AWQ,反思用Qwen-Max)
- 自动化测试:添加"测试用例生成"工具,增强规划验证能力
# 教学能力扩展
- 难度分级:设计初级、中级、高级三个教学版本
- 故障库:预设常见错误场景,用于教学演示
版权声明:本方案由[Kevin Zhang]编写,仅供教学使用。如需商业用途,请联系作者获取授权。
版本信息:v1.0 | 最后更新:2025-9-27
技术支持:xprogrammer@163.com
编辑 (opens new window)
上次更新: 2025/10/16, 15:19:01