feat: 实现 ReAct 推理模式并优化日志输出

新增 ReActAdvisor 引导 AI 按照 Thought-Action-Observation-Iterate 流程进行推理和工具调用,提升任务执行的系统性和完整性。同时优化 HTTP 流量日志,简化输出格式,提高日志可读性。

主要变更:
- 新增 ReActAdvisor 实现 ReAct 推理模式,order=-10 确保最先执行
- 在系统提示中添加 Skills 目录结构和脚本路径使用说明
- 优化 Advisor 链注释,明确各 Advisor 的执行顺序和职责
- 简化 HttpTrafficLogger 输出,移除冗余的请求/响应头信息
- 将日志最大体积从 100KB 提升到 1MB,支持更大的请求体

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
hughhuang(黄健铭)andClaude Sonnet 4.5 committed 2026-02-04 17:09:15 +08:00
1 parent 6b602f5cd0
commit e059d1aa50
3 files changed
+164 -37

No files matched your search

@@ -11,6 +11,7 @@ import org.springaicommunity.agent.tools.SkillsTool;
import org.springaicommunity.agent.tools.TodoWriteTool;
import org.springaicommunity.agent.tools.TodoWriteTool.Todos;
import org.springaicommunity.agent.tools.TodoWriteTool.Todos.TodoItem;
import org.springaicommunity.skills.advisor.ReActAdvisor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.ToolCallAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
@@ -80,7 +81,8 @@ public class Application {
ChatClient.Builder chatClientBuilder(ChatModel chatModel,
@Value("${agent.skills.dirs:Unknown}") List<Resource> agentSkillsDirs,
SyncMcpToolCallbackProvider mcpToolCallbackProvider,
ApplicationEventPublisher applicationEventPublisher) {
ApplicationEventPublisher applicationEventPublisher,
ReActAdvisor reactAdvisor) {
// @formatter:off
return ChatClient.builder(chatModel)
@@ -98,7 +100,13 @@ public class Application {
.defaultSystem("""
IMPORTANT: When the user requests any task, you MUST first check if there is an available Skill that matches the task.
Skills provide specialized capabilities and domain knowledge for specific tasks.
Skills Directory Structure:
- Base Path: D:\\\\workspace\\\\spring-ai-skill\\\\src\\\\main\\\\resources\\\\.claude\\\\skills
- Each skill has its own subdirectory: {base_path}\\\\{skill_name}
- Example: xlsx skill is located at D:\\\\workspace\\\\spring-ai-skill\\\\src\\\\main\\\\resources\\\\.claude\\\\skills\\\\xlsx
- When executing scripts from a skill, ALWAYS use the full absolute path
- Example script path: D:\\\\workspace\\\\spring-ai-skill\\\\src\\\\main\\\\resources\\\\.claude\\\\skills\\\\xlsx\\\\script.py
Tool Priority:
1. FIRST: Check available Skills and use the Skill tool if a matching skill exists
2. SECOND: Use other built-in tools (Bash, FileSystem, Glob, Grep, etc.) only if no suitable Skill is available
@@ -137,17 +145,23 @@ public class Application {
.defaultToolCallbacks(mcpToolCallbackProvider.getToolCallbacks())
.defaultAdvisors(
// Tool Calling advisor
// ReAct Advisor - order=-10,最先执行,添加 ReAct 推理引导
reactAdvisor,
// Tool Calling advisor - 处理工具调用的递归循环
ToolCallAdvisor.builder().build(),
// Custom logging advisor - order=-1 确保最先执行,可以捕获工具调用
// Custom logging advisor - order=-1,记录请求和工具调用
MyLoggingAdvisor.builder()
.order(-1)
.showAvailableTools(true)
.showSystemMessage(true)
.build(),
// Tool call capture advisor (接收来自 MyLoggingAdvisor 的工具调用信息)
// Tool call capture advisor - order=0,捕获工具调用信息供前端展示
ToolCallCaptureAdvisor.builder().order(0).build(),
// LLM 请求响应日志记录 - order=100 确保最后执行
// LLM 请求响应日志记录 - order=100,最后执行,记录完整交互
LLMLoggingAdvisor.builder()
.logDirectory("logs/llm")
.order(100)