fix(formatting)
This commit is contained in:
parent
7b127e5635
commit
c3e845e0e2
6 changed files with 77 additions and 40 deletions
|
|
@ -185,31 +185,43 @@ const AgentActionDisplay = ({
|
||||||
{event.details.currentTask && (
|
{event.details.currentTask && (
|
||||||
<div className="flex space-x-1">
|
<div className="flex space-x-1">
|
||||||
<span className="font-bold">Current Task:</span>
|
<span className="font-bold">Current Task:</span>
|
||||||
<span className="italic">"{event.details.currentTask}"</span>
|
<span className="italic">
|
||||||
</div>
|
"{event.details.currentTask}"
|
||||||
)}
|
</span>
|
||||||
{event.details.taskIndex !== undefined && event.details.totalTasks !== undefined && (
|
|
||||||
<div className="flex space-x-1">
|
|
||||||
<span className="font-bold">Progress:</span>
|
|
||||||
<span>Task {event.details.taskIndex} of {event.details.totalTasks}</span>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{event.details.taskIndex !== undefined &&
|
||||||
|
event.details.totalTasks !== undefined && (
|
||||||
|
<div className="flex space-x-1">
|
||||||
|
<span className="font-bold">Progress:</span>
|
||||||
|
<span>
|
||||||
|
Task {event.details.taskIndex} of{' '}
|
||||||
|
{event.details.totalTasks}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{event.details.completedTask && (
|
{event.details.completedTask && (
|
||||||
<div className="flex space-x-1">
|
<div className="flex space-x-1">
|
||||||
<span className="font-bold">Completed:</span>
|
<span className="font-bold">Completed:</span>
|
||||||
<span className="italic">"{event.details.completedTask}"</span>
|
<span className="italic">
|
||||||
|
"{event.details.completedTask}"
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{event.details.nextTask && (
|
{event.details.nextTask && (
|
||||||
<div className="flex space-x-1">
|
<div className="flex space-x-1">
|
||||||
<span className="font-bold">Next:</span>
|
<span className="font-bold">Next:</span>
|
||||||
<span className="italic">"{event.details.nextTask}"</span>
|
<span className="italic">
|
||||||
|
"{event.details.nextTask}"
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{event.details.currentSearchFocus && (
|
{event.details.currentSearchFocus && (
|
||||||
<div className="flex space-x-1">
|
<div className="flex space-x-1">
|
||||||
<span className="font-bold">Search Focus:</span>
|
<span className="font-bold">Search Focus:</span>
|
||||||
<span className="italic">"{event.details.currentSearchFocus}"</span>
|
<span className="italic">
|
||||||
|
"{event.details.currentSearchFocus}"
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@ import {
|
||||||
additionalWebSearchPrompt,
|
additionalWebSearchPrompt,
|
||||||
decideNextActionPrompt,
|
decideNextActionPrompt,
|
||||||
} from '../prompts/analyzer';
|
} from '../prompts/analyzer';
|
||||||
import { removeThinkingBlocks, removeThinkingBlocksFromMessages } from '../utils/contentUtils';
|
import {
|
||||||
|
removeThinkingBlocks,
|
||||||
|
removeThinkingBlocksFromMessages,
|
||||||
|
} from '../utils/contentUtils';
|
||||||
|
|
||||||
export class AnalyzerAgent {
|
export class AnalyzerAgent {
|
||||||
private llm: BaseChatModel;
|
private llm: BaseChatModel;
|
||||||
|
|
@ -84,7 +87,9 @@ export class AnalyzerAgent {
|
||||||
query: state.originalQuery || state.query, // Use original query for analysis context
|
query: state.originalQuery || state.query, // Use original query for analysis context
|
||||||
});
|
});
|
||||||
|
|
||||||
const thinkingBlocksRemovedMessages = removeThinkingBlocksFromMessages(state.messages);
|
const thinkingBlocksRemovedMessages = removeThinkingBlocksFromMessages(
|
||||||
|
state.messages,
|
||||||
|
);
|
||||||
|
|
||||||
const nextActionResponse = await this.llm.invoke(
|
const nextActionResponse = await this.llm.invoke(
|
||||||
[...thinkingBlocksRemovedMessages, new HumanMessage(nextActionPrompt)],
|
[...thinkingBlocksRemovedMessages, new HumanMessage(nextActionPrompt)],
|
||||||
|
|
@ -118,7 +123,10 @@ export class AnalyzerAgent {
|
||||||
});
|
});
|
||||||
|
|
||||||
const stream = await this.llm.stream(
|
const stream = await this.llm.stream(
|
||||||
[...removeThinkingBlocksFromMessages(state.messages), new SystemMessage(moreUserInfoPrompt)],
|
[
|
||||||
|
...removeThinkingBlocksFromMessages(state.messages),
|
||||||
|
new SystemMessage(moreUserInfoPrompt),
|
||||||
|
],
|
||||||
{ signal: this.signal },
|
{ signal: this.signal },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -175,7 +183,10 @@ export class AnalyzerAgent {
|
||||||
});
|
});
|
||||||
|
|
||||||
const moreInfoResponse = await this.llm.invoke(
|
const moreInfoResponse = await this.llm.invoke(
|
||||||
[...removeThinkingBlocksFromMessages(state.messages), new HumanMessage(moreInfoPrompt)],
|
[
|
||||||
|
...removeThinkingBlocksFromMessages(state.messages),
|
||||||
|
new HumanMessage(moreInfoPrompt),
|
||||||
|
],
|
||||||
{ signal: this.signal },
|
{ signal: this.signal },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -210,7 +221,10 @@ export class AnalyzerAgent {
|
||||||
],
|
],
|
||||||
query: moreInfoQuestion, // Use the refined question for TaskManager to analyze
|
query: moreInfoQuestion, // Use the refined question for TaskManager to analyze
|
||||||
searchInstructions: moreInfoQuestion,
|
searchInstructions: moreInfoQuestion,
|
||||||
searchInstructionHistory: [...(state.searchInstructionHistory || []), moreInfoQuestion],
|
searchInstructionHistory: [
|
||||||
|
...(state.searchInstructionHistory || []),
|
||||||
|
moreInfoQuestion,
|
||||||
|
],
|
||||||
fullAnalysisAttempts: 1,
|
fullAnalysisAttempts: 1,
|
||||||
originalQuery: state.originalQuery || state.query, // Preserve the original user query
|
originalQuery: state.originalQuery || state.query, // Preserve the original user query
|
||||||
// Reset task list so TaskManager can break down the search requirements again
|
// Reset task list so TaskManager can break down the search requirements again
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,11 @@ ${doc.metadata?.url.toLowerCase().includes('file') ? '' : '\n<url>' + doc.metada
|
||||||
);
|
);
|
||||||
|
|
||||||
const stream = await this.llm.stream(
|
const stream = await this.llm.stream(
|
||||||
[...removeThinkingBlocksFromMessages(state.messages), new SystemMessage(synthesisPrompt), new HumanMessage(state.originalQuery || state.query)],
|
[
|
||||||
|
...removeThinkingBlocksFromMessages(state.messages),
|
||||||
|
new SystemMessage(synthesisPrompt),
|
||||||
|
new HumanMessage(state.originalQuery || state.query),
|
||||||
|
],
|
||||||
{ signal: this.signal },
|
{ signal: this.signal },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -115,25 +115,26 @@ export class TaskManagerAgent {
|
||||||
query: state.query,
|
query: state.query,
|
||||||
});
|
});
|
||||||
|
|
||||||
const taskBreakdownResult = await this.llm.invoke(
|
const taskBreakdownResult = await this.llm.invoke([prompt], {
|
||||||
[prompt],
|
signal: this.signal,
|
||||||
{ signal: this.signal },
|
});
|
||||||
);
|
|
||||||
|
|
||||||
// Parse the response to extract tasks
|
// Parse the response to extract tasks
|
||||||
const responseContent = taskBreakdownResult.content as string;
|
const responseContent = taskBreakdownResult.content as string;
|
||||||
const taskLines = responseContent
|
const taskLines = responseContent
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(line => line.trim().startsWith('TASK:'))
|
.filter((line) => line.trim().startsWith('TASK:'))
|
||||||
.map(line => line.replace('TASK:', '').trim())
|
.map((line) => line.replace('TASK:', '').trim())
|
||||||
.filter(task => task.length > 0);
|
.filter((task) => task.length > 0);
|
||||||
|
|
||||||
if (taskLines.length === 0) {
|
if (taskLines.length === 0) {
|
||||||
// Fallback: if no tasks found, use the original query
|
// Fallback: if no tasks found, use the original query
|
||||||
taskLines.push(state.query);
|
taskLines.push(state.query);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Task breakdown completed: ${taskLines.length} tasks identified`);
|
console.log(
|
||||||
|
`Task breakdown completed: ${taskLines.length} tasks identified`,
|
||||||
|
);
|
||||||
taskLines.forEach((task, index) => {
|
taskLines.forEach((task, index) => {
|
||||||
console.log(`Task ${index + 1}: ${task}`);
|
console.log(`Task ${index + 1}: ${task}`);
|
||||||
});
|
});
|
||||||
|
|
@ -152,9 +153,10 @@ export class TaskManagerAgent {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const responseMessage = taskLines.length === 1
|
const responseMessage =
|
||||||
? 'Question is already focused and ready for processing'
|
taskLines.length === 1
|
||||||
: `Question broken down into ${taskLines.length} focused tasks for parallel processing`;
|
? 'Question is already focused and ready for processing'
|
||||||
|
: `Question broken down into ${taskLines.length} focused tasks for parallel processing`;
|
||||||
|
|
||||||
return new Command({
|
return new Command({
|
||||||
goto: 'web_search', // Next step would typically be web search for each task
|
goto: 'web_search', // Next step would typically be web search for each task
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,14 @@ export class WebSearchAgent {
|
||||||
setTemperature(this.llm, 0); // Set temperature to 0 for deterministic output
|
setTemperature(this.llm, 0); // Set temperature to 0 for deterministic output
|
||||||
|
|
||||||
// Determine current task to process
|
// Determine current task to process
|
||||||
const currentTask = state.tasks && state.tasks.length > 0
|
const currentTask =
|
||||||
? state.tasks[state.currentTaskIndex || 0]
|
state.tasks && state.tasks.length > 0
|
||||||
: state.query;
|
? state.tasks[state.currentTaskIndex || 0]
|
||||||
|
: state.query;
|
||||||
|
|
||||||
console.log(`Processing task ${(state.currentTaskIndex || 0) + 1} of ${state.tasks?.length || 1}: "${currentTask}"`);
|
console.log(
|
||||||
|
`Processing task ${(state.currentTaskIndex || 0) + 1} of ${state.tasks?.length || 1}: "${currentTask}"`,
|
||||||
|
);
|
||||||
|
|
||||||
// Emit preparing web search event
|
// Emit preparing web search event
|
||||||
this.emitter.emit('agent_action', {
|
this.emitter.emit('agent_action', {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import {
|
import {
|
||||||
BaseMessage,
|
BaseMessage,
|
||||||
AIMessage,
|
AIMessage,
|
||||||
HumanMessage,
|
HumanMessage,
|
||||||
SystemMessage
|
SystemMessage,
|
||||||
} from '@langchain/core/messages';
|
} from '@langchain/core/messages';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,15 +21,17 @@ export const removeThinkingBlocks = (text: string): string => {
|
||||||
* @param messages Array of BaseMessage objects
|
* @param messages Array of BaseMessage objects
|
||||||
* @returns New array with thinking blocks removed from each message's content
|
* @returns New array with thinking blocks removed from each message's content
|
||||||
*/
|
*/
|
||||||
export const removeThinkingBlocksFromMessages = (messages: BaseMessage[]): BaseMessage[] => {
|
export const removeThinkingBlocksFromMessages = (
|
||||||
return messages.map(message => {
|
messages: BaseMessage[],
|
||||||
|
): BaseMessage[] => {
|
||||||
|
return messages.map((message) => {
|
||||||
// Only process string content, leave complex content as-is
|
// Only process string content, leave complex content as-is
|
||||||
if (typeof message.content !== 'string') {
|
if (typeof message.content !== 'string') {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanedContent = removeThinkingBlocks(message.content);
|
const cleanedContent = removeThinkingBlocks(message.content);
|
||||||
|
|
||||||
// Create new instance of the same message type with cleaned content
|
// Create new instance of the same message type with cleaned content
|
||||||
if (message instanceof AIMessage) {
|
if (message instanceof AIMessage) {
|
||||||
return new AIMessage(cleanedContent);
|
return new AIMessage(cleanedContent);
|
||||||
|
|
@ -43,4 +45,4 @@ export const removeThinkingBlocksFromMessages = (messages: BaseMessage[]): BaseM
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue