Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add options to filter conversation history messages used in sequential LLM and Agent nodes #3653

Merged
14 changes: 11 additions & 3 deletions packages/components/nodes/sequentialagents/Agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ class Agent_SeqAgents implements INode {
optional: true,
default: examplePrompt
},
{
label: 'Disable Conversation History',
name: 'disableConversationHistory',
type: 'boolean',
optional: true,
description: `If set to true, the conversation history messages from the state will not be automatically included in the prompt`,
additionalParams: true
},
{
label: 'Human Prompt',
name: 'humanMessagePrompt',
Expand Down Expand Up @@ -728,16 +736,16 @@ async function agentNode(
}

// @ts-ignore
state.messages = restructureMessages(llm, state)
state.messages = nodeData.inputs?.disableConversationHistory | false? [] : restructureMessages(llm, state)

let result = await agent.invoke({ ...state, signal: abortControllerSignal.signal }, config)

if (interrupt) {
const messages = state.messages as unknown as BaseMessage[]
const lastMessage = messages[messages.length - 1]
const lastMessage = messages.length ? messages[messages.length - 1] : null

// If the last message is a tool message and is an interrupted message, format output into standard agent output
if (lastMessage._getType() === 'tool' && lastMessage.additional_kwargs?.nodeId === nodeData.id) {
if (lastMessage && lastMessage._getType() === 'tool' && lastMessage.additional_kwargs?.nodeId === nodeData.id) {
let formattedAgentResult: {
output?: string
usedTools?: IUsedTool[]
Expand Down
10 changes: 9 additions & 1 deletion packages/components/nodes/sequentialagents/LLMNode/LLMNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ class LLMNode_SeqAgents implements INode {
type: 'string',
placeholder: 'LLM'
},
{
label: 'Disable Conversation History',
name: 'disableConversationHistory',
type: 'boolean',
optional: true,
description: `If set to true, the conversation history messages from the state will not be automatically included in the prompt`,
additionalParams: true
},
{
label: 'System Prompt',
name: 'systemMessagePrompt',
Expand Down Expand Up @@ -535,7 +543,7 @@ async function agentNode(
}

// @ts-ignore
state.messages = restructureMessages(llm, state)
state.messages = nodeData.inputs?.disableConversationHistory | false ? [] : restructureMessages(llm, state)
jeanibarz marked this conversation as resolved.
Show resolved Hide resolved

let result: AIMessageChunk | ICommonObject = await agent.invoke({ ...state, signal: abortControllerSignal.signal }, config)

Expand Down