feat: added performance statistics info when using embedded LLM

This commit is contained in:
Xiaohan-Tian
2026-05-14 19:05:13 -07:00
parent 98c2b97413
commit eb1c7bd2fc
8 changed files with 58 additions and 8 deletions
+3 -2
View File
@@ -110,6 +110,7 @@ export class AgentCore {
let assistantTextContent = '';
const accumulatedToolCalls: ToolCall[] = [];
let finishReason = 'stop';
let performanceInfo: StreamChunk['performanceInfo'];
for await (const chunk of this.llmProvider.generateStream(conversationHistory, systemPrompt, tools)) {
if (chunk.type === 'text') {
@@ -120,6 +121,7 @@ export class AgentCore {
accumulatedToolCalls.push(chunk.toolCall);
} else if (chunk.type === 'done') {
finishReason = chunk.finishReason ?? 'stop';
performanceInfo = chunk.performanceInfo;
}
}
@@ -163,10 +165,9 @@ export class AgentCore {
// LLM finished with text response (stop reason)
this.agentState.updateMessage(this.currentAssistantMessageId, assistantTextContent);
continueLoop = false;
yield { type: 'done', content: '', finishReason, performanceInfo };
}
}
yield { type: 'done', content: '', finishReason: 'stop' };
} finally {
this.currentUserMessageId = null;
this.currentAssistantMessageId = null;
+9 -1
View File
@@ -296,6 +296,14 @@ export class LocalBrowserLLMProvider implements LLMProvider {
yield { type: 'tool_call', content: '', toolCall };
}
yield { type: 'done', content: '', finishReason };
yield {
type: 'done',
content: '',
finishReason,
performanceInfo: {
prefillTps,
generationTps,
},
};
}
}
+7 -1
View File
@@ -4,10 +4,16 @@
import type { ToolCall } from '../core/AgentState';
export interface PerformanceInfo {
prefillTps?: number;
generationTps?: number;
}
export interface StreamChunk {
type: 'text' | 'tool_call' | 'tool_result' | 'done';
content: string;
toolCall?: ToolCall;
toolResult?: { name: string; success: boolean; result: string };
finishReason?: string; // 'stop' | 'tool_calls' — present on 'done' chunks
performanceInfo?: PerformanceInfo;
finishReason?: string;
}