python_eval 차트 이미지를 모델이 빠뜨리면 최종 답변에 코드로 덧붙임

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-17 12:19:56 +09:00
1 parent 320b3887a2
commit b4716a4513
2 files changed
+26 -1

No files matched your search

+2 -1
View File
@@ -83,7 +83,7 @@ import { createBrowserDesktopAdvisors, type BrowserDesktopAdvisorCtx } from './b
import type { SkillsManager } from '../skills-manager';
import { selectToolsForTurn, bootAllowedTools, codeAiBlockedTools } from './tool-scope';
import { buildChatSystemPrompt, groundingResultReadingRule } from './system-prompt';
import { replyLooksEmpty, appendDroppedSearchImages } from './reply-content';
import { replyLooksEmpty, appendDroppedSearchImages, appendGeneratedChartImages } from './reply-content';
import { evaluateSearchBudget } from './search-budget';
import { decideAutoRecover, shouldForceMessagingRetry as decideMessagingRetry, shouldForceWorkshopSaveRetry, shouldForceWorkshopFileRetry, shouldForceUnverifiedSpecRetry, unverifiedSpecPrompt, shouldForceEmptyGroundingRetry as decideEmptyGroundingRetry, GROUNDING_TOOL_PATTERN } from './retry-decisions';
import { logToolSkip } from './tool-skip-log';
@@ -2500,6 +2500,7 @@ async function handleChat(
}
finalText = sanitizeFinalReply(finalText, { preflightReason: preflightReasonForTurn }) || 'Hey! How can I help?';
finalText = appendDroppedSearchImages(finalText, allToolResults);
finalText = appendGeneratedChartImages(finalText, allToolResults);
logToDaily(workspacePath, 'SmallClaw', finalText, sessionId);
if (fileOpV2Active) {
+24
View File
@@ -47,3 +47,27 @@ export function appendDroppedSearchImages(
}
return finalText;
}
const FILES_IMG_MD_G = /!\[[^\]]*\]\(\/api\/files\/[^)]+\)/g;
/**
* python_eval reports charts it saved as `![name](/api/files/name.png)` in its result, but the model
* often answers "차트는 squares_chart.png 파일로 저장되었습니다" without the link, or with a bare
* `![x](x.png)` that resolves nowhere (2026-10-17, two restarts of prompt hints did not fix it).
* Append every generated chart whose /api/files/ URL the reply does not already carry.
*/
export function appendGeneratedChartImages(
finalText: string,
toolResults: ReadonlyArray<{ name?: string; error?: boolean; result?: string }> | undefined,
): string {
if (!toolResults?.length) return finalText;
const missing: string[] = [];
for (const r of toolResults) {
if (r?.name !== 'python_eval' || r.error || !r.result) continue;
for (const md of r.result.match(FILES_IMG_MD_G) || []) {
const url = md.slice(md.indexOf('](') + 2, -1);
if (!finalText.includes(url) && !missing.includes(md)) missing.push(md);
}
}
return missing.length ? `${finalText}\n\n${missing.join('\n\n')}`.trim() : finalText;
}