优化了agent
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { tool } from "@langchain/core/tools"
|
||||
import { z } from "zod"
|
||||
import { Solar } from "lunar-javascript"
|
||||
import logger from "../../../../utils/logger.js"
|
||||
|
||||
/**
|
||||
* 日历工具
|
||||
@@ -75,7 +76,7 @@ async function getBeijingNow() {
|
||||
success: true
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`获取网络时间失败,使用本机时间: ${error.message}`)
|
||||
logger.warn(`获取网络时间失败,使用本机时间: ${error.message}`)
|
||||
const now = new Date()
|
||||
return {
|
||||
...getBeijingDateParts(now),
|
||||
@@ -118,7 +119,7 @@ export const getCalendarInfoTool = tool(
|
||||
const solar = Solar.fromYmd(now.year, now.month, now.day)
|
||||
return JSON.stringify({ now, ...buildDayInfo(solar) }, null, 2)
|
||||
} catch (error) {
|
||||
console.error("Error in calendar tool:", error)
|
||||
logger.error("Error in calendar tool:", error)
|
||||
return JSON.stringify({ error: error.message }, null, 2)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { tool } from "langchain"
|
||||
import lunarLib from "lunar-javascript"
|
||||
import { tool } from "@langchain/core/tools";
|
||||
import { z } from "zod";
|
||||
import lunarLib from "lunar-javascript";
|
||||
const { Solar, HolidayUtil } = lunarLib
|
||||
|
||||
/**
|
||||
@@ -36,17 +37,8 @@ export const getYearHolidaysTool = tool(
|
||||
{
|
||||
name: "get_year_holidays",
|
||||
description: "查询给定年份节日所在日期列表,包括法定节假日安排(含调休)与传统节日",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
year: {
|
||||
type: "number",
|
||||
description: "年份",
|
||||
minimum: 1900,
|
||||
maximum: 2100
|
||||
}
|
||||
},
|
||||
required: ["year"]
|
||||
}
|
||||
schema: z.object({
|
||||
year: z.number().int().min(1900).max(2100).describe("年份")
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user