fix(agent): prevent passing asset IDs to read_thread and improve tool error messages

This commit is contained in:
yiling
2026-07-29 15:18:30 +08:00
parent 1c7a87488b
commit d267c7de98
2 changed files with 29 additions and 2 deletions
+13 -2
View File
@@ -3,7 +3,10 @@ import { Type } from '@sinclair/typebox'
import { type AgentTool } from '@earendil-works/pi-agent-core'
const readThreadSchema = Type.Object({
threadId: Type.String({ description: 'The comment ID of the thread root' }),
threadId: Type.String({
description:
'The root comment ID of a thread (e.g. from [Thread ID: ...]). Do NOT pass an asset ID or project ID.',
}),
})
export const createReadThreadTool = (): AgentTool<
@@ -21,8 +24,16 @@ export const createReadThreadTool = (): AgentTool<
})
if (!rootComment) {
const isAsset = await prisma.asset.findUnique({
where: { id: params.threadId },
select: { id: true },
})
const errorText = isAsset
? `ID "${params.threadId}" is an Asset ID, not a Comment Thread ID. Do not pass asset IDs to read_thread.`
: `Comment thread with ID "${params.threadId}" not found.`
return {
content: [{ type: 'text', text: `Comment thread with ID "${params.threadId}" not found.` }],
content: [{ type: 'text', text: errorText }],
details: { threadId: params.threadId },
}
}