feat: 逻辑优化

This commit is contained in:
digua
2025-12-06 02:20:11 +08:00
parent 5618bf7be4
commit cd2dc0b8db
12 changed files with 361 additions and 292 deletions
+11 -1
View File
@@ -147,7 +147,7 @@ function getLockedPromptSection(chatType: 'group' | 'private'): string {
`
: `成员查询策略:
- 当用户提到特定群成员(如"张三说过什么"、"小明的发言"等)时,应先调用 get_group_members 获取成员列表
- 群成员有三种名称:accountNameQQ原始昵称)、groupNickname(群昵称)、aliases(用户自定义别名)
- 群成员有三种名称:accountName(原始昵称)、groupNickname(群昵称)、aliases(用户自定义别名)
- 通过 get_group_members 的 search 参数可以模糊搜索这三种名称
- 找到成员后,使用其 id 字段作为 search_messages 的 sender_id 参数来获取该成员的发言
`
@@ -553,6 +553,16 @@ export class Agent {
let toolParams: Record<string, unknown> | undefined
try {
toolParams = JSON.parse(tc.function.arguments || '{}')
// 对于消息获取类工具,用用户配置的 limit 覆盖 LLM 传递的值(保持显示一致)
const toolsWithLimit = ['search_messages', 'get_recent_messages', 'get_conversation_between']
if (this.context.maxMessagesLimit && toolsWithLimit.includes(tc.function.name)) {
toolParams = {
...toolParams,
limit: this.context.maxMessagesLimit, // 用户配置优先
}
}
// 对于搜索类工具,添加时间范围信息
if (
this.context.timeFilter &&
+13 -6
View File
@@ -54,8 +54,8 @@ async function searchMessagesExecutor(
context: ToolContext
): Promise<unknown> {
const { sessionId, timeFilter: contextTimeFilter, maxMessagesLimit } = context
// 优先使用 LLM 指定的 limit,其次使用用户配置,最后使用默认值 200,上限 5000
const limit = Math.min(params.limit || maxMessagesLimit || 200, 5000)
// 用户配置优先:如果用户设置了 maxMessagesLimit,使用它;否则使用 LLM 指定的值或默认值 200,上限 5000
const limit = Math.min(maxMessagesLimit || params.limit || 200, 5000)
// 构建时间过滤器:优先使用 LLM 指定的年/月,否则使用 context 中的
let effectiveTimeFilter = contextTimeFilter
@@ -144,8 +144,15 @@ async function getRecentMessagesExecutor(
context: ToolContext
): Promise<unknown> {
const { sessionId, timeFilter: contextTimeFilter, maxMessagesLimit } = context
// 优先使用 LLM 指定的 limit,其次使用用户配置,最后使用默认值 100
const limit = params.limit || maxMessagesLimit || 100
// 用户配置优先:如果用户设置了 maxMessagesLimit,使用它;否则使用 LLM 指定的值或默认值 100
const limit = maxMessagesLimit || params.limit || 100
console.log('[getRecentMessages] 参数调试:', {
'params.limit': params.limit,
'context.maxMessagesLimit': maxMessagesLimit,
'计算后的 limit': limit,
'context 完整内容': JSON.stringify(context),
})
// 构建时间过滤器:优先使用 LLM 指定的年/月
let effectiveTimeFilter = contextTimeFilter
@@ -495,8 +502,8 @@ async function getConversationBetweenExecutor(
context: ToolContext
): Promise<unknown> {
const { sessionId, timeFilter: contextTimeFilter, maxMessagesLimit } = context
// 优先使用 LLM 指定的 limit,其次使用用户配置,最后使用默认值 100
const limit = params.limit || maxMessagesLimit || 100
// 用户配置优先:如果用户设置了 maxMessagesLimit,使用它;否则使用 LLM 指定的值或默认值 100
const limit = maxMessagesLimit || params.limit || 100
// 构建时间过滤器
let effectiveTimeFilter = contextTimeFilter
+7 -5
View File
@@ -476,11 +476,13 @@ export function registerAIHandlers({ win }: IpcContext): void {
if (abortController.signal.aborted) {
return
}
aiLogger.debug('IPC', `Agent chunk: ${requestId}`, {
type: chunk.type,
contentLength: chunk.content?.length,
toolName: chunk.toolName,
})
// 减少日志噪音:只在工具调用时记录
if (chunk.type === 'tool_start' || chunk.type === 'tool_result') {
aiLogger.debug('IPC', `Agent chunk: ${requestId}`, {
type: chunk.type,
toolName: chunk.toolName,
})
}
win.webContents.send('agent:streamChunk', { requestId, chunk })
})