fix(agents): use text placeholders for historical attachments to avoid token overflow
Historical images/PDFs were being re-downloaded and base64-encoded for every API call, causing 200K+ token requests. Now only the current message includes full attachment blocks; historical ones use text placeholders like "[用户上传了图片: photo.png]". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
06226a3d74
commit
f2903bd67a
|
|
@ -449,13 +449,17 @@ export class CoordinatorAgentService implements OnModuleInit {
|
|||
): Promise<ClaudeMessage[]> {
|
||||
const messages: ClaudeMessage[] = [];
|
||||
|
||||
// Convert previous messages
|
||||
// Convert previous messages (use text placeholders for historical attachments to save tokens)
|
||||
if (context.previousMessages) {
|
||||
for (const msg of context.previousMessages) {
|
||||
if (msg.attachments?.length) {
|
||||
const contentBlocks = await this.buildAttachmentBlocks(msg.attachments);
|
||||
contentBlocks.push({ type: 'text', text: msg.content });
|
||||
messages.push({ role: msg.role, content: contentBlocks });
|
||||
const placeholders = msg.attachments.map(
|
||||
(att) => `[用户上传了${att.type === 'image' ? '图片' : '文件'}: ${att.originalName}]`,
|
||||
);
|
||||
messages.push({
|
||||
role: msg.role,
|
||||
content: placeholders.join('\n') + '\n' + msg.content,
|
||||
});
|
||||
} else {
|
||||
messages.push({ role: msg.role, content: msg.content });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue