Skip to content

Commit a82dd93

Browse files
authored
Feature/add max iterations to agents (#2161)
add max iterations to agents
1 parent e7a58fc commit a82dd93

File tree

8 files changed

+80
-8
lines changed

8 files changed

+80
-8
lines changed

packages/components/nodes/agents/ConversationalAgent/ConversationalAgent.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class ConversationalAgent_Agents implements INode {
8686
type: 'Moderation',
8787
optional: true,
8888
list: true
89+
},
90+
{
91+
label: 'Max Iterations',
92+
name: 'maxIterations',
93+
type: 'number',
94+
optional: true,
95+
additionalParams: true
8996
}
9097
]
9198
this.sessionId = fields?.sessionId
@@ -176,6 +183,7 @@ const prepareAgent = async (
176183
flowObj: { sessionId?: string; chatId?: string; input?: string }
177184
) => {
178185
const model = nodeData.inputs?.model as BaseChatModel
186+
const maxIterations = nodeData.inputs?.maxIterations as string
179187
let tools = nodeData.inputs?.tools as Tool[]
180188
tools = flatten(tools)
181189
const memory = nodeData.inputs?.memory as FlowiseMemory
@@ -247,7 +255,8 @@ const prepareAgent = async (
247255
sessionId: flowObj?.sessionId,
248256
chatId: flowObj?.chatId,
249257
input: flowObj?.input,
250-
verbose: process.env.DEBUG === 'true'
258+
verbose: process.env.DEBUG === 'true',
259+
maxIterations: maxIterations ? parseFloat(maxIterations) : undefined
251260
})
252261

253262
return executor

