fix(driveragent): prevent duplicate thinking/output markers during token streaming and mark transitions
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartagent',
|
||||
version: '1.5.3',
|
||||
version: '1.5.4',
|
||||
description: 'an agentic framework built on top of @push.rocks/smartai'
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ export class DriverAgent {
|
||||
private messageHistory: plugins.smartai.ChatMessage[] = [];
|
||||
private tools: Map<string, BaseToolWrapper> = new Map();
|
||||
private onToken?: (token: string) => void;
|
||||
private isInThinkingMode = false; // Track thinking/content state for markers
|
||||
|
||||
constructor(
|
||||
provider: plugins.smartai.MultiModalModel,
|
||||
@@ -494,14 +495,27 @@ Your complete output here
|
||||
// Pass onToken callback through onChunk for streaming with thinking markers
|
||||
this.onToken ? (chunk: any) => {
|
||||
if (chunk.thinking && this.onToken) {
|
||||
this.onToken(`[THINKING] ${chunk.thinking}`);
|
||||
// Add marker only when transitioning INTO thinking mode
|
||||
if (!this.isInThinkingMode) {
|
||||
this.onToken('\n[THINKING] ');
|
||||
this.isInThinkingMode = true;
|
||||
}
|
||||
this.onToken(chunk.thinking);
|
||||
}
|
||||
if (chunk.content && this.onToken) {
|
||||
// Add marker when transitioning OUT of thinking mode
|
||||
if (this.isInThinkingMode) {
|
||||
this.onToken('\n[OUTPUT] ');
|
||||
this.isInThinkingMode = false;
|
||||
}
|
||||
this.onToken(chunk.content);
|
||||
}
|
||||
} : undefined
|
||||
);
|
||||
|
||||
// Reset thinking state after response completes
|
||||
this.isInThinkingMode = false;
|
||||
|
||||
// Add assistant response to history
|
||||
const historyMessage: plugins.smartai.ChatMessage = {
|
||||
role: 'assistant',
|
||||
@@ -581,14 +595,27 @@ Your complete output here
|
||||
// Pass onToken callback through onChunk for streaming with thinking markers
|
||||
this.onToken ? (chunk: any) => {
|
||||
if (chunk.thinking && this.onToken) {
|
||||
this.onToken(`[THINKING] ${chunk.thinking}`);
|
||||
// Add marker only when transitioning INTO thinking mode
|
||||
if (!this.isInThinkingMode) {
|
||||
this.onToken('\n[THINKING] ');
|
||||
this.isInThinkingMode = true;
|
||||
}
|
||||
this.onToken(chunk.thinking);
|
||||
}
|
||||
if (chunk.content && this.onToken) {
|
||||
// Add marker when transitioning OUT of thinking mode
|
||||
if (this.isInThinkingMode) {
|
||||
this.onToken('\n[OUTPUT] ');
|
||||
this.isInThinkingMode = false;
|
||||
}
|
||||
this.onToken(chunk.content);
|
||||
}
|
||||
} : undefined
|
||||
);
|
||||
|
||||
// Reset thinking state after response completes
|
||||
this.isInThinkingMode = false;
|
||||
|
||||
// Add assistant response to history
|
||||
this.messageHistory.push({
|
||||
role: 'assistant',
|
||||
|
||||
Reference in New Issue
Block a user