@n8n/n8n-nodes-langchain
Version:

94 lines • 3.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolThink = void 0;
const tools_1 = require("@langchain/classic/tools");
const n8n_workflow_1 = require("n8n-workflow");
const ai_utilities_1 = require("@n8n/ai-utilities");
async function getTool(ctx, itemIndex) {
const node = ctx.getNode();
const { typeVersion } = node;
const name = typeVersion === 1 ? 'thinking_tool' : (0, n8n_workflow_1.nodeNameToToolName)(node);
const description = ctx.getNodeParameter('description', itemIndex);
return new tools_1.DynamicTool({
name,
description,
func: async (subject) => {
return subject;
},
});
}
const defaultToolDescription = 'Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.';
class ToolThink {
constructor() {
this.description = {
displayName: 'Think Tool',
name: 'toolThink',
icon: 'node:think-tool',
iconColor: 'black',
group: ['transform'],
version: [1, 1.1],
description: 'Invite the AI agent to do some thinking',
defaults: {
name: 'Think',
},
codex: {
categories: ['AI'],
subcategories: {
AI: ['Tools'],
Tools: ['Other Tools'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolthink/',
},
],
},
},
inputs: [],
outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
outputNames: ['Tool'],
properties: [
(0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiAgent]),
{
displayName: 'Think Tool Description',
name: 'description',
type: 'string',
default: defaultToolDescription,
placeholder: '[Describe your thinking tool here, explaining how it will help the AI think]',
description: "The thinking tool's description",
typeOptions: {
rows: 3,
},
required: true,
},
],
};
}
async supplyData(itemIndex) {
const tool = await getTool(this, itemIndex);
return {
response: (0, ai_utilities_1.logWrapper)(tool, this),
};
}
async execute() {
const input = this.getInputData();
const response = [];
for (let i = 0; i < input.length; i++) {
const inputItem = input[i];
const tool = await getTool(this, i);
const result = await tool.invoke(inputItem.json);
response.push({
json: {
response: result,
},
pairedItem: {
item: i,
},
});
}
return [response];
}
}
exports.ToolThink = ToolThink;
//# sourceMappingURL=ToolThink.node.js.map