Files
spring-ai-skill/docs/快速开始指南.md
hughhuangandClaude Sonnet 4.5 85b3130514 docs: 添加快速开始指南
- 提供 5 分钟快速启动步骤
- 包含常见问题解答和故障排查
- 提供实战场景示例
- 说明进阶使用和开发模式
- 添加完整的检查清单

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-30 16:12:00 +08:00

391 lines
7.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 快速开始指南
本指南将帮助你在 5 分钟内启动并运行 Spring AI Skills Demo 项目。
## 📋 前置要求
- ✅ JDK 17 或更高版本
- ✅ Maven 3.6 或更高版本
- ✅ Node.js 16+ (用于 MCP 服务器)
- ✅ 智谱 AI API Key(或其他 LLM 提供商)
## 🚀 5 分钟快速启动
### 步骤 1:克隆项目
```bash
git clone <repository-url>
cd spring-ai-skill
```
### 步骤 2:配置 API Key
编辑 `src/main/resources/application.properties`:
```properties
# 使用智谱 AI(推荐,已配置)
spring.ai.openai-sdk.api-key=你的智谱AI_API_KEY
# 或使用其他模型(需要修改 pom.xml)
# spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
# spring.ai.openai.api-key=${OPENAI_API_KEY}
```
**获取智谱 AI API Key**:
1. 访问 https://open.bigmodel.cn/
2. 注册并登录
3. 在控制台创建 API Key
### 步骤 3:启动 MCP 服务器(可选)
如果需要使用风险成本工具:
```bash
# 检查 Node.js 版本
node --version
# MCP 服务器会在应用启动时自动启动
# 确保路径正确:mcp-servers/risk-cost-server/index.js
```
### 步骤 4:启动应用
```bash
# 编译并启动
mvn spring-boot:run
# 或者先编译再运行
mvn clean package
java -jar target/skills-demo-0.1.0-SNAPSHOT.jar
```
### 步骤 5:访问 Web 界面
打开浏览器访问:**http://localhost:8080**
🎉 恭喜!你已经成功启动项目!
---
## 💡 第一次使用
### 示例 1:简单对话
在 Web 界面输入:
```
你好,请介绍一下你的功能
```
Agent 会介绍可用的工具和 Skills。
### 示例 2:使用 TodoWrite
```
请帮我分析一个复杂任务的执行步骤,使用 TodoWrite 组织任务
```
你会看到类似这样的进度显示:
```
📋 Progress: 1/3 tasks completed (33%)
[✓] 理解用户需求
[→] 分解任务步骤
[ ] 生成执行计划
```
### 示例 3:调用定价 Skill
```
请帮我为"测试科技公司"进行客户定价
```
Agent 会自动调用定价 Skill,执行完整的定价流程。
### 示例 4:使用 MCP 工具
```
请获取"某某企业"的风险成本率
```
Agent 会调用 MCP 工具获取风险成本数据。
---
## 🔧 常见问题
### Q1: 启动失败,提示端口被占用
**解决方案**:修改 `application.properties` 中的端口
```properties
server.port=8081 # 改为其他端口
```
### Q2: MCP 工具调用失败
**检查清单**:
1. ✅ Node.js 是否安装:`node --version`
2. ✅ MCP 服务器路径是否正确
3. ✅ 查看日志:`logs/llm/` 目录
**临时禁用 MCP**:
注释掉 `Application.java` 中的 MCP 配置:
```java
// 暂时注释掉
// .defaultToolCallbacks(mcpToolCallbackProvider.getToolCallbacks())
```
### Q3: Skills 未加载
**检查**:
```properties
# 确认配置正确
agent.skills.dirs=classpath:/.claude/skills
```
**验证 Skills 目录**:
```bash
ls src/main/resources/.claude/skills/
# 应该看到 pricing/ 目录
```
### Q4: API Key 无效
**症状**:返回 401 或 403 错误
**解决方案**:
1. 检查 API Key 是否正确
2. 确认 API Key 有足够的额度
3. 检查网络连接
### Q5: TodoWrite 不显示进度
**原因**:Agent 没有使用 TodoWrite 工具
**解决方案**:在提示词中明确要求
```
请使用 TodoWrite 工具组织你的任务步骤
```
---
## 📚 下一步
### 学习资源
1. **阅读文档**
- [TodoWrite 使用指南](TodoWrite使用指南.md)
- [项目总结](项目总结.md)
2. **探索 Skills**
- 查看 `src/main/resources/.claude/skills/pricing/`
- 了解如何创建自定义 Skill
3. **查看日志**
- LLM 请求日志:`logs/llm/`
- 应用日志:控制台输出
### 进阶使用
#### 1. 添加新的 Skill
```bash
# 创建新 Skill 目录
mkdir -p src/main/resources/.claude/skills/my-skill
# 创建 SKILL.md
cat > src/main/resources/.claude/skills/my-skill/SKILL.md << 'EOF'
---
name: my-skill
description: 我的自定义 Skill
version: 1.0.0
---
# 任务说明
这里是 Skill 的详细说明...
EOF
# 重启应用
```
#### 2. 添加新的 MCP 工具
```bash
# 创建 MCP 服务器
mkdir -p mcp-servers/my-tool
cd mcp-servers/my-tool
npm init -y
npm install @modelcontextprotocol/sdk
# 创建 index.js
# ... (参考 risk-cost-server/index.js)
# 配置 application.properties
spring.ai.mcp.client.stdio.connections.my-tool.command=node
spring.ai.mcp.client.stdio.connections.my-tool.args[0]=mcp-servers/my-tool/index.js
```
#### 3. 切换 LLM 模型
**使用 Claude**:
```xml
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-anthropic</artifactId>
</dependency>
```
```properties
# application.properties
spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
spring.ai.anthropic.chat.options.model=claude-sonnet-4-5-20250929
```
**使用 OpenAI**:
```properties
spring.ai.openai.api-key=${OPENAI_API_KEY}
spring.ai.openai.chat.options.model=gpt-4
```
---
## 🎯 实战场景
### 场景 1:客户定价流程
```
用户:请帮我为"深圳某某科技有限公司"执行完整的定价流程
Agent 会:
1. 调用客户评级 Skill
2. 使用 MCP 获取风险成本
3. 选择定价方法
4. 计算最终利率
5. 展示结果
全程使用 TodoWrite 显示进度
```
### 场景 2:批量数据分析
```
用户:分析最近 3 个月的定价数据,找出异常客户并生成报告。
使用 TodoWrite 组织任务。
Agent 会:
1. 读取数据文件
2. 分析异常客户
3. 生成调整建议
4. 保存报告
实时显示任务进度
```
### 场景 3:文件操作
```
用户:读取 data/customers.json 文件,统计客户数量
Agent 会:
1. 使用 FileSystemTools 读取文件
2. 解析 JSON 数据
3. 统计并返回结果
```
---
## 🛠️ 开发模式
### 启用调试日志
```properties
# application.properties
logging.level.org.springaicommunity=DEBUG
logging.level.org.springframework.ai=DEBUG
```
### 查看工具调用详情
控制台会显示:
```
USER:
- TOOLS: ["Skill", "TodoWrite", "get_customer_risk_cost", ...]
- TEXT: 用户输入的内容
ASSISTANT:
- TOOL-CALL: Skill ({"command": "客户定价", ...})
- TEXT: Agent 的响应
```
### 查看 LLM 日志
```bash
# 查看最新的 LLM 请求
ls -lt logs/llm/
# 查看具体日志
cat logs/llm/request-2026-01-30-*.json
```
---
## 📞 获取帮助
### 遇到问题?
1. **查看日志**
- 应用日志:控制台
- LLM 日志:`logs/llm/`
2. **检查配置**
- `application.properties`
- `pom.xml`
3. **查看文档**
- [项目总结](项目总结.md)
- [TodoWrite 使用指南](TodoWrite使用指南.md)
4. **提交 Issue**
- 描述问题
- 附上日志
- 说明环境信息
### 社区资源
- [Spring AI 官方文档](https://docs.spring.io/spring-ai/reference/)
- [Spring AI GitHub](https://github.com/spring-projects/spring-ai)
- [MCP 协议文档](https://modelcontextprotocol.io/)
---
## ✅ 检查清单
启动前确认:
- [ ] JDK 17+ 已安装
- [ ] Maven 已安装
- [ ] API Key 已配置
- [ ] 端口 8080 未被占用
- [ ] Node.js 已安装(如需 MCP)
启动后验证:
- [ ] 应用成功启动(无错误日志)
- [ ] Web 界面可访问
- [ ] 可以发送消息并收到回复
- [ ] Skills 已加载(查看日志)
- [ ] MCP 工具可用(可选)
---
**祝你使用愉快!** 🎉
如有问题,请查看 [项目总结](项目总结.md) 或提交 Issue。