package org.example.agent.tool; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.ai.tool.annotation.Tool; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Component; import java.time.LocalDateTime; @Component public class DateTimeTools { private static final Logger logger = LoggerFactory.getLogger(DateTimeTools.class); /** 工具名常量,用于动态构建提示词 */ public static final String TOOL_GET_CURRENT_DATETIME = "getCurrentDateTime"; @Tool(description = "Get the current date and time in the user's timezone. " + "IMPORTANT: Time changes constantly. Always call this tool when user asks about time, " + "even if there's a recent time query in the conversation history.") public String getCurrentDateTime() { String currentTime = LocalDateTime.now().atZone(LocaleContextHolder.getTimeZone().toZoneId()).toString(); logger.debug("🕐 getCurrentDateTime 调用 - 返回时间: {}", currentTime); return currentTime; } }