2025-06-09 23:00:25 -06:00
|
|
|
import { Embeddings } from '@langchain/core/embeddings';
|
|
|
|
|
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
2025-07-29 10:18:11 -06:00
|
|
|
import { BaseMessage } from '@langchain/core/messages';
|
2025-06-09 23:00:25 -06:00
|
|
|
import { EventEmitter } from 'events';
|
2025-07-29 10:18:11 -06:00
|
|
|
import { SimplifiedAgent } from './simplifiedAgent';
|
2025-06-09 23:00:25 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Agent Search class implementing LangGraph Supervisor pattern
|
|
|
|
|
*/
|
|
|
|
|
export class AgentSearch {
|
2025-06-19 12:49:37 -06:00
|
|
|
private emitter: EventEmitter;
|
2025-06-28 14:48:08 -06:00
|
|
|
private focusMode: string;
|
2025-06-09 23:00:25 -06:00
|
|
|
|
2025-07-29 10:18:11 -06:00
|
|
|
// Simplified agent experimental implementation
|
|
|
|
|
private simplifiedAgent: SimplifiedAgent;
|
|
|
|
|
|
2025-06-09 23:00:25 -06:00
|
|
|
constructor(
|
|
|
|
|
llm: BaseChatModel,
|
|
|
|
|
embeddings: Embeddings,
|
|
|
|
|
emitter: EventEmitter,
|
|
|
|
|
systemInstructions: string = '',
|
|
|
|
|
personaInstructions: string = '',
|
|
|
|
|
signal: AbortSignal,
|
2025-06-28 14:48:08 -06:00
|
|
|
focusMode: string = 'webSearch',
|
2025-06-09 23:00:25 -06:00
|
|
|
) {
|
2025-06-19 12:49:37 -06:00
|
|
|
this.emitter = emitter;
|
2025-06-28 14:48:08 -06:00
|
|
|
this.focusMode = focusMode;
|
2025-06-09 23:00:25 -06:00
|
|
|
|
2025-07-29 10:18:11 -06:00
|
|
|
// Initialize simplified agent (experimental)
|
|
|
|
|
this.simplifiedAgent = new SimplifiedAgent(
|
2025-06-21 16:12:19 -06:00
|
|
|
llm,
|
2025-06-22 13:35:01 -06:00
|
|
|
embeddings,
|
2025-06-15 11:53:00 -06:00
|
|
|
emitter,
|
|
|
|
|
systemInstructions,
|
|
|
|
|
personaInstructions,
|
2025-06-17 00:20:05 -06:00
|
|
|
signal,
|
2025-06-29 13:59:52 -06:00
|
|
|
);
|
2025-06-09 23:00:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-29 10:18:11 -06:00
|
|
|
* Execute the simplified agent search workflow (experimental)
|
2025-06-09 23:00:25 -06:00
|
|
|
*/
|
2025-07-29 10:18:11 -06:00
|
|
|
async searchAndAnswerSimplified(
|
|
|
|
|
query: string,
|
|
|
|
|
history: BaseMessage[] = [],
|
|
|
|
|
fileIds: string[] = [],
|
|
|
|
|
): Promise<void> {
|
|
|
|
|
console.log('AgentSearch: Using simplified agent implementation');
|
|
|
|
|
|
|
|
|
|
// Emit agent action to indicate simplified agent usage
|
|
|
|
|
this.emitter.emit(
|
|
|
|
|
'data',
|
|
|
|
|
JSON.stringify({
|
|
|
|
|
type: 'agent_action',
|
|
|
|
|
data: {
|
|
|
|
|
action: 'agent_implementation_selection',
|
|
|
|
|
message: 'Using simplified agent implementation (experimental)',
|
|
|
|
|
details: `Focus mode: ${this.focusMode}, Files: ${fileIds.length}`,
|
2025-06-17 00:20:05 -06:00
|
|
|
},
|
2025-07-29 10:18:11 -06:00
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2025-08-02 12:52:14 -06:00
|
|
|
// Delegate to simplified agent with focus mode
|
|
|
|
|
await this.simplifiedAgent.searchAndAnswer(
|
|
|
|
|
query,
|
|
|
|
|
history,
|
|
|
|
|
fileIds,
|
|
|
|
|
this.focusMode,
|
|
|
|
|
);
|
2025-06-09 23:00:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the agent search workflow
|
|
|
|
|
*/
|
2025-06-28 14:48:08 -06:00
|
|
|
async searchAndAnswer(
|
2025-06-28 17:59:12 -06:00
|
|
|
query: string,
|
|
|
|
|
history: BaseMessage[] = [],
|
|
|
|
|
fileIds: string[] = [],
|
2025-06-28 14:48:08 -06:00
|
|
|
) {
|
2025-07-29 10:18:11 -06:00
|
|
|
console.log('AgentSearch: Routing to simplified agent implementation');
|
|
|
|
|
return await this.searchAndAnswerSimplified(query, history, fileIds);
|
2025-06-09 23:00:25 -06:00
|
|
|
}
|
|
|
|
|
}
|