🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: recognize image-only model completions (#17695)
YuTengjing63750e193669
diff --git a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.test.ts b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.test.tsindex cf3510a1fd1..03860ae3f27 100644--- a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.test.ts+++ b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.test.ts@@ -287,4 +287,36 @@ describe('ServerCallLlmAttempt', () => {}),);});++ it('accepts an image-only multimodal completion as non-empty', async () => {+ const blobStore: BlobStore = {+ persistBase64: vi.fn().mockResolvedValue({+ fileId: 'file-1',+ key: 'files/generations/image.png',+ url: 'https://files.example/image.png',+ }),+ resolveUrl: vi.fn(),+ };+ const { attempt } = createAttempt(async ({ callback }) => {+ await callback?.onContentPart?.({+ content: 'BASE64_IMAGE',+ mimeType: 'image/png',+ partType: 'image',+ });+ await callback?.onCompletion?.({+ finishReason: 'stop',+ text: '',+ usage: { outputImageTokens: 1120, totalOutputTokens: 1120 },+ });+ }, blobStore);++ await expect(attempt.execute()).resolves.toBeUndefined();+ expect(attempt.snapshot()).toEqual(+ expect.objectContaining({+ content: '',+ contentParts: [{ image: 'https://files.example/image.png', type: 'image' }],+ hasContentImages: true,+ }),+ );+ });});diff --git a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.ts b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.tsindex a38afaaa6f7..688a1da088a 100644--- a/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.ts+++ b/apps/server/src/modules/AgentRuntime/adapters/serverCallLlmAttempt.ts@@ -278,11 +278,13 @@ export class ServerCallLlmAttempt {}private async assertNonEmptyCompletion() {+ const imageCount = this.getOutputImageCount();+if (isEmptyModelCompletion({content: this.streamSink.content,hasGrounding: !!this.grounding,- imageCount: this.imageList.length,+ imageCount,outputTokens: this.usage?.totalOutputTokens,reasoning: this.streamSink.thinkingContent,toolCallCount: this.toolsCalling.length + this.toolCalls.length,@@ -300,7 +302,7 @@ export class ServerCallLlmAttempt {contentLength: this.streamSink.content.length,cost: this.usage?.cost,finishReason: this.finishReason,- imageCount: this.imageList.length,+ imageCount,maxAttempts: this.maxAttempts,model: this.model,outputTokens: this.usage?.totalOutputTokens,@@ -311,6 +313,19 @@ export class ServerCallLlmAttempt {}}+ /**+ * Native multimodal responses store generated images in contentParts rather+ * than the legacy imageList. Count both paths so image-only completions are+ * not mistaken for empty provider responses.+ */+ private getOutputImageCount() {+ const contentPartImageCount = this.streamSink.contentParts.filter(+ (part) => part.type === 'image',+ ).length;++ return this.imageList.length + contentPartImageCount;+ }+private logResult() {log('[%s] finish model-runtime calling | content: %d chars | reasoning: %d chars | tools: %d | usage: %s',