packages/components/nodes/agents/ConversationalRetrievalAgent/ConversationalRetrievalAgent.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ class ConversationalRetrievalAgent_Agents implements INode {
7171
type: 'Moderation',
7272
optional: true,
7373
list: true
74+
},
75+
{
76+
label: 'Max Iterations',
77+
name: 'maxIterations',
78+
type: 'number',
79+
optional: true,
80+
additionalParams: true
7481
}
7582
]
7683
this.sessionId = fields?.sessionId
@@ -131,6 +138,7 @@ const prepareAgent = (nodeData: INodeData, flowObj: { sessionId?: string; chatId
131138
const model = nodeData.inputs?.model as ChatOpenAI
132139
const memory = nodeData.inputs?.memory as FlowiseMemory
133140
const systemMessage = nodeData.inputs?.systemMessage as string
141+
const maxIterations = nodeData.inputs?.maxIterations as string
134142
let tools = nodeData.inputs?.tools
135143
tools = flatten(tools)
136144
const memoryKey = memory.memoryKey ? memory.memoryKey : 'chat_history'
@@ -168,7 +176,8 @@ const prepareAgent = (nodeData: INodeData, flowObj: { sessionId?: string; chatId
168176
chatId: flowObj?.chatId,
169177
input: flowObj?.input,
170178
returnIntermediateSteps: true,
171-
verbose: process.env.DEBUG === 'true' ? true : false
179+
verbose: process.env.DEBUG === 'true' ? true : false,
180+
maxIterations: maxIterations ? parseFloat(maxIterations) : undefined
172181
})
173182

174183
return executor

packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class MRKLAgentChat_Agents implements INode {
5858
type: 'Moderation',
5959
optional: true,
6060
list: true
61+
},
62+
{
63+
label: 'Max Iterations',
64+
name: 'maxIterations',
65+
type: 'number',
66+
optional: true,
67+
additionalParams: true
6168
}
6269
]
6370
this.sessionId = fields?.sessionId
@@ -69,6 +76,7 @@ class MRKLAgentChat_Agents implements INode {
6976

7077
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string | object> {
7178
const memory = nodeData.inputs?.memory as FlowiseMemory
79+
const maxIterations = nodeData.inputs?.maxIterations as string
7280
const model = nodeData.inputs?.model as BaseChatModel
7381
let tools = nodeData.inputs?.tools as Tool[]
7482
const moderations = nodeData.inputs?.inputModeration as Moderation[]
@@ -120,7 +128,8 @@ class MRKLAgentChat_Agents implements INode {
120128
const executor = new AgentExecutor({
121129
agent,
122130
tools,
123-
verbose: process.env.DEBUG === 'true'
131+
verbose: process.env.DEBUG === 'true',
132+
maxIterations: maxIterations ? parseFloat(maxIterations) : undefined
124133
})
125134

126135
const callbacks = await additionalCallbacks(nodeData, options)

packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class MRKLAgentLLM_Agents implements INode {
5050
type: 'Moderation',
5151
optional: true,
5252
list: true
53+
},
54+
{
55+
label: 'Max Iterations',
56+
name: 'maxIterations',
57+
type: 'number',
58+
optional: true,
59+
additionalParams: true
5360
}
5461
]
5562
}
@@ -60,6 +67,7 @@ class MRKLAgentLLM_Agents implements INode {
6067

6168
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string | object> {
6269
const model = nodeData.inputs?.model as BaseLanguageModel
70+
const maxIterations = nodeData.inputs?.maxIterations as string
6371
let tools = nodeData.inputs?.tools as Tool[]
6472
const moderations = nodeData.inputs?.inputModeration as Moderation[]
6573

@@ -87,7 +95,8 @@ class MRKLAgentLLM_Agents implements INode {
8795
const executor = new AgentExecutor({
8896
agent,
8997
tools,
90-
verbose: process.env.DEBUG === 'true' ? true : false
98+
verbose: process.env.DEBUG === 'true' ? true : false,
99+
maxIterations: maxIterations ? parseFloat(maxIterations) : undefined
91100
})
92101

93102
const callbacks = await additionalCallbacks(nodeData, options)

packages/components/nodes/agents/MistralAIToolAgent/MistralAIToolAgent.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class MistralAIToolAgent_Agents implements INode {
6969
type: 'Moderation',
7070
optional: true,
7171
list: true
72+
},
73+
{
74+
label: 'Max Iterations',
75+
name: 'maxIterations',
76+
type: 'number',
77+
optional: true,
78+
additionalParams: true
7279
}
7380
]
7481
this.sessionId = fields?.sessionId
@@ -157,6 +164,7 @@ class MistralAIToolAgent_Agents implements INode {
157164
const prepareAgent = (nodeData: INodeData, flowObj: { sessionId?: string; chatId?: string; input?: string }) => {
158165
const model = nodeData.inputs?.model as ChatOpenAI
159166
const memory = nodeData.inputs?.memory as FlowiseMemory
167+
const maxIterations = nodeData.inputs?.maxIterations as string
160168
const systemMessage = nodeData.inputs?.systemMessage as string
161169
let tools = nodeData.inputs?.tools
162170
tools = flatten(tools)
@@ -194,7 +202,8 @@ const prepareAgent = (nodeData: INodeData, flowObj: { sessionId?: string; chatId
194202
sessionId: flowObj?.sessionId,
195203
chatId: flowObj?.chatId,
196204
input: flowObj?.input,
197-
verbose: process.env.DEBUG === 'true' ? true : false
205+
verbose: process.env.DEBUG === 'true' ? true : false,
206+
maxIterations: maxIterations ? parseFloat(maxIterations) : undefined
198207
})
199208

200209
return executor

packages/components/nodes/agents/OpenAIFunctionAgent/OpenAIFunctionAgent.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ class OpenAIFunctionAgent_Agents implements INode {
6868
type: 'Moderation',
6969
optional: true,
7070
list: true
71+
},
72+
{
73+
label: 'Max Iterations',
74+
name: 'maxIterations',
75+
type: 'number',
76+
optional: true,
77+
additionalParams: true
7178
}
7279
]
7380
this.sessionId = fields?.sessionId
@@ -155,6 +162,7 @@ class OpenAIFunctionAgent_Agents implements INode {
155162

156163
const prepareAgent = (nodeData: INodeData, flowObj: { sessionId?: string; chatId?: string; input?: string }) => {
157164
const model = nodeData.inputs?.model as ChatOpenAI
165+
const maxIterations = nodeData.inputs?.maxIterations as string
158166
const memory = nodeData.inputs?.memory as FlowiseMemory
159167
const systemMessage = nodeData.inputs?.systemMessage as string
160168
let tools = nodeData.inputs?.tools
@@ -193,7 +201,8 @@ const prepareAgent = (nodeData: INodeData, flowObj: { sessionId?: string; chatId
193201
sessionId: flowObj?.sessionId,
194202
chatId: flowObj?.chatId,
195203
input: flowObj?.input,
196-
verbose: process.env.DEBUG === 'true' ? true : false
204+
verbose: process.env.DEBUG === 'true' ? true : false,
205+
maxIterations: maxIterations ? parseFloat(maxIterations) : undefined
197206
})
198207

199208
return executor

packages/components/nodes/agents/OpenAIToolAgent/OpenAIToolAgent.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ class OpenAIToolAgent_Agents implements INode {
6969
type: 'Moderation',
7070
optional: true,
7171
list: true
72+
},
73+
{
74+
label: 'Max Iterations',
75+
name: 'maxIterations',
76+
type: 'number',
77+
optional: true,
78+
additionalParams: true
7279
}
7380
]
7481
this.sessionId = fields?.sessionId
@@ -156,6 +163,7 @@ class OpenAIToolAgent_Agents implements INode {
156163

157164
const prepareAgent = (nodeData: INodeData, flowObj: { sessionId?: string; chatId?: string; input?: string }) => {
158165
const model = nodeData.inputs?.model as ChatOpenAI
166+
const maxIterations = nodeData.inputs?.maxIterations as string
159167
const memory = nodeData.inputs?.memory as FlowiseMemory
160168
const systemMessage = nodeData.inputs?.systemMessage as string
161169
let tools = nodeData.inputs?.tools
@@ -192,7 +200,8 @@ const prepareAgent = (nodeData: INodeData, flowObj: { sessionId?: string; chatId
192200
sessionId: flowObj?.sessionId,
193201
chatId: flowObj?.chatId,
194202
input: flowObj?.input,
195-
verbose: process.env.DEBUG === 'true' ? true : false
203+
verbose: process.env.DEBUG === 'true' ? true : false,
204+
maxIterations: maxIterations ? parseFloat(maxIterations) : undefined
196205
})
197206

198207
return executor

packages/components/nodes/agents/XMLAgent/XMLAgent.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ class XMLAgent_Agents implements INode {
9393
type: 'Moderation',
9494
optional: true,
9595
list: true
96+
},
97+
{
98+
label: 'Max Iterations',
99+
name: 'maxIterations',
100+
type: 'number',
101+
optional: true,
102+
additionalParams: true
96103
}
97104
]
98105
this.sessionId = fields?.sessionId
@@ -179,6 +186,7 @@ class XMLAgent_Agents implements INode {
179186

180187
const prepareAgent = async (nodeData: INodeData, flowObj: { sessionId?: string; chatId?: string; input?: string }) => {
181188
const model = nodeData.inputs?.model as BaseChatModel
189+
const maxIterations = nodeData.inputs?.maxIterations as string
182190
const memory = nodeData.inputs?.memory as FlowiseMemory
183191
const systemMessage = nodeData.inputs?.systemMessage as string
184192
let tools = nodeData.inputs?.tools
@@ -233,7 +241,8 @@ const prepareAgent = async (nodeData: INodeData, flowObj: { sessionId?: string;
233241
chatId: flowObj?.chatId,
234242
input: flowObj?.input,
235243
isXML: true,
236-
verbose: process.env.DEBUG === 'true' ? true : false
244+
verbose: process.env.DEBUG === 'true' ? true : false,
245+
maxIterations: maxIterations ? parseFloat(maxIterations) : undefined
237246
})
238247

239248
return executor

0 commit comments

Comments
 (0)