mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
feat: Add option to returnIntermediateSteps
for AI agents (#8113)
## Summary ![CleanShot 2023-12-21 at 08 30 16](https://github.com/n8n-io/n8n/assets/12657221/66b0de47-80cd-41f9-940e-6cacc2c940a9) Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
This commit is contained in:
parent
6580b927b3
commit
7806a65229
|
@ -67,6 +67,13 @@ export const conversationalAgentProperties: INodeProperties[] = [
|
|||
default: 10,
|
||||
description: 'The maximum number of iterations the agent will run before stopping',
|
||||
},
|
||||
{
|
||||
displayName: 'Return Intermediate Steps',
|
||||
name: 'returnIntermediateSteps',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether or not the output should include intermediate steps the agent took',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
|
@ -41,6 +41,7 @@ export async function conversationalAgentExecute(
|
|||
systemMessage?: string;
|
||||
humanMessage?: string;
|
||||
maxIterations?: number;
|
||||
returnIntermediateSteps?: boolean;
|
||||
};
|
||||
|
||||
const agentExecutor = await initializeAgentExecutorWithOptions(tools, model, {
|
||||
|
@ -50,6 +51,7 @@ export async function conversationalAgentExecute(
|
|||
// memory option, but the memoryKey set on it must be "chat_history".
|
||||
agentType: 'chat-conversational-react-description',
|
||||
memory,
|
||||
returnIntermediateSteps: options?.returnIntermediateSteps === true,
|
||||
maxIterations: options.maxIterations ?? 10,
|
||||
agentArgs: {
|
||||
systemMessage: options.systemMessage,
|
||||
|
|
|
@ -57,6 +57,13 @@ export const openAiFunctionsAgentProperties: INodeProperties[] = [
|
|||
default: 10,
|
||||
description: 'The maximum number of iterations the agent will run before stopping',
|
||||
},
|
||||
{
|
||||
displayName: 'Return Intermediate Steps',
|
||||
name: 'returnIntermediateSteps',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether or not the output should include intermediate steps the agent took',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
|
@ -40,6 +40,7 @@ export async function openAiFunctionsAgentExecute(
|
|||
const options = this.getNodeParameter('options', 0, {}) as {
|
||||
systemMessage?: string;
|
||||
maxIterations?: number;
|
||||
returnIntermediateSteps?: boolean;
|
||||
};
|
||||
|
||||
const agentConfig: AgentExecutorInput = {
|
||||
|
@ -49,6 +50,7 @@ export async function openAiFunctionsAgentExecute(
|
|||
}),
|
||||
tools,
|
||||
maxIterations: options.maxIterations ?? 10,
|
||||
returnIntermediateSteps: options?.returnIntermediateSteps === true,
|
||||
memory:
|
||||
memory ??
|
||||
new BufferMemory({
|
||||
|
|
|
@ -82,6 +82,13 @@ export const reActAgentAgentProperties: INodeProperties[] = [
|
|||
rows: 6,
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Return Intermediate Steps',
|
||||
name: 'returnIntermediateSteps',
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
description: 'Whether or not the output should include intermediate steps the agent took',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
|
@ -34,6 +34,7 @@ export async function reActAgentAgentExecute(
|
|||
suffix?: string;
|
||||
suffixChat?: string;
|
||||
humanMessageTemplate?: string;
|
||||
returnIntermediateSteps?: boolean;
|
||||
};
|
||||
let agent: ChatAgent | ZeroShotAgent;
|
||||
|
||||
|
@ -50,7 +51,11 @@ export async function reActAgentAgentExecute(
|
|||
});
|
||||
}
|
||||
|
||||
const agentExecutor = AgentExecutor.fromAgentAndTools({ agent, tools });
|
||||
const agentExecutor = AgentExecutor.fromAgentAndTools({
|
||||
agent,
|
||||
tools,
|
||||
returnIntermediateSteps: options?.returnIntermediateSteps === true,
|
||||
});
|
||||
|
||||
const returnData: INodeExecutionData[] = [];
|
||||
|
||||
|
|
|
@ -43,8 +43,13 @@ export class ToolWikipedia implements INodeType {
|
|||
};
|
||||
|
||||
async supplyData(this: IExecuteFunctions): Promise<SupplyData> {
|
||||
const WikiTool = new WikipediaQueryRun();
|
||||
|
||||
WikiTool.description =
|
||||
'A tool for interacting with and fetching data from the Wikipedia API. The input should always be a string query.';
|
||||
|
||||
return {
|
||||
response: logWrapper(new WikipediaQueryRun(), this),
|
||||
response: logWrapper(WikiTool, this),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue