@n8n/n8n-nodes-langchain 1.116.2 → 1.117.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -209,7 +209,7 @@ function buildSteps(response, itemIndex) {
209
209
  toolCallId: toolInput?.id,
210
210
  type: toolInput.type || "tool_call"
211
211
  },
212
- observation: JSON.stringify(tool.data)
212
+ observation: JSON.stringify(tool.data?.data?.ai_tool?.[0]?.[0]?.json ?? "")
213
213
  };
214
214
  steps.push(toolResult);
215
215
  }
@@ -308,10 +308,17 @@ async function toolsAgentExecute(response) {
308
308
  input
309
309
  );
310
310
  if (result.toolCalls && result.toolCalls.length > 0) {
311
+ const currentIteration = (response?.metadata?.iterationCount ?? 0) + 1;
312
+ if (options.maxIterations && currentIteration > options.maxIterations) {
313
+ throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Maximum iterations reached");
314
+ }
311
315
  const actions = await createEngineRequests(result.toolCalls, itemIndex, tools);
312
316
  return {
313
317
  actions,
314
- metadata: { previousRequests: buildSteps(response, itemIndex) }
318
+ metadata: {
319
+ previousRequests: buildSteps(response, itemIndex),
320
+ iterationCount: currentIteration
321
+ }
315
322
  };
316
323
  }
317
324
  return result;
@@ -341,10 +348,17 @@ async function toolsAgentExecute(response) {
341
348
  }
342
349
  return result;
343
350
  }
351
+ const currentIteration = (response?.metadata?.iterationCount ?? 0) + 1;
352
+ if (options.maxIterations && currentIteration > options.maxIterations) {
353
+ throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Maximum iterations reached");
354
+ }
344
355
  const actions = await createEngineRequests(modelResponse, itemIndex, tools);
345
356
  return {
346
357
  actions,
347
- metadata: { previousRequests: buildSteps(response, itemIndex) }
358
+ metadata: {
359
+ previousRequests: buildSteps(response, itemIndex),
360
+ iterationCount: currentIteration
361
+ }
348
362
  };
349
363
  }
350
364
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/execute.ts"],"sourcesContent":["import type { StreamEvent } from '@langchain/core/dist/tracers/event_stream';\nimport type { IterableReadableStream } from '@langchain/core/dist/utils/stream';\nimport type { BaseChatModel } from '@langchain/core/language_models/chat_models';\nimport type { AIMessageChunk, BaseMessage, MessageContentText } from '@langchain/core/messages';\nimport { AIMessage, trimMessages } from '@langchain/core/messages';\nimport type { ToolCall } from '@langchain/core/messages/tool';\nimport type { ChatPromptTemplate } from '@langchain/core/prompts';\nimport { RunnableSequence } from '@langchain/core/runnables';\nimport { type AgentRunnableSequence, createToolCallingAgent } from 'langchain/agents';\nimport type { BaseChatMemory } from 'langchain/memory';\nimport type { DynamicStructuredTool, Tool } from 'langchain/tools';\nimport omit from 'lodash/omit';\nimport {\n\tjsonParse,\n\tNodeConnectionTypes,\n\tnodeNameToToolName,\n\tNodeOperationError,\n\tsleep,\n} from 'n8n-workflow';\nimport type {\n\tEngineRequest,\n\tGenericValue,\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tISupplyDataFunctions,\n\tEngineResponse,\n} from 'n8n-workflow';\nimport assert from 'node:assert';\n\nimport { getPromptInputByType } from '@utils/helpers';\nimport {\n\tgetOptionalOutputParser,\n\ttype N8nOutputParser,\n} from '@utils/output_parsers/N8nOutputParser';\n\nimport {\n\tfixEmptyContentMessage,\n\tgetAgentStepsParser,\n\tgetChatModel,\n\tgetOptionalMemory,\n\tgetTools,\n\tprepareMessages,\n\tpreparePrompt,\n} from '../common';\nimport { SYSTEM_MESSAGE } from '../prompt';\n\ntype ToolCallRequest = {\n\ttool: string;\n\ttoolInput: Record<string, unknown>;\n\ttoolCallId: string;\n\ttype?: string;\n\tlog?: string;\n\tmessageLog?: unknown[];\n};\n\nasync function createEngineRequests(\n\ttoolCalls: ToolCallRequest[],\n\titemIndex: number,\n\ttools: Array<DynamicStructuredTool | Tool>,\n) {\n\treturn toolCalls.map((toolCall) => {\n\t\t// First try to get from metadata (for toolkit tools)\n\t\tconst foundTool = tools.find((tool) => tool.name === toolCall.tool);\n\n\t\tif (!foundTool) return;\n\n\t\tconst nodeName = foundTool.metadata?.sourceNodeName;\n\n\t\t// For toolkit tools, include the tool name so the node knows which tool to execute\n\t\tconst input = foundTool.metadata?.isFromToolkit\n\t\t\t? { ...toolCall.toolInput, tool: toolCall.tool }\n\t\t\t: toolCall.toolInput;\n\n\t\treturn {\n\t\t\tnodeName,\n\t\t\tinput,\n\t\t\ttype: NodeConnectionTypes.AiTool,\n\t\t\tid: toolCall.toolCallId,\n\t\t\tmetadata: {\n\t\t\t\titemIndex,\n\t\t\t},\n\t\t};\n\t});\n}\n\n/**\n * Creates an agent executor with the given configuration\n */\nfunction createAgentSequence(\n\tmodel: BaseChatModel,\n\ttools: Array<DynamicStructuredTool | Tool>,\n\tprompt: ChatPromptTemplate,\n\t_options: { maxIterations?: number; returnIntermediateSteps?: boolean },\n\toutputParser?: N8nOutputParser,\n\tmemory?: BaseChatMemory,\n\tfallbackModel?: BaseChatModel | null,\n) {\n\tconst agent = createToolCallingAgent({\n\t\tllm: model,\n\t\ttools,\n\t\tprompt,\n\t\tstreamRunnable: false,\n\t});\n\n\tlet fallbackAgent: AgentRunnableSequence | undefined;\n\tif (fallbackModel) {\n\t\tfallbackAgent = createToolCallingAgent({\n\t\t\tllm: fallbackModel,\n\t\t\ttools,\n\t\t\tprompt,\n\t\t\tstreamRunnable: false,\n\t\t});\n\t}\n\tconst runnableAgent = RunnableSequence.from([\n\t\tfallbackAgent ? agent.withFallbacks([fallbackAgent]) : agent,\n\t\tgetAgentStepsParser(outputParser, memory),\n\t\tfixEmptyContentMessage,\n\t]) as AgentRunnableSequence;\n\n\trunnableAgent.singleAction = true;\n\trunnableAgent.streamRunnable = false;\n\n\treturn runnableAgent;\n}\n\ntype IntermediateStep = {\n\taction: {\n\t\ttool: string;\n\t\ttoolInput: Record<string, unknown>;\n\t\tlog: string;\n\t\tmessageLog: unknown[];\n\t\ttoolCallId: string;\n\t\ttype: string;\n\t};\n\tobservation?: string;\n};\n\ntype AgentResult = {\n\toutput: string;\n\tintermediateSteps?: IntermediateStep[];\n\ttoolCalls?: ToolCallRequest[];\n};\n\nasync function processEventStream(\n\tctx: IExecuteFunctions,\n\teventStream: IterableReadableStream<StreamEvent>,\n\titemIndex: number,\n\treturnIntermediateSteps: boolean = false,\n\tmemory?: BaseChatMemory,\n\tinput?: string,\n): Promise<AgentResult> {\n\tconst agentResult: AgentResult = {\n\t\toutput: '',\n\t};\n\n\tif (returnIntermediateSteps) {\n\t\tagentResult.intermediateSteps = [];\n\t}\n\n\tconst toolCalls: ToolCallRequest[] = [];\n\n\tctx.sendChunk('begin', itemIndex);\n\tfor await (const event of eventStream) {\n\t\t// Stream chat model tokens as they come in\n\t\tswitch (event.event) {\n\t\t\tcase 'on_chat_model_stream':\n\t\t\t\tconst chunk = event.data?.chunk as AIMessageChunk;\n\t\t\t\tif (chunk?.content) {\n\t\t\t\t\tconst chunkContent = chunk.content;\n\t\t\t\t\tlet chunkText = '';\n\t\t\t\t\tif (Array.isArray(chunkContent)) {\n\t\t\t\t\t\tfor (const message of chunkContent) {\n\t\t\t\t\t\t\tif (message?.type === 'text') {\n\t\t\t\t\t\t\t\tchunkText += (message as MessageContentText)?.text;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (typeof chunkContent === 'string') {\n\t\t\t\t\t\tchunkText = chunkContent;\n\t\t\t\t\t}\n\t\t\t\t\tctx.sendChunk('item', itemIndex, chunkText);\n\n\t\t\t\t\tagentResult.output += chunkText;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'on_chat_model_end':\n\t\t\t\t// Capture full LLM response with tool calls for intermediate steps\n\t\t\t\tif (event.data) {\n\t\t\t\t\tconst chatModelData = event.data as {\n\t\t\t\t\t\toutput?: { tool_calls?: ToolCall[]; content?: string };\n\t\t\t\t\t};\n\t\t\t\t\tconst output = chatModelData.output;\n\n\t\t\t\t\t// Check if this LLM response contains tool calls\n\t\t\t\t\tif (output?.tool_calls && output.tool_calls.length > 0) {\n\t\t\t\t\t\t// Collect tool calls for request building\n\t\t\t\t\t\tfor (const toolCall of output.tool_calls) {\n\t\t\t\t\t\t\ttoolCalls.push({\n\t\t\t\t\t\t\t\ttool: toolCall.name,\n\t\t\t\t\t\t\t\ttoolInput: toolCall.args,\n\t\t\t\t\t\t\t\ttoolCallId: toolCall.id || 'unknown',\n\t\t\t\t\t\t\t\ttype: toolCall.type || 'tool_call',\n\t\t\t\t\t\t\t\tlog:\n\t\t\t\t\t\t\t\t\toutput.content ||\n\t\t\t\t\t\t\t\t\t`Calling ${toolCall.name} with input: ${JSON.stringify(toolCall.args)}`,\n\t\t\t\t\t\t\t\tmessageLog: [output],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Also add to intermediate steps if needed\n\t\t\t\t\t\tif (returnIntermediateSteps) {\n\t\t\t\t\t\t\tfor (const toolCall of output.tool_calls) {\n\t\t\t\t\t\t\t\tagentResult.intermediateSteps!.push({\n\t\t\t\t\t\t\t\t\taction: {\n\t\t\t\t\t\t\t\t\t\ttool: toolCall.name,\n\t\t\t\t\t\t\t\t\t\ttoolInput: toolCall.args,\n\t\t\t\t\t\t\t\t\t\tlog:\n\t\t\t\t\t\t\t\t\t\t\toutput.content ||\n\t\t\t\t\t\t\t\t\t\t\t`Calling ${toolCall.name} with input: ${JSON.stringify(toolCall.args)}`,\n\t\t\t\t\t\t\t\t\t\tmessageLog: [output], // Include the full LLM response\n\t\t\t\t\t\t\t\t\t\ttoolCallId: toolCall.id || 'unknown',\n\t\t\t\t\t\t\t\t\t\ttype: toolCall.type || 'tool_call',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'on_tool_end':\n\t\t\t\t// Capture tool execution results and match with action\n\t\t\t\tif (returnIntermediateSteps && event.data && agentResult.intermediateSteps!.length > 0) {\n\t\t\t\t\tconst toolData = event.data as { output?: string };\n\t\t\t\t\t// Find the matching intermediate step for this tool call\n\t\t\t\t\tconst matchingStep = agentResult.intermediateSteps!.find(\n\t\t\t\t\t\t(step) => !step.observation && step.action.tool === event.name,\n\t\t\t\t\t);\n\t\t\t\t\tif (matchingStep) {\n\t\t\t\t\t\tmatchingStep.observation = toolData.output || '';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tctx.sendChunk('end', itemIndex);\n\n\t// Save conversation to memory if memory is connected\n\tif (memory && input && agentResult.output) {\n\t\tawait memory.saveContext({ input }, { output: agentResult.output });\n\t}\n\n\t// Include collected tool calls in the result\n\tif (toolCalls.length > 0) {\n\t\tagentResult.toolCalls = toolCalls;\n\t}\n\n\treturn agentResult;\n}\n\nexport type RequestResponseMetadata = {\n\titemIndex?: number;\n\tpreviousRequests: ToolCallData[];\n};\n\ntype ToolCallData = {\n\taction: {\n\t\ttool: string;\n\t\ttoolInput: Record<string, unknown>;\n\t\tlog: string | number | true | object;\n\t\ttoolCallId: IDataObject | GenericValue | GenericValue[] | IDataObject[];\n\t\ttype: string | number | true | object;\n\t};\n\tobservation: string;\n};\n\nfunction buildSteps(\n\tresponse: EngineResponse<RequestResponseMetadata> | undefined,\n\titemIndex: number,\n): ToolCallData[] {\n\tconst steps: ToolCallData[] = [];\n\n\tif (response) {\n\t\tconst responses = response?.actionResponses ?? [];\n\n\t\tif (response.metadata?.previousRequests) {\n\t\t\tsteps.push(...response.metadata.previousRequests);\n\t\t}\n\n\t\tfor (const tool of responses) {\n\t\t\tif (tool.action?.metadata?.itemIndex !== itemIndex) continue;\n\n\t\t\tconst toolInput: IDataObject = {\n\t\t\t\t...tool.action.input,\n\t\t\t\tid: tool.action.id,\n\t\t\t};\n\t\t\tif (!toolInput || !tool.data) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst step = steps.find((step) => step.action.toolCallId === toolInput.id);\n\t\t\tif (step) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Create a synthetic AI message for the messageLog\n\t\t\t// This represents the AI's decision to call the tool\n\t\t\tconst syntheticAIMessage = new AIMessage({\n\t\t\t\tcontent: `Calling ${tool.action.nodeName} with input: ${JSON.stringify(toolInput)}`,\n\t\t\t\ttool_calls: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: (toolInput?.id as string) ?? 'reconstructed_call',\n\t\t\t\t\t\tname: nodeNameToToolName(tool.action.nodeName),\n\t\t\t\t\t\targs: toolInput,\n\t\t\t\t\t\ttype: 'tool_call',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tconst toolResult = {\n\t\t\t\taction: {\n\t\t\t\t\ttool: nodeNameToToolName(tool.action.nodeName),\n\t\t\t\t\ttoolInput: (toolInput.input as IDataObject) || {},\n\t\t\t\t\tlog: toolInput.log || syntheticAIMessage.content,\n\t\t\t\t\tmessageLog: [syntheticAIMessage],\n\t\t\t\t\ttoolCallId: toolInput?.id,\n\t\t\t\t\ttype: toolInput.type || 'tool_call',\n\t\t\t\t},\n\t\t\t\tobservation: JSON.stringify(tool.data),\n\t\t\t};\n\n\t\t\tsteps.push(toolResult);\n\t\t}\n\t}\n\treturn steps;\n}\n\n/* -----------------------------------------------------------\n Main Executor Function\n----------------------------------------------------------- */\n/**\n * The main executor method for the Tools Agent.\n *\n * This function retrieves necessary components (model, memory, tools), prepares the prompt,\n * creates the agent, and processes each input item. The error handling for each item is also\n * managed here based on the node's continueOnFail setting.\n *\n * @param this Execute context. SupplyDataContext is passed when agent is as a tool\n *\n * @returns The array of execution data for all processed items\n */\nexport async function toolsAgentExecute(\n\tthis: IExecuteFunctions | ISupplyDataFunctions,\n\tresponse?: EngineResponse<RequestResponseMetadata>,\n): Promise<INodeExecutionData[][] | EngineRequest<RequestResponseMetadata>> {\n\tthis.logger.debug('Executing Tools Agent V3');\n\n\tconst returnData: INodeExecutionData[] = [];\n\tlet request: EngineRequest<RequestResponseMetadata> | undefined = undefined;\n\n\tconst items = this.getInputData();\n\tconst batchSize = this.getNodeParameter('options.batching.batchSize', 0, 1) as number;\n\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t'options.batching.delayBetweenBatches',\n\t\t0,\n\t\t0,\n\t) as number;\n\tconst needsFallback = this.getNodeParameter('needsFallback', 0, false) as boolean;\n\tconst memory = await getOptionalMemory(this);\n\tconst model = await getChatModel(this, 0);\n\tassert(model, 'Please connect a model to the Chat Model input');\n\tconst fallbackModel = needsFallback ? await getChatModel(this, 1) : null;\n\n\tif (needsFallback && !fallbackModel) {\n\t\tthrow new NodeOperationError(\n\t\t\tthis.getNode(),\n\t\t\t'Please connect a model to the Fallback Model input or disable the fallback option',\n\t\t);\n\t}\n\n\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\tconst batch = items.slice(i, i + batchSize);\n\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\tconst itemIndex = i + batchItemIndex;\n\n\t\t\tif (response && response?.metadata?.itemIndex === itemIndex) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst steps = buildSteps(response, itemIndex);\n\n\t\t\tconst input = getPromptInputByType({\n\t\t\t\tctx: this,\n\t\t\t\ti: itemIndex,\n\t\t\t\tinputKey: 'text',\n\t\t\t\tpromptTypeKey: 'promptType',\n\t\t\t});\n\t\t\tif (input === undefined) {\n\t\t\t\tthrow new NodeOperationError(this.getNode(), 'The \"text\" parameter is empty.');\n\t\t\t}\n\t\t\tconst outputParser = await getOptionalOutputParser(this, itemIndex);\n\t\t\tconst tools = await getTools(this, outputParser);\n\t\t\tconst options = this.getNodeParameter('options', itemIndex) as {\n\t\t\t\tsystemMessage?: string;\n\t\t\t\tmaxIterations?: number;\n\t\t\t\treturnIntermediateSteps?: boolean;\n\t\t\t\tpassthroughBinaryImages?: boolean;\n\t\t\t\tenableStreaming?: boolean;\n\t\t\t\tmaxTokensFromMemory?: number;\n\t\t\t};\n\n\t\t\tif (options.enableStreaming === undefined) {\n\t\t\t\toptions.enableStreaming = true;\n\t\t\t}\n\n\t\t\t// Prepare the prompt messages and prompt template.\n\t\t\tconst messages = await prepareMessages(this, itemIndex, {\n\t\t\t\tsystemMessage: options.systemMessage,\n\t\t\t\tpassthroughBinaryImages: options.passthroughBinaryImages ?? true,\n\t\t\t\toutputParser,\n\t\t\t});\n\t\t\tconst prompt: ChatPromptTemplate = preparePrompt(messages);\n\n\t\t\t// Create executors for primary and fallback models\n\t\t\tconst executor = createAgentSequence(\n\t\t\t\tmodel,\n\t\t\t\ttools,\n\t\t\t\tprompt,\n\t\t\t\toptions,\n\t\t\t\toutputParser,\n\t\t\t\tmemory,\n\t\t\t\tfallbackModel,\n\t\t\t);\n\t\t\t// Invoke with fallback logic\n\t\t\tconst invokeParams = {\n\t\t\t\tsteps,\n\t\t\t\tinput,\n\t\t\t\tsystem_message: options.systemMessage ?? SYSTEM_MESSAGE,\n\t\t\t\tformatting_instructions:\n\t\t\t\t\t'IMPORTANT: For your response to user, you MUST use the `format_final_json_response` tool with your complete answer formatted according to the required schema. Do not attempt to format the JSON manually - always use this tool. Your response will be rejected if it is not properly formatted through this tool. Only use this tool once you are ready to provide your final answer.',\n\t\t\t};\n\t\t\tconst executeOptions = { signal: this.getExecutionCancelSignal() };\n\n\t\t\t// Check if streaming is actually available\n\t\t\tconst isStreamingAvailable = 'isStreaming' in this ? this.isStreaming?.() : undefined;\n\n\t\t\tif (\n\t\t\t\t'isStreaming' in this &&\n\t\t\t\toptions.enableStreaming &&\n\t\t\t\tisStreamingAvailable &&\n\t\t\t\tthis.getNode().typeVersion >= 2.1\n\t\t\t) {\n\t\t\t\tlet chatHistory: BaseMessage[] | undefined = undefined;\n\t\t\t\tif (memory) {\n\t\t\t\t\t// Load memory variables to respect context window length\n\t\t\t\t\tchatHistory = await loadChatHistory(memory, model, options.maxTokensFromMemory);\n\t\t\t\t}\n\t\t\t\tconst eventStream = executor.streamEvents(\n\t\t\t\t\t{\n\t\t\t\t\t\t...invokeParams,\n\t\t\t\t\t\tchat_history: chatHistory,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tversion: 'v2',\n\t\t\t\t\t\t...executeOptions,\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tconst result = await processEventStream(\n\t\t\t\t\tthis,\n\t\t\t\t\teventStream,\n\t\t\t\t\titemIndex,\n\t\t\t\t\toptions.returnIntermediateSteps,\n\t\t\t\t\tmemory,\n\t\t\t\t\tinput,\n\t\t\t\t);\n\n\t\t\t\t// If result contains tool calls, build the request object like the normal flow\n\t\t\t\tif (result.toolCalls && result.toolCalls.length > 0) {\n\t\t\t\t\tconst actions = await createEngineRequests(result.toolCalls, itemIndex, tools);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tactions,\n\t\t\t\t\t\tmetadata: { previousRequests: buildSteps(response, itemIndex) },\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t} else {\n\t\t\t\t// Handle regular execution\n\t\t\t\tlet chatHistory: BaseMessage[] | undefined = undefined;\n\t\t\t\tif (memory) {\n\t\t\t\t\t// Load memory variables to respect context window length\n\t\t\t\t\tchatHistory = await loadChatHistory(memory, model, options.maxTokensFromMemory);\n\t\t\t\t}\n\t\t\t\tconst modelResponse = await executor.invoke({\n\t\t\t\t\t...invokeParams,\n\t\t\t\t\tchat_history: chatHistory,\n\t\t\t\t});\n\n\t\t\t\tif ('returnValues' in modelResponse) {\n\t\t\t\t\t// Save conversation to memory including any tool call context\n\t\t\t\t\tif (memory && input && modelResponse.returnValues.output) {\n\t\t\t\t\t\t// If there were tool calls in this conversation, include them in the context\n\t\t\t\t\t\tlet fullOutput = modelResponse.returnValues.output as string;\n\n\t\t\t\t\t\tif (steps.length > 0) {\n\t\t\t\t\t\t\t// Include tool call information in the conversation context\n\t\t\t\t\t\t\tconst toolContext = steps\n\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\t(step) =>\n\t\t\t\t\t\t\t\t\t\t`Tool: ${step.action.tool}, Input: ${JSON.stringify(step.action.toolInput)}, Result: ${step.observation}`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.join('; ');\n\t\t\t\t\t\t\tfullOutput = `[Used tools: ${toolContext}] ${fullOutput}`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait memory.saveContext({ input }, { output: fullOutput });\n\t\t\t\t\t}\n\t\t\t\t\t// Include intermediate steps if requested\n\t\t\t\t\tconst result = { ...modelResponse.returnValues };\n\t\t\t\t\tif (options.returnIntermediateSteps && steps.length > 0) {\n\t\t\t\t\t\tresult.intermediateSteps = steps;\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\n\t\t\t\t// If response contains tool calls, we need to return this in the right format\n\t\t\t\tconst actions = await createEngineRequests(modelResponse, itemIndex, tools);\n\n\t\t\t\treturn {\n\t\t\t\t\tactions,\n\t\t\t\t\tmetadata: { previousRequests: buildSteps(response, itemIndex) },\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\n\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\t\t// This is only used to check if the output parser is connected\n\t\t// so we can parse the output if needed. Actual output parsing is done in the loop above\n\t\tconst outputParser = await getOptionalOutputParser(this, 0);\n\t\tbatchResults.forEach((result, index) => {\n\t\t\tconst itemIndex = i + index;\n\t\t\tif (result.status === 'rejected') {\n\t\t\t\tconst error = result.reason as Error;\n\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\treturnData.push({\n\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t} as INodeExecutionData);\n\t\t\t\t\treturn;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst response = result.value;\n\n\t\t\tif ('actions' in response) {\n\t\t\t\tif (!request) {\n\t\t\t\t\trequest = {\n\t\t\t\t\t\tactions: response.actions,\n\t\t\t\t\t\tmetadata: response.metadata,\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\trequest.actions.push(...response.actions);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If memory and outputParser are connected, parse the output.\n\t\t\tif (memory && outputParser) {\n\t\t\t\tconst parsedOutput = jsonParse<{ output: Record<string, unknown> }>(\n\t\t\t\t\tresponse.output as string,\n\t\t\t\t);\n\t\t\t\tresponse.output = parsedOutput?.output ?? parsedOutput;\n\t\t\t}\n\n\t\t\t// Omit internal keys before returning the result.\n\t\t\tconst itemResult: INodeExecutionData = {\n\t\t\t\tjson: omit(\n\t\t\t\t\tresponse,\n\t\t\t\t\t'system_message',\n\t\t\t\t\t'formatting_instructions',\n\t\t\t\t\t'input',\n\t\t\t\t\t'chat_history',\n\t\t\t\t\t'agent_scratchpad',\n\t\t\t\t),\n\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t};\n\n\t\t\treturnData.push(itemResult);\n\t\t});\n\n\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\tawait sleep(delayBetweenBatches);\n\t\t}\n\t}\n\t// Check if we have any Request objects (tool calls)\n\tif (request) {\n\t\treturn request;\n\t}\n\n\t// Otherwise return execution data\n\treturn [returnData];\n}\nasync function loadChatHistory(\n\tmemory: BaseChatMemory,\n\tmodel: BaseChatModel,\n\tmaxTokensFromMemory?: number,\n): Promise<BaseMessage[]> {\n\tconst memoryVariables = await memory.loadMemoryVariables({});\n\tlet chatHistory = memoryVariables['chat_history'] as BaseMessage[];\n\n\tif (maxTokensFromMemory) {\n\t\tchatHistory = await trimMessages(chatHistory, {\n\t\t\tstrategy: 'last',\n\t\t\tmaxTokens: maxTokensFromMemory,\n\t\t\ttokenCounter: model,\n\t\t\tincludeSystem: true,\n\t\t\tstartOn: 'human',\n\t\t\tallowPart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AACA;AAAA,MACD;AAGA,UAAI,UAAU,cAAc;AAC3B,cAAM,mBAAe;AAAA,UACpBA,UAAS;AAAA,QACV;AACA,QAAAA,UAAS,SAAS,cAAc,UAAU;AAAA,MAC3C;AAGA,YAAM,aAAiC;AAAA,QACtC,UAAM,YAAAC;AAAA,UACLD;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAAA,QACA,YAAY,EAAE,MAAM,UAAU;AAAA,MAC/B;AAEA,iBAAW,KAAK,UAAU;AAAA,IAC3B,CAAC;AAED,QAAI,IAAI,YAAY,MAAM,UAAU,sBAAsB,GAAG;AAC5D,gBAAM,2BAAM,mBAAmB;AAAA,IAChC;AAAA,EACD;AAEA,MAAI,SAAS;AACZ,WAAO;AAAA,EACR;AAGA,SAAO,CAAC,UAAU;AACnB;AACA,eAAe,gBACd,QACA,OACA,qBACyB;AACzB,QAAM,kBAAkB,MAAM,OAAO,oBAAoB,CAAC,CAAC;AAC3D,MAAI,cAAc,gBAAgB,cAAc;AAEhD,MAAI,qBAAqB;AACxB,kBAAc,UAAM,8BAAa,aAAa;AAAA,MAC7C,UAAU;AAAA,MACV,WAAW;AAAA,MACX,cAAc;AAAA,MACd,eAAe;AAAA,MACf,SAAS;AAAA,MACT,cAAc;AAAA,IACf,CAAC;AAAA,EACF;AAEA,SAAO;AACR;","names":["step","assert","outputParser","response","omit"]}
1
+ {"version":3,"sources":["../../../../../../../nodes/agents/Agent/agents/ToolsAgent/V3/execute.ts"],"sourcesContent":["import type { StreamEvent } from '@langchain/core/dist/tracers/event_stream';\nimport type { IterableReadableStream } from '@langchain/core/dist/utils/stream';\nimport type { BaseChatModel } from '@langchain/core/language_models/chat_models';\nimport type { AIMessageChunk, BaseMessage, MessageContentText } from '@langchain/core/messages';\nimport { AIMessage, trimMessages } from '@langchain/core/messages';\nimport type { ToolCall } from '@langchain/core/messages/tool';\nimport type { ChatPromptTemplate } from '@langchain/core/prompts';\nimport { RunnableSequence } from '@langchain/core/runnables';\nimport { type AgentRunnableSequence, createToolCallingAgent } from 'langchain/agents';\nimport type { BaseChatMemory } from 'langchain/memory';\nimport type { DynamicStructuredTool, Tool } from 'langchain/tools';\nimport omit from 'lodash/omit';\nimport {\n\tjsonParse,\n\tNodeConnectionTypes,\n\tnodeNameToToolName,\n\tNodeOperationError,\n\tsleep,\n} from 'n8n-workflow';\nimport type {\n\tEngineRequest,\n\tGenericValue,\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tISupplyDataFunctions,\n\tEngineResponse,\n} from 'n8n-workflow';\nimport assert from 'node:assert';\n\nimport { getPromptInputByType } from '@utils/helpers';\nimport {\n\tgetOptionalOutputParser,\n\ttype N8nOutputParser,\n} from '@utils/output_parsers/N8nOutputParser';\n\nimport {\n\tfixEmptyContentMessage,\n\tgetAgentStepsParser,\n\tgetChatModel,\n\tgetOptionalMemory,\n\tgetTools,\n\tprepareMessages,\n\tpreparePrompt,\n} from '../common';\nimport { SYSTEM_MESSAGE } from '../prompt';\n\ntype ToolCallRequest = {\n\ttool: string;\n\ttoolInput: Record<string, unknown>;\n\ttoolCallId: string;\n\ttype?: string;\n\tlog?: string;\n\tmessageLog?: unknown[];\n};\n\nasync function createEngineRequests(\n\ttoolCalls: ToolCallRequest[],\n\titemIndex: number,\n\ttools: Array<DynamicStructuredTool | Tool>,\n) {\n\treturn toolCalls.map((toolCall) => {\n\t\t// First try to get from metadata (for toolkit tools)\n\t\tconst foundTool = tools.find((tool) => tool.name === toolCall.tool);\n\n\t\tif (!foundTool) return;\n\n\t\tconst nodeName = foundTool.metadata?.sourceNodeName;\n\n\t\t// For toolkit tools, include the tool name so the node knows which tool to execute\n\t\tconst input = foundTool.metadata?.isFromToolkit\n\t\t\t? { ...toolCall.toolInput, tool: toolCall.tool }\n\t\t\t: toolCall.toolInput;\n\n\t\treturn {\n\t\t\tnodeName,\n\t\t\tinput,\n\t\t\ttype: NodeConnectionTypes.AiTool,\n\t\t\tid: toolCall.toolCallId,\n\t\t\tmetadata: {\n\t\t\t\titemIndex,\n\t\t\t},\n\t\t};\n\t});\n}\n\n/**\n * Creates an agent executor with the given configuration\n */\nfunction createAgentSequence(\n\tmodel: BaseChatModel,\n\ttools: Array<DynamicStructuredTool | Tool>,\n\tprompt: ChatPromptTemplate,\n\t_options: { maxIterations?: number; returnIntermediateSteps?: boolean },\n\toutputParser?: N8nOutputParser,\n\tmemory?: BaseChatMemory,\n\tfallbackModel?: BaseChatModel | null,\n) {\n\tconst agent = createToolCallingAgent({\n\t\tllm: model,\n\t\ttools,\n\t\tprompt,\n\t\tstreamRunnable: false,\n\t});\n\n\tlet fallbackAgent: AgentRunnableSequence | undefined;\n\tif (fallbackModel) {\n\t\tfallbackAgent = createToolCallingAgent({\n\t\t\tllm: fallbackModel,\n\t\t\ttools,\n\t\t\tprompt,\n\t\t\tstreamRunnable: false,\n\t\t});\n\t}\n\tconst runnableAgent = RunnableSequence.from([\n\t\tfallbackAgent ? agent.withFallbacks([fallbackAgent]) : agent,\n\t\tgetAgentStepsParser(outputParser, memory),\n\t\tfixEmptyContentMessage,\n\t]) as AgentRunnableSequence;\n\n\trunnableAgent.singleAction = true;\n\trunnableAgent.streamRunnable = false;\n\n\treturn runnableAgent;\n}\n\ntype IntermediateStep = {\n\taction: {\n\t\ttool: string;\n\t\ttoolInput: Record<string, unknown>;\n\t\tlog: string;\n\t\tmessageLog: unknown[];\n\t\ttoolCallId: string;\n\t\ttype: string;\n\t};\n\tobservation?: string;\n};\n\ntype AgentResult = {\n\toutput: string;\n\tintermediateSteps?: IntermediateStep[];\n\ttoolCalls?: ToolCallRequest[];\n};\n\nasync function processEventStream(\n\tctx: IExecuteFunctions,\n\teventStream: IterableReadableStream<StreamEvent>,\n\titemIndex: number,\n\treturnIntermediateSteps: boolean = false,\n\tmemory?: BaseChatMemory,\n\tinput?: string,\n): Promise<AgentResult> {\n\tconst agentResult: AgentResult = {\n\t\toutput: '',\n\t};\n\n\tif (returnIntermediateSteps) {\n\t\tagentResult.intermediateSteps = [];\n\t}\n\n\tconst toolCalls: ToolCallRequest[] = [];\n\n\tctx.sendChunk('begin', itemIndex);\n\tfor await (const event of eventStream) {\n\t\t// Stream chat model tokens as they come in\n\t\tswitch (event.event) {\n\t\t\tcase 'on_chat_model_stream':\n\t\t\t\tconst chunk = event.data?.chunk as AIMessageChunk;\n\t\t\t\tif (chunk?.content) {\n\t\t\t\t\tconst chunkContent = chunk.content;\n\t\t\t\t\tlet chunkText = '';\n\t\t\t\t\tif (Array.isArray(chunkContent)) {\n\t\t\t\t\t\tfor (const message of chunkContent) {\n\t\t\t\t\t\t\tif (message?.type === 'text') {\n\t\t\t\t\t\t\t\tchunkText += (message as MessageContentText)?.text;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (typeof chunkContent === 'string') {\n\t\t\t\t\t\tchunkText = chunkContent;\n\t\t\t\t\t}\n\t\t\t\t\tctx.sendChunk('item', itemIndex, chunkText);\n\n\t\t\t\t\tagentResult.output += chunkText;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'on_chat_model_end':\n\t\t\t\t// Capture full LLM response with tool calls for intermediate steps\n\t\t\t\tif (event.data) {\n\t\t\t\t\tconst chatModelData = event.data as {\n\t\t\t\t\t\toutput?: { tool_calls?: ToolCall[]; content?: string };\n\t\t\t\t\t};\n\t\t\t\t\tconst output = chatModelData.output;\n\n\t\t\t\t\t// Check if this LLM response contains tool calls\n\t\t\t\t\tif (output?.tool_calls && output.tool_calls.length > 0) {\n\t\t\t\t\t\t// Collect tool calls for request building\n\t\t\t\t\t\tfor (const toolCall of output.tool_calls) {\n\t\t\t\t\t\t\ttoolCalls.push({\n\t\t\t\t\t\t\t\ttool: toolCall.name,\n\t\t\t\t\t\t\t\ttoolInput: toolCall.args,\n\t\t\t\t\t\t\t\ttoolCallId: toolCall.id || 'unknown',\n\t\t\t\t\t\t\t\ttype: toolCall.type || 'tool_call',\n\t\t\t\t\t\t\t\tlog:\n\t\t\t\t\t\t\t\t\toutput.content ||\n\t\t\t\t\t\t\t\t\t`Calling ${toolCall.name} with input: ${JSON.stringify(toolCall.args)}`,\n\t\t\t\t\t\t\t\tmessageLog: [output],\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Also add to intermediate steps if needed\n\t\t\t\t\t\tif (returnIntermediateSteps) {\n\t\t\t\t\t\t\tfor (const toolCall of output.tool_calls) {\n\t\t\t\t\t\t\t\tagentResult.intermediateSteps!.push({\n\t\t\t\t\t\t\t\t\taction: {\n\t\t\t\t\t\t\t\t\t\ttool: toolCall.name,\n\t\t\t\t\t\t\t\t\t\ttoolInput: toolCall.args,\n\t\t\t\t\t\t\t\t\t\tlog:\n\t\t\t\t\t\t\t\t\t\t\toutput.content ||\n\t\t\t\t\t\t\t\t\t\t\t`Calling ${toolCall.name} with input: ${JSON.stringify(toolCall.args)}`,\n\t\t\t\t\t\t\t\t\t\tmessageLog: [output], // Include the full LLM response\n\t\t\t\t\t\t\t\t\t\ttoolCallId: toolCall.id || 'unknown',\n\t\t\t\t\t\t\t\t\t\ttype: toolCall.type || 'tool_call',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'on_tool_end':\n\t\t\t\t// Capture tool execution results and match with action\n\t\t\t\tif (returnIntermediateSteps && event.data && agentResult.intermediateSteps!.length > 0) {\n\t\t\t\t\tconst toolData = event.data as { output?: string };\n\t\t\t\t\t// Find the matching intermediate step for this tool call\n\t\t\t\t\tconst matchingStep = agentResult.intermediateSteps!.find(\n\t\t\t\t\t\t(step) => !step.observation && step.action.tool === event.name,\n\t\t\t\t\t);\n\t\t\t\t\tif (matchingStep) {\n\t\t\t\t\t\tmatchingStep.observation = toolData.output || '';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tctx.sendChunk('end', itemIndex);\n\n\t// Save conversation to memory if memory is connected\n\tif (memory && input && agentResult.output) {\n\t\tawait memory.saveContext({ input }, { output: agentResult.output });\n\t}\n\n\t// Include collected tool calls in the result\n\tif (toolCalls.length > 0) {\n\t\tagentResult.toolCalls = toolCalls;\n\t}\n\n\treturn agentResult;\n}\n\nexport type RequestResponseMetadata = {\n\titemIndex?: number;\n\tpreviousRequests: ToolCallData[];\n\titerationCount?: number;\n};\n\ntype ToolCallData = {\n\taction: {\n\t\ttool: string;\n\t\ttoolInput: Record<string, unknown>;\n\t\tlog: string | number | true | object;\n\t\ttoolCallId: IDataObject | GenericValue | GenericValue[] | IDataObject[];\n\t\ttype: string | number | true | object;\n\t};\n\tobservation: string;\n};\n\nfunction buildSteps(\n\tresponse: EngineResponse<RequestResponseMetadata> | undefined,\n\titemIndex: number,\n): ToolCallData[] {\n\tconst steps: ToolCallData[] = [];\n\n\tif (response) {\n\t\tconst responses = response?.actionResponses ?? [];\n\n\t\tif (response.metadata?.previousRequests) {\n\t\t\tsteps.push(...response.metadata.previousRequests);\n\t\t}\n\n\t\tfor (const tool of responses) {\n\t\t\tif (tool.action?.metadata?.itemIndex !== itemIndex) continue;\n\n\t\t\tconst toolInput: IDataObject = {\n\t\t\t\t...tool.action.input,\n\t\t\t\tid: tool.action.id,\n\t\t\t};\n\t\t\tif (!toolInput || !tool.data) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst step = steps.find((step) => step.action.toolCallId === toolInput.id);\n\t\t\tif (step) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Create a synthetic AI message for the messageLog\n\t\t\t// This represents the AI's decision to call the tool\n\t\t\tconst syntheticAIMessage = new AIMessage({\n\t\t\t\tcontent: `Calling ${tool.action.nodeName} with input: ${JSON.stringify(toolInput)}`,\n\t\t\t\ttool_calls: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: (toolInput?.id as string) ?? 'reconstructed_call',\n\t\t\t\t\t\tname: nodeNameToToolName(tool.action.nodeName),\n\t\t\t\t\t\targs: toolInput,\n\t\t\t\t\t\ttype: 'tool_call',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t});\n\n\t\t\tconst toolResult = {\n\t\t\t\taction: {\n\t\t\t\t\ttool: nodeNameToToolName(tool.action.nodeName),\n\t\t\t\t\ttoolInput: (toolInput.input as IDataObject) || {},\n\t\t\t\t\tlog: toolInput.log || syntheticAIMessage.content,\n\t\t\t\t\tmessageLog: [syntheticAIMessage],\n\t\t\t\t\ttoolCallId: toolInput?.id,\n\t\t\t\t\ttype: toolInput.type || 'tool_call',\n\t\t\t\t},\n\t\t\t\tobservation: JSON.stringify(tool.data?.data?.ai_tool?.[0]?.[0]?.json ?? ''),\n\t\t\t};\n\n\t\t\tsteps.push(toolResult);\n\t\t}\n\t}\n\treturn steps;\n}\n\n/* -----------------------------------------------------------\n Main Executor Function\n----------------------------------------------------------- */\n/**\n * The main executor method for the Tools Agent.\n *\n * This function retrieves necessary components (model, memory, tools), prepares the prompt,\n * creates the agent, and processes each input item. The error handling for each item is also\n * managed here based on the node's continueOnFail setting.\n *\n * @param this Execute context. SupplyDataContext is passed when agent is as a tool\n *\n * @returns The array of execution data for all processed items\n */\nexport async function toolsAgentExecute(\n\tthis: IExecuteFunctions | ISupplyDataFunctions,\n\tresponse?: EngineResponse<RequestResponseMetadata>,\n): Promise<INodeExecutionData[][] | EngineRequest<RequestResponseMetadata>> {\n\tthis.logger.debug('Executing Tools Agent V3');\n\n\tconst returnData: INodeExecutionData[] = [];\n\tlet request: EngineRequest<RequestResponseMetadata> | undefined = undefined;\n\n\tconst items = this.getInputData();\n\tconst batchSize = this.getNodeParameter('options.batching.batchSize', 0, 1) as number;\n\tconst delayBetweenBatches = this.getNodeParameter(\n\t\t'options.batching.delayBetweenBatches',\n\t\t0,\n\t\t0,\n\t) as number;\n\tconst needsFallback = this.getNodeParameter('needsFallback', 0, false) as boolean;\n\tconst memory = await getOptionalMemory(this);\n\tconst model = await getChatModel(this, 0);\n\tassert(model, 'Please connect a model to the Chat Model input');\n\tconst fallbackModel = needsFallback ? await getChatModel(this, 1) : null;\n\n\tif (needsFallback && !fallbackModel) {\n\t\tthrow new NodeOperationError(\n\t\t\tthis.getNode(),\n\t\t\t'Please connect a model to the Fallback Model input or disable the fallback option',\n\t\t);\n\t}\n\n\tfor (let i = 0; i < items.length; i += batchSize) {\n\t\tconst batch = items.slice(i, i + batchSize);\n\t\tconst batchPromises = batch.map(async (_item, batchItemIndex) => {\n\t\t\tconst itemIndex = i + batchItemIndex;\n\n\t\t\tif (response && response?.metadata?.itemIndex === itemIndex) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst steps = buildSteps(response, itemIndex);\n\n\t\t\tconst input = getPromptInputByType({\n\t\t\t\tctx: this,\n\t\t\t\ti: itemIndex,\n\t\t\t\tinputKey: 'text',\n\t\t\t\tpromptTypeKey: 'promptType',\n\t\t\t});\n\t\t\tif (input === undefined) {\n\t\t\t\tthrow new NodeOperationError(this.getNode(), 'The \"text\" parameter is empty.');\n\t\t\t}\n\t\t\tconst outputParser = await getOptionalOutputParser(this, itemIndex);\n\t\t\tconst tools = await getTools(this, outputParser);\n\t\t\tconst options = this.getNodeParameter('options', itemIndex) as {\n\t\t\t\tsystemMessage?: string;\n\t\t\t\tmaxIterations?: number;\n\t\t\t\treturnIntermediateSteps?: boolean;\n\t\t\t\tpassthroughBinaryImages?: boolean;\n\t\t\t\tenableStreaming?: boolean;\n\t\t\t\tmaxTokensFromMemory?: number;\n\t\t\t};\n\n\t\t\tif (options.enableStreaming === undefined) {\n\t\t\t\toptions.enableStreaming = true;\n\t\t\t}\n\n\t\t\t// Prepare the prompt messages and prompt template.\n\t\t\tconst messages = await prepareMessages(this, itemIndex, {\n\t\t\t\tsystemMessage: options.systemMessage,\n\t\t\t\tpassthroughBinaryImages: options.passthroughBinaryImages ?? true,\n\t\t\t\toutputParser,\n\t\t\t});\n\t\t\tconst prompt: ChatPromptTemplate = preparePrompt(messages);\n\n\t\t\t// Create executors for primary and fallback models\n\t\t\tconst executor = createAgentSequence(\n\t\t\t\tmodel,\n\t\t\t\ttools,\n\t\t\t\tprompt,\n\t\t\t\toptions,\n\t\t\t\toutputParser,\n\t\t\t\tmemory,\n\t\t\t\tfallbackModel,\n\t\t\t);\n\t\t\t// Invoke with fallback logic\n\t\t\tconst invokeParams = {\n\t\t\t\tsteps,\n\t\t\t\tinput,\n\t\t\t\tsystem_message: options.systemMessage ?? SYSTEM_MESSAGE,\n\t\t\t\tformatting_instructions:\n\t\t\t\t\t'IMPORTANT: For your response to user, you MUST use the `format_final_json_response` tool with your complete answer formatted according to the required schema. Do not attempt to format the JSON manually - always use this tool. Your response will be rejected if it is not properly formatted through this tool. Only use this tool once you are ready to provide your final answer.',\n\t\t\t};\n\t\t\tconst executeOptions = { signal: this.getExecutionCancelSignal() };\n\n\t\t\t// Check if streaming is actually available\n\t\t\tconst isStreamingAvailable = 'isStreaming' in this ? this.isStreaming?.() : undefined;\n\n\t\t\tif (\n\t\t\t\t'isStreaming' in this &&\n\t\t\t\toptions.enableStreaming &&\n\t\t\t\tisStreamingAvailable &&\n\t\t\t\tthis.getNode().typeVersion >= 2.1\n\t\t\t) {\n\t\t\t\tlet chatHistory: BaseMessage[] | undefined = undefined;\n\t\t\t\tif (memory) {\n\t\t\t\t\t// Load memory variables to respect context window length\n\t\t\t\t\tchatHistory = await loadChatHistory(memory, model, options.maxTokensFromMemory);\n\t\t\t\t}\n\t\t\t\tconst eventStream = executor.streamEvents(\n\t\t\t\t\t{\n\t\t\t\t\t\t...invokeParams,\n\t\t\t\t\t\tchat_history: chatHistory,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tversion: 'v2',\n\t\t\t\t\t\t...executeOptions,\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tconst result = await processEventStream(\n\t\t\t\t\tthis,\n\t\t\t\t\teventStream,\n\t\t\t\t\titemIndex,\n\t\t\t\t\toptions.returnIntermediateSteps,\n\t\t\t\t\tmemory,\n\t\t\t\t\tinput,\n\t\t\t\t);\n\n\t\t\t\t// If result contains tool calls, build the request object like the normal flow\n\t\t\t\tif (result.toolCalls && result.toolCalls.length > 0) {\n\t\t\t\t\tconst currentIteration = (response?.metadata?.iterationCount ?? 0) + 1;\n\n\t\t\t\t\t// Check if we've exceeded maxIterations\n\t\t\t\t\tif (options.maxIterations && currentIteration > options.maxIterations) {\n\t\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'Maximum iterations reached');\n\t\t\t\t\t}\n\n\t\t\t\t\tconst actions = await createEngineRequests(result.toolCalls, itemIndex, tools);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tactions,\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tpreviousRequests: buildSteps(response, itemIndex),\n\t\t\t\t\t\t\titerationCount: currentIteration,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t} else {\n\t\t\t\t// Handle regular execution\n\t\t\t\tlet chatHistory: BaseMessage[] | undefined = undefined;\n\t\t\t\tif (memory) {\n\t\t\t\t\t// Load memory variables to respect context window length\n\t\t\t\t\tchatHistory = await loadChatHistory(memory, model, options.maxTokensFromMemory);\n\t\t\t\t}\n\t\t\t\tconst modelResponse = await executor.invoke({\n\t\t\t\t\t...invokeParams,\n\t\t\t\t\tchat_history: chatHistory,\n\t\t\t\t});\n\n\t\t\t\tif ('returnValues' in modelResponse) {\n\t\t\t\t\t// Save conversation to memory including any tool call context\n\t\t\t\t\tif (memory && input && modelResponse.returnValues.output) {\n\t\t\t\t\t\t// If there were tool calls in this conversation, include them in the context\n\t\t\t\t\t\tlet fullOutput = modelResponse.returnValues.output as string;\n\n\t\t\t\t\t\tif (steps.length > 0) {\n\t\t\t\t\t\t\t// Include tool call information in the conversation context\n\t\t\t\t\t\t\tconst toolContext = steps\n\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\t(step) =>\n\t\t\t\t\t\t\t\t\t\t`Tool: ${step.action.tool}, Input: ${JSON.stringify(step.action.toolInput)}, Result: ${step.observation}`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t.join('; ');\n\t\t\t\t\t\t\tfullOutput = `[Used tools: ${toolContext}] ${fullOutput}`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tawait memory.saveContext({ input }, { output: fullOutput });\n\t\t\t\t\t}\n\t\t\t\t\t// Include intermediate steps if requested\n\t\t\t\t\tconst result = { ...modelResponse.returnValues };\n\t\t\t\t\tif (options.returnIntermediateSteps && steps.length > 0) {\n\t\t\t\t\t\tresult.intermediateSteps = steps;\n\t\t\t\t\t}\n\t\t\t\t\treturn result;\n\t\t\t\t}\n\n\t\t\t\tconst currentIteration = (response?.metadata?.iterationCount ?? 0) + 1;\n\n\t\t\t\t// Check if we've exceeded maxIterations\n\t\t\t\tif (options.maxIterations && currentIteration > options.maxIterations) {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), 'Maximum iterations reached');\n\t\t\t\t}\n\n\t\t\t\tconst actions = await createEngineRequests(modelResponse, itemIndex, tools);\n\n\t\t\t\treturn {\n\t\t\t\t\tactions,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tpreviousRequests: buildSteps(response, itemIndex),\n\t\t\t\t\t\titerationCount: currentIteration,\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t});\n\n\t\tconst batchResults = await Promise.allSettled(batchPromises);\n\t\t// This is only used to check if the output parser is connected\n\t\t// so we can parse the output if needed. Actual output parsing is done in the loop above\n\t\tconst outputParser = await getOptionalOutputParser(this, 0);\n\t\tbatchResults.forEach((result, index) => {\n\t\t\tconst itemIndex = i + index;\n\t\t\tif (result.status === 'rejected') {\n\t\t\t\tconst error = result.reason as Error;\n\t\t\t\tif (this.continueOnFail()) {\n\t\t\t\t\treturnData.push({\n\t\t\t\t\t\tjson: { error: error.message },\n\t\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t\t} as INodeExecutionData);\n\t\t\t\t\treturn;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new NodeOperationError(this.getNode(), error);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst response = result.value;\n\n\t\t\tif ('actions' in response) {\n\t\t\t\tif (!request) {\n\t\t\t\t\trequest = {\n\t\t\t\t\t\tactions: response.actions,\n\t\t\t\t\t\tmetadata: response.metadata,\n\t\t\t\t\t};\n\t\t\t\t} else {\n\t\t\t\t\trequest.actions.push(...response.actions);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If memory and outputParser are connected, parse the output.\n\t\t\tif (memory && outputParser) {\n\t\t\t\tconst parsedOutput = jsonParse<{ output: Record<string, unknown> }>(\n\t\t\t\t\tresponse.output as string,\n\t\t\t\t);\n\t\t\t\tresponse.output = parsedOutput?.output ?? parsedOutput;\n\t\t\t}\n\n\t\t\t// Omit internal keys before returning the result.\n\t\t\tconst itemResult: INodeExecutionData = {\n\t\t\t\tjson: omit(\n\t\t\t\t\tresponse,\n\t\t\t\t\t'system_message',\n\t\t\t\t\t'formatting_instructions',\n\t\t\t\t\t'input',\n\t\t\t\t\t'chat_history',\n\t\t\t\t\t'agent_scratchpad',\n\t\t\t\t),\n\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t};\n\n\t\t\treturnData.push(itemResult);\n\t\t});\n\n\t\tif (i + batchSize < items.length && delayBetweenBatches > 0) {\n\t\t\tawait sleep(delayBetweenBatches);\n\t\t}\n\t}\n\t// Check if we have any Request objects (tool calls)\n\tif (request) {\n\t\treturn request;\n\t}\n\n\t// Otherwise return execution data\n\treturn [returnData];\n}\nasync function loadChatHistory(\n\tmemory: BaseChatMemory,\n\tmodel: BaseChatModel,\n\tmaxTokensFromMemory?: number,\n): Promise<BaseMessage[]> {\n\tconst memoryVariables = await memory.loadMemoryVariables({});\n\tlet chatHistory = memoryVariables['chat_history'] as BaseMessage[];\n\n\tif (maxTokensFromMemory) {\n\t\tchatHistory = await trimMessages(chatHistory, {\n\t\t\tstrategy: 'last',\n\t\t\tmaxTokens: maxTokensFromMemory,\n\t\t\ttokenCounter: model,\n\t\t\tincludeSystem: true,\n\t\t\tstartOn: 'human',\n\t\t\tallowPartial: true,\n\t\t});\n\t}\n\n\treturn chatHistory;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAAwC;AAGxC,uBAAiC;AACjC,oBAAmE;AAGnE,kBAAiB;AACjB,0BAMO;AAUP,yBAAmB;AAEnB,qBAAqC;AACrC,6BAGO;AAEP,oBAQO;AACP,oBAA+B;AAW/B,eAAe,qBACd,WACA,WACA,OACC;AACD,SAAO,UAAU,IAAI,CAAC,aAAa;AAElC,UAAM,YAAY,MAAM,KAAK,CAAC,SAAS,KAAK,SAAS,SAAS,IAAI;AAElE,QAAI,CAAC,UAAW;AAEhB,UAAM,WAAW,UAAU,UAAU;AAGrC,UAAM,QAAQ,UAAU,UAAU,gBAC/B,EAAE,GAAG,SAAS,WAAW,MAAM,SAAS,KAAK,IAC7C,SAAS;AAEZ,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA,MAAM,wCAAoB;AAAA,MAC1B,IAAI,SAAS;AAAA,MACb,UAAU;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAAA,EACD,CAAC;AACF;AAKA,SAAS,oBACR,OACA,OACA,QACA,UACA,cACA,QACA,eACC;AACD,QAAM,YAAQ,sCAAuB;AAAA,IACpC,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA,gBAAgB;AAAA,EACjB,CAAC;AAED,MAAI;AACJ,MAAI,eAAe;AAClB,wBAAgB,sCAAuB;AAAA,MACtC,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,IACjB,CAAC;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,QACA,OACA,qBACyB;AACzB,QAAM,kBAAkB,MAAM,OAAO,oBAAoB,CAAC,CAAC;AAC3D,MAAI,cAAc,gBAAgB,cAAc;AAEhD,MAAI,qBAAqB;AACxB,kBAAc,UAAM,8BAAa,aAAa;AAAA,MAC7C,UAAU;AAAA,MACV,WAAW;AAAA,MACX,cAAc;AAAA,MACd,eAAe;AAAA,MACf,SAAS;AAAA,MACT,cAAc;AAAA,IACf,CAAC;AAAA,EACF;AAEA,SAAO;AACR;","names":["step","assert","outputParser","response","omit"]}
@@ -159,8 +159,8 @@ class LmChatAnthropic {
159
159
  type: "resourceLocator",
160
160
  default: {
161
161
  mode: "list",
162
- value: "claude-sonnet-4-20250514",
163
- cachedResultName: "Claude 4 Sonnet"
162
+ value: "claude-sonnet-4-5-20250929",
163
+ cachedResultName: "Claude Sonnet 4.5"
164
164
  },
165
165
  required: true,
166
166
  modes: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts"],"sourcesContent":["import { ChatAnthropic } from '@langchain/anthropic';\nimport type { LLMResult } from '@langchain/core/outputs';\nimport { getProxyAgent } from '@utils/httpProxyAgent';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\nimport {\n\tNodeConnectionTypes,\n\ttype INodePropertyOptions,\n\ttype INodeProperties,\n\ttype ISupplyDataFunctions,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';\nimport { N8nLlmTracing } from '../N8nLlmTracing';\nimport { searchModels } from './methods/searchModels';\n\nconst modelField: INodeProperties = {\n\tdisplayName: 'Model',\n\tname: 'model',\n\ttype: 'options',\n\t// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items\n\toptions: [\n\t\t{\n\t\t\tname: 'Claude 3.5 Sonnet(20241022)',\n\t\t\tvalue: 'claude-3-5-sonnet-20241022',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Opus(20240229)',\n\t\t\tvalue: 'claude-3-opus-20240229',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3.5 Sonnet(20240620)',\n\t\t\tvalue: 'claude-3-5-sonnet-20240620',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Sonnet(20240229)',\n\t\t\tvalue: 'claude-3-sonnet-20240229',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3.5 Haiku(20241022)',\n\t\t\tvalue: 'claude-3-5-haiku-20241022',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Haiku(20240307)',\n\t\t\tvalue: 'claude-3-haiku-20240307',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude 2',\n\t\t\tvalue: 'claude-2',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude 2.1',\n\t\t\tvalue: 'claude-2.1',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude Instant 1.2',\n\t\t\tvalue: 'claude-instant-1.2',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude Instant 1',\n\t\t\tvalue: 'claude-instant-1',\n\t\t},\n\t],\n\tdescription:\n\t\t'The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.',\n\tdefault: 'claude-2',\n};\n\nconst MIN_THINKING_BUDGET = 1024;\nconst DEFAULT_MAX_TOKENS = 4096;\nexport class LmChatAnthropic implements INodeType {\n\tmethods = {\n\t\tlistSearch: {\n\t\t\tsearchModels,\n\t\t},\n\t};\n\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Anthropic Chat Model',\n\n\t\tname: 'lmChatAnthropic',\n\t\ticon: 'file:anthropic.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdefaultVersion: 1.3,\n\t\tdescription: 'Language Model Anthropic',\n\t\tdefaults: {\n\t\t\tname: 'Anthropic Chat Model',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Language Models', 'Root Nodes'],\n\t\t\t\t'Language Models': ['Chat Models (Recommended)'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatanthropic/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\talias: ['claude', 'sonnet', 'opus'],\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiLanguageModel],\n\t\toutputNames: ['Model'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'anthropicApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiChain]),\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdefault: 'claude-3-sonnet-20240229',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdefault: 'claude-3-5-sonnet-20240620',\n\t\t\t\toptions: (modelField.options ?? []).filter(\n\t\t\t\t\t(o): o is INodePropertyOptions => 'name' in o && !o.name.toString().startsWith('LEGACY'),\n\t\t\t\t),\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'resourceLocator',\n\t\t\t\tdefault: {\n\t\t\t\t\tmode: 'list',\n\t\t\t\t\tvalue: 'claude-sonnet-4-20250514',\n\t\t\t\t\tcachedResultName: 'Claude 4 Sonnet',\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t\tmodes: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'From List',\n\t\t\t\t\t\tname: 'list',\n\t\t\t\t\t\ttype: 'list',\n\t\t\t\t\t\tplaceholder: 'Select a model...',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tsearchListMethod: 'searchModels',\n\t\t\t\t\t\t\tsearchable: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'ID',\n\t\t\t\t\t\tname: 'id',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tplaceholder: 'Claude Sonnet',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdescription:\n\t\t\t\t\t'The model. Choose from the list, or specify an ID. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.3 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Maximum Number of Tokens',\n\t\t\t\t\t\tname: 'maxTokensToSample',\n\t\t\t\t\t\tdefault: DEFAULT_MAX_TOKENS,\n\t\t\t\t\t\tdescription: 'The maximum number of tokens to generate in the completion',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Sampling Temperature',\n\t\t\t\t\t\tname: 'temperature',\n\t\t\t\t\t\tdefault: 0.7,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top K',\n\t\t\t\t\t\tname: 'topK',\n\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: -1, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Used to remove \"long tail\" low probability responses. Defaults to -1, which disables it.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top P',\n\t\t\t\t\t\tname: 'topP',\n\t\t\t\t\t\tdefault: 1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Enable Thinking',\n\t\t\t\t\t\tname: 'thinking',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription: 'Whether to enable thinking mode for the model',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Thinking Budget (Tokens)',\n\t\t\t\t\t\tname: 'thinkingBudget',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdefault: MIN_THINKING_BUDGET,\n\t\t\t\t\t\tdescription: 'The maximum number of tokens to use for thinking',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<{\n\t\t\turl?: string;\n\t\t\tapiKey?: string;\n\t\t\theader?: boolean;\n\t\t\theaderName?: string;\n\t\t\theaderValue?: string;\n\t\t}>('anthropicApi');\n\t\tconst baseURL = credentials.url ?? 'https://api.anthropic.com';\n\t\tconst version = this.getNode().typeVersion;\n\t\tconst modelName =\n\t\t\tversion >= 1.3\n\t\t\t\t? (this.getNodeParameter('model.value', itemIndex) as string)\n\t\t\t\t: (this.getNodeParameter('model', itemIndex) as string);\n\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\tmaxTokensToSample?: number;\n\t\t\ttemperature: number;\n\t\t\ttopK?: number;\n\t\t\ttopP?: number;\n\t\t\tthinking?: boolean;\n\t\t\tthinkingBudget?: number;\n\t\t};\n\t\tlet invocationKwargs = {};\n\n\t\tconst tokensUsageParser = (result: LLMResult) => {\n\t\t\tconst usage = (result?.llmOutput?.usage as {\n\t\t\t\tinput_tokens: number;\n\t\t\t\toutput_tokens: number;\n\t\t\t}) ?? {\n\t\t\t\tinput_tokens: 0,\n\t\t\t\toutput_tokens: 0,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tcompletionTokens: usage.output_tokens,\n\t\t\t\tpromptTokens: usage.input_tokens,\n\t\t\t\ttotalTokens: usage.input_tokens + usage.output_tokens,\n\t\t\t};\n\t\t};\n\n\t\tif (options.thinking) {\n\t\t\tinvocationKwargs = {\n\t\t\t\tthinking: {\n\t\t\t\t\ttype: 'enabled',\n\t\t\t\t\t// If thinking is enabled, we need to set a budget.\n\t\t\t\t\t// We fallback to 1024 as that is the minimum\n\t\t\t\t\tbudget_tokens: options.thinkingBudget ?? MIN_THINKING_BUDGET,\n\t\t\t\t},\n\t\t\t\t// The default Langchain max_tokens is -1 (no limit) but Anthropic requires a number\n\t\t\t\t// higher than budget_tokens\n\t\t\t\tmax_tokens: options.maxTokensToSample ?? DEFAULT_MAX_TOKENS,\n\t\t\t\t// These need to be unset when thinking is enabled.\n\t\t\t\t// Because the invocationKwargs will override the model options\n\t\t\t\t// we can pass options to the model and then override them here\n\t\t\t\ttop_k: undefined,\n\t\t\t\ttop_p: undefined,\n\t\t\t\ttemperature: undefined,\n\t\t\t};\n\t\t}\n\n\t\tconst clientOptions: {\n\t\t\tfetchOptions?: { dispatcher: any };\n\t\t\tdefaultHeaders?: Record<string, string>;\n\t\t} = {\n\t\t\tfetchOptions: {\n\t\t\t\tdispatcher: getProxyAgent(baseURL),\n\t\t\t},\n\t\t};\n\n\t\tif (\n\t\t\tcredentials.header &&\n\t\t\ttypeof credentials.headerName === 'string' &&\n\t\t\tcredentials.headerName &&\n\t\t\ttypeof credentials.headerValue === 'string'\n\t\t) {\n\t\t\tclientOptions.defaultHeaders = {\n\t\t\t\t[credentials.headerName]: credentials.headerValue,\n\t\t\t};\n\t\t}\n\n\t\tconst model = new ChatAnthropic({\n\t\t\tanthropicApiKey: credentials.apiKey,\n\t\t\tmodel: modelName,\n\t\t\tanthropicApiUrl: baseURL,\n\t\t\tmaxTokens: options.maxTokensToSample,\n\t\t\ttemperature: options.temperature,\n\t\t\ttopK: options.topK,\n\t\t\ttopP: options.topP,\n\t\t\tcallbacks: [new N8nLlmTracing(this, { tokensUsageParser })],\n\t\t\tonFailedAttempt: makeN8nLlmFailedAttemptHandler(this),\n\t\t\tinvocationKwargs,\n\t\t\tclientOptions,\n\t\t});\n\n\t\t// Some Anthropic models do not support Langchain default of -1 for topP so we need to unset it\n\t\tif (options.topP === undefined) {\n\t\t\tdelete model.topP;\n\t\t}\n\n\t\t// If topP is set to a value and temperature is not, unset default Langchain temperature\n\t\tif (options.topP !== undefined && options.temperature === undefined) {\n\t\t\tdelete model.temperature;\n\t\t}\n\n\t\treturn {\n\t\t\tresponse: model,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA8B;AAE9B,4BAA8B;AAC9B,0BAA6C;AAC7C,0BAQO;AAEP,wCAA+C;AAC/C,2BAA8B;AAC9B,0BAA6B;AAE7B,MAAM,aAA8B;AAAA,EACnC,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA;AAAA,EAEN,SAAS;AAAA,IACR;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MAC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AAA,MACd,WAAW,CAAC,IAAI,mCAAc,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAAA,MAC1D,qBAAiB,kEAA+B,IAAI;AAAA,MACpD;AAAA,MACA;AAAA,IACD,CAAC;AAGD,QAAI,QAAQ,SAAS,QAAW;AAC/B,aAAO,MAAM;AAAA,IACd;AAGA,QAAI,QAAQ,SAAS,UAAa,QAAQ,gBAAgB,QAAW;AACpE,aAAO,MAAM;AAAA,IACd;AAEA,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../nodes/llms/LMChatAnthropic/LmChatAnthropic.node.ts"],"sourcesContent":["import { ChatAnthropic } from '@langchain/anthropic';\nimport type { LLMResult } from '@langchain/core/outputs';\nimport { getProxyAgent } from '@utils/httpProxyAgent';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\nimport {\n\tNodeConnectionTypes,\n\ttype INodePropertyOptions,\n\ttype INodeProperties,\n\ttype ISupplyDataFunctions,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { makeN8nLlmFailedAttemptHandler } from '../n8nLlmFailedAttemptHandler';\nimport { N8nLlmTracing } from '../N8nLlmTracing';\nimport { searchModels } from './methods/searchModels';\n\nconst modelField: INodeProperties = {\n\tdisplayName: 'Model',\n\tname: 'model',\n\ttype: 'options',\n\t// eslint-disable-next-line n8n-nodes-base/node-param-options-type-unsorted-items\n\toptions: [\n\t\t{\n\t\t\tname: 'Claude 3.5 Sonnet(20241022)',\n\t\t\tvalue: 'claude-3-5-sonnet-20241022',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Opus(20240229)',\n\t\t\tvalue: 'claude-3-opus-20240229',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3.5 Sonnet(20240620)',\n\t\t\tvalue: 'claude-3-5-sonnet-20240620',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Sonnet(20240229)',\n\t\t\tvalue: 'claude-3-sonnet-20240229',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3.5 Haiku(20241022)',\n\t\t\tvalue: 'claude-3-5-haiku-20241022',\n\t\t},\n\t\t{\n\t\t\tname: 'Claude 3 Haiku(20240307)',\n\t\t\tvalue: 'claude-3-haiku-20240307',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude 2',\n\t\t\tvalue: 'claude-2',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude 2.1',\n\t\t\tvalue: 'claude-2.1',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude Instant 1.2',\n\t\t\tvalue: 'claude-instant-1.2',\n\t\t},\n\t\t{\n\t\t\tname: 'LEGACY: Claude Instant 1',\n\t\t\tvalue: 'claude-instant-1',\n\t\t},\n\t],\n\tdescription:\n\t\t'The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.',\n\tdefault: 'claude-2',\n};\n\nconst MIN_THINKING_BUDGET = 1024;\nconst DEFAULT_MAX_TOKENS = 4096;\nexport class LmChatAnthropic implements INodeType {\n\tmethods = {\n\t\tlistSearch: {\n\t\t\tsearchModels,\n\t\t},\n\t};\n\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Anthropic Chat Model',\n\n\t\tname: 'lmChatAnthropic',\n\t\ticon: 'file:anthropic.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdefaultVersion: 1.3,\n\t\tdescription: 'Language Model Anthropic',\n\t\tdefaults: {\n\t\t\tname: 'Anthropic Chat Model',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Language Models', 'Root Nodes'],\n\t\t\t\t'Language Models': ['Chat Models (Recommended)'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatanthropic/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\talias: ['claude', 'sonnet', 'opus'],\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiLanguageModel],\n\t\toutputNames: ['Model'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'anthropicApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiChain]),\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdefault: 'claude-3-sonnet-20240229',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...modelField,\n\t\t\t\tdefault: 'claude-3-5-sonnet-20240620',\n\t\t\t\toptions: (modelField.options ?? []).filter(\n\t\t\t\t\t(o): o is INodePropertyOptions => 'name' in o && !o.name.toString().startsWith('LEGACY'),\n\t\t\t\t),\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tname: 'model',\n\t\t\t\ttype: 'resourceLocator',\n\t\t\t\tdefault: {\n\t\t\t\t\tmode: 'list',\n\t\t\t\t\tvalue: 'claude-sonnet-4-5-20250929',\n\t\t\t\t\tcachedResultName: 'Claude Sonnet 4.5',\n\t\t\t\t},\n\t\t\t\trequired: true,\n\t\t\t\tmodes: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'From List',\n\t\t\t\t\t\tname: 'list',\n\t\t\t\t\t\ttype: 'list',\n\t\t\t\t\t\tplaceholder: 'Select a model...',\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\tsearchListMethod: 'searchModels',\n\t\t\t\t\t\t\tsearchable: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'ID',\n\t\t\t\t\t\tname: 'id',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tplaceholder: 'Claude Sonnet',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdescription:\n\t\t\t\t\t'The model. Choose from the list, or specify an ID. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.3 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdescription: 'Additional options to add',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Maximum Number of Tokens',\n\t\t\t\t\t\tname: 'maxTokensToSample',\n\t\t\t\t\t\tdefault: DEFAULT_MAX_TOKENS,\n\t\t\t\t\t\tdescription: 'The maximum number of tokens to generate in the completion',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Sampling Temperature',\n\t\t\t\t\t\tname: 'temperature',\n\t\t\t\t\t\tdefault: 0.7,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top K',\n\t\t\t\t\t\tname: 'topK',\n\t\t\t\t\t\tdefault: -1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: -1, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Used to remove \"long tail\" low probability responses. Defaults to -1, which disables it.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Top P',\n\t\t\t\t\t\tname: 'topP',\n\t\t\t\t\t\tdefault: 1,\n\t\t\t\t\t\ttypeOptions: { maxValue: 1, minValue: 0, numberPrecision: 1 },\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\thide: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Enable Thinking',\n\t\t\t\t\t\tname: 'thinking',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\tdescription: 'Whether to enable thinking mode for the model',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Thinking Budget (Tokens)',\n\t\t\t\t\t\tname: 'thinkingBudget',\n\t\t\t\t\t\ttype: 'number',\n\t\t\t\t\t\tdefault: MIN_THINKING_BUDGET,\n\t\t\t\t\t\tdescription: 'The maximum number of tokens to use for thinking',\n\t\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t\tthinking: [true],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<{\n\t\t\turl?: string;\n\t\t\tapiKey?: string;\n\t\t\theader?: boolean;\n\t\t\theaderName?: string;\n\t\t\theaderValue?: string;\n\t\t}>('anthropicApi');\n\t\tconst baseURL = credentials.url ?? 'https://api.anthropic.com';\n\t\tconst version = this.getNode().typeVersion;\n\t\tconst modelName =\n\t\t\tversion >= 1.3\n\t\t\t\t? (this.getNodeParameter('model.value', itemIndex) as string)\n\t\t\t\t: (this.getNodeParameter('model', itemIndex) as string);\n\n\t\tconst options = this.getNodeParameter('options', itemIndex, {}) as {\n\t\t\tmaxTokensToSample?: number;\n\t\t\ttemperature: number;\n\t\t\ttopK?: number;\n\t\t\ttopP?: number;\n\t\t\tthinking?: boolean;\n\t\t\tthinkingBudget?: number;\n\t\t};\n\t\tlet invocationKwargs = {};\n\n\t\tconst tokensUsageParser = (result: LLMResult) => {\n\t\t\tconst usage = (result?.llmOutput?.usage as {\n\t\t\t\tinput_tokens: number;\n\t\t\t\toutput_tokens: number;\n\t\t\t}) ?? {\n\t\t\t\tinput_tokens: 0,\n\t\t\t\toutput_tokens: 0,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tcompletionTokens: usage.output_tokens,\n\t\t\t\tpromptTokens: usage.input_tokens,\n\t\t\t\ttotalTokens: usage.input_tokens + usage.output_tokens,\n\t\t\t};\n\t\t};\n\n\t\tif (options.thinking) {\n\t\t\tinvocationKwargs = {\n\t\t\t\tthinking: {\n\t\t\t\t\ttype: 'enabled',\n\t\t\t\t\t// If thinking is enabled, we need to set a budget.\n\t\t\t\t\t// We fallback to 1024 as that is the minimum\n\t\t\t\t\tbudget_tokens: options.thinkingBudget ?? MIN_THINKING_BUDGET,\n\t\t\t\t},\n\t\t\t\t// The default Langchain max_tokens is -1 (no limit) but Anthropic requires a number\n\t\t\t\t// higher than budget_tokens\n\t\t\t\tmax_tokens: options.maxTokensToSample ?? DEFAULT_MAX_TOKENS,\n\t\t\t\t// These need to be unset when thinking is enabled.\n\t\t\t\t// Because the invocationKwargs will override the model options\n\t\t\t\t// we can pass options to the model and then override them here\n\t\t\t\ttop_k: undefined,\n\t\t\t\ttop_p: undefined,\n\t\t\t\ttemperature: undefined,\n\t\t\t};\n\t\t}\n\n\t\tconst clientOptions: {\n\t\t\tfetchOptions?: { dispatcher: any };\n\t\t\tdefaultHeaders?: Record<string, string>;\n\t\t} = {\n\t\t\tfetchOptions: {\n\t\t\t\tdispatcher: getProxyAgent(baseURL),\n\t\t\t},\n\t\t};\n\n\t\tif (\n\t\t\tcredentials.header &&\n\t\t\ttypeof credentials.headerName === 'string' &&\n\t\t\tcredentials.headerName &&\n\t\t\ttypeof credentials.headerValue === 'string'\n\t\t) {\n\t\t\tclientOptions.defaultHeaders = {\n\t\t\t\t[credentials.headerName]: credentials.headerValue,\n\t\t\t};\n\t\t}\n\n\t\tconst model = new ChatAnthropic({\n\t\t\tanthropicApiKey: credentials.apiKey,\n\t\t\tmodel: modelName,\n\t\t\tanthropicApiUrl: baseURL,\n\t\t\tmaxTokens: options.maxTokensToSample,\n\t\t\ttemperature: options.temperature,\n\t\t\ttopK: options.topK,\n\t\t\ttopP: options.topP,\n\t\t\tcallbacks: [new N8nLlmTracing(this, { tokensUsageParser })],\n\t\t\tonFailedAttempt: makeN8nLlmFailedAttemptHandler(this),\n\t\t\tinvocationKwargs,\n\t\t\tclientOptions,\n\t\t});\n\n\t\t// Some Anthropic models do not support Langchain default of -1 for topP so we need to unset it\n\t\tif (options.topP === undefined) {\n\t\t\tdelete model.topP;\n\t\t}\n\n\t\t// If topP is set to a value and temperature is not, unset default Langchain temperature\n\t\tif (options.topP !== undefined && options.temperature === undefined) {\n\t\t\tdelete model.temperature;\n\t\t}\n\n\t\treturn {\n\t\t\tresponse: model,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA8B;AAE9B,4BAA8B;AAC9B,0BAA6C;AAC7C,0BAQO;AAEP,wCAA+C;AAC/C,2BAA8B;AAC9B,0BAA6B;AAE7B,MAAM,aAA8B;AAAA,EACnC,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA;AAAA,EAEN,SAAS;AAAA,IACR;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EACA,aACC;AAAA,EACD,SAAS;AACV;AAEA,MAAM,sBAAsB;AAC5B,MAAM,qBAAq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AAQ,SAAS,UAAa,QAAQ,gBAAgB,QAAW;AACpE,aAAO,MAAM;AAAA,IACd;AAEA,WAAO;AAAA,MACN,UAAU;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
@@ -46,7 +46,7 @@ async function searchModels(filter) {
46
46
  });
47
47
  const { data: models = [] } = await openai.models.list();
48
48
  const url = baseURL && new URL(baseURL);
49
- const isCustomAPI = !!(url && url.hostname !== "api.openai.com");
49
+ const isCustomAPI = !!(url && !["api.openai.com", "ai-assistant.n8n.io"].includes(url.hostname));
50
50
  const filteredModels = models.filter((model) => {
51
51
  const includeModel = (0, import_modelFiltering.shouldIncludeModel)(model.id, isCustomAPI);
52
52
  if (!filter) return includeModel;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../nodes/llms/LMChatOpenAi/methods/loadModels.ts"],"sourcesContent":["import type { ILoadOptionsFunctions, INodeListSearchResult } from 'n8n-workflow';\nimport OpenAI from 'openai';\n\nimport { shouldIncludeModel } from '../../../vendors/OpenAi/helpers/modelFiltering';\nimport { getProxyAgent } from '@utils/httpProxyAgent';\n\nexport async function searchModels(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\tconst credentials = await this.getCredentials('openAiApi');\n\tconst baseURL =\n\t\t(this.getNodeParameter('options.baseURL', '') as string) ||\n\t\t(credentials.url as string) ||\n\t\t'https://api.openai.com/v1';\n\n\tconst openai = new OpenAI({\n\t\tbaseURL,\n\t\tapiKey: credentials.apiKey as string,\n\t\tfetchOptions: {\n\t\t\tdispatcher: getProxyAgent(baseURL),\n\t\t},\n\t});\n\tconst { data: models = [] } = await openai.models.list();\n\n\tconst url = baseURL && new URL(baseURL);\n\tconst isCustomAPI = !!(url && url.hostname !== 'api.openai.com');\n\n\tconst filteredModels = models.filter((model: { id: string }) => {\n\t\tconst includeModel = shouldIncludeModel(model.id, isCustomAPI);\n\n\t\tif (!filter) return includeModel;\n\n\t\treturn includeModel && model.id.toLowerCase().includes(filter.toLowerCase());\n\t});\n\n\tfilteredModels.sort((a, b) => a.id.localeCompare(b.id));\n\n\treturn {\n\t\tresults: filteredModels.map((model: { id: string }) => ({\n\t\t\tname: model.id,\n\t\t\tvalue: model.id,\n\t\t})),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAmB;AAEnB,4BAAmC;AACnC,4BAA8B;AAE9B,eAAsB,aAErB,QACiC;AACjC,QAAM,cAAc,MAAM,KAAK,eAAe,WAAW;AACzD,QAAM,UACJ,KAAK,iBAAiB,mBAAmB,EAAE,KAC3C,YAAY,OACb;AAED,QAAM,SAAS,IAAI,cAAAA,QAAO;AAAA,IACzB;AAAA,IACA,QAAQ,YAAY;AAAA,IACpB,cAAc;AAAA,MACb,gBAAY,qCAAc,OAAO;AAAA,IAClC;AAAA,EACD,CAAC;AACD,QAAM,EAAE,MAAM,SAAS,CAAC,EAAE,IAAI,MAAM,OAAO,OAAO,KAAK;AAEvD,QAAM,MAAM,WAAW,IAAI,IAAI,OAAO;AACtC,QAAM,cAAc,CAAC,EAAE,OAAO,IAAI,aAAa;AAE/C,QAAM,iBAAiB,OAAO,OAAO,CAAC,UAA0B;AAC/D,UAAM,mBAAe,0CAAmB,MAAM,IAAI,WAAW;AAE7D,QAAI,CAAC,OAAQ,QAAO;AAEpB,WAAO,gBAAgB,MAAM,GAAG,YAAY,EAAE,SAAS,OAAO,YAAY,CAAC;AAAA,EAC5E,CAAC;AAED,iBAAe,KAAK,CAAC,GAAG,MAAM,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC;AAEtD,SAAO;AAAA,IACN,SAAS,eAAe,IAAI,CAAC,WAA2B;AAAA,MACvD,MAAM,MAAM;AAAA,MACZ,OAAO,MAAM;AAAA,IACd,EAAE;AAAA,EACH;AACD;","names":["OpenAI"]}
1
+ {"version":3,"sources":["../../../../../nodes/llms/LMChatOpenAi/methods/loadModels.ts"],"sourcesContent":["import type { ILoadOptionsFunctions, INodeListSearchResult } from 'n8n-workflow';\nimport OpenAI from 'openai';\n\nimport { shouldIncludeModel } from '../../../vendors/OpenAi/helpers/modelFiltering';\nimport { getProxyAgent } from '@utils/httpProxyAgent';\n\nexport async function searchModels(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\tconst credentials = await this.getCredentials('openAiApi');\n\tconst baseURL =\n\t\t(this.getNodeParameter('options.baseURL', '') as string) ||\n\t\t(credentials.url as string) ||\n\t\t'https://api.openai.com/v1';\n\n\tconst openai = new OpenAI({\n\t\tbaseURL,\n\t\tapiKey: credentials.apiKey as string,\n\t\tfetchOptions: {\n\t\t\tdispatcher: getProxyAgent(baseURL),\n\t\t},\n\t});\n\tconst { data: models = [] } = await openai.models.list();\n\n\tconst url = baseURL && new URL(baseURL);\n\tconst isCustomAPI = !!(url && !['api.openai.com', 'ai-assistant.n8n.io'].includes(url.hostname));\n\n\tconst filteredModels = models.filter((model: { id: string }) => {\n\t\tconst includeModel = shouldIncludeModel(model.id, isCustomAPI);\n\n\t\tif (!filter) return includeModel;\n\n\t\treturn includeModel && model.id.toLowerCase().includes(filter.toLowerCase());\n\t});\n\n\tfilteredModels.sort((a, b) => a.id.localeCompare(b.id));\n\n\treturn {\n\t\tresults: filteredModels.map((model: { id: string }) => ({\n\t\t\tname: model.id,\n\t\t\tvalue: model.id,\n\t\t})),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAmB;AAEnB,4BAAmC;AACnC,4BAA8B;AAE9B,eAAsB,aAErB,QACiC;AACjC,QAAM,cAAc,MAAM,KAAK,eAAe,WAAW;AACzD,QAAM,UACJ,KAAK,iBAAiB,mBAAmB,EAAE,KAC3C,YAAY,OACb;AAED,QAAM,SAAS,IAAI,cAAAA,QAAO;AAAA,IACzB;AAAA,IACA,QAAQ,YAAY;AAAA,IACpB,cAAc;AAAA,MACb,gBAAY,qCAAc,OAAO;AAAA,IAClC;AAAA,EACD,CAAC;AACD,QAAM,EAAE,MAAM,SAAS,CAAC,EAAE,IAAI,MAAM,OAAO,OAAO,KAAK;AAEvD,QAAM,MAAM,WAAW,IAAI,IAAI,OAAO;AACtC,QAAM,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC,kBAAkB,qBAAqB,EAAE,SAAS,IAAI,QAAQ;AAE9F,QAAM,iBAAiB,OAAO,OAAO,CAAC,UAA0B;AAC/D,UAAM,mBAAe,0CAAmB,MAAM,IAAI,WAAW;AAE7D,QAAI,CAAC,OAAQ,QAAO;AAEpB,WAAO,gBAAgB,MAAM,GAAG,YAAY,EAAE,SAAS,OAAO,YAAY,CAAC;AAAA,EAC5E,CAAC;AAED,iBAAe,KAAK,CAAC,GAAG,MAAM,EAAE,GAAG,cAAc,EAAE,EAAE,CAAC;AAEtD,SAAO;AAAA,IACN,SAAS,eAAe,IAAI,CAAC,WAA2B;AAAA,MACvD,MAAM,MAAM;AAAA,MACZ,OAAO,MAAM;AAAA,IACd,EAAE;AAAA,EACH;AACD;","names":["OpenAI"]}
@@ -63,7 +63,14 @@ class ToolWorkflowV2 {
63
63
  continue;
64
64
  }
65
65
  const result = await tool.invoke(item.json);
66
- response.push(result);
66
+ if (Array.isArray(result)) {
67
+ response.push(...result);
68
+ } else {
69
+ response.push({
70
+ json: { response: result },
71
+ pairedItem: { item: itemIndex }
72
+ });
73
+ }
67
74
  }
68
75
  return [response];
69
76
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.ts"],"sourcesContent":["import type { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';\n\nimport type {\n\tINodeTypeBaseDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n\tINodeType,\n\tINodeTypeDescription,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n} from 'n8n-workflow';\nimport { nodeNameToToolName } from 'n8n-workflow';\n\nimport { localResourceMapping } from './methods';\nimport { WorkflowToolService } from './utils/WorkflowToolService';\nimport { versionDescription } from './versionDescription';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\tenableLogging: boolean,\n\titemIndex: number,\n): Promise<DynamicTool | DynamicStructuredTool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\tconst returnAllItems = typeVersion > 2;\n\n\tconst workflowToolService = new WorkflowToolService(ctx, { returnAllItems });\n\tconst name =\n\t\ttypeVersion <= 2.1 ? (ctx.getNodeParameter('name', 0) as string) : nodeNameToToolName(node);\n\tconst description = ctx.getNodeParameter('description', 0) as string;\n\n\treturn await workflowToolService.createTool({\n\t\tctx,\n\t\tname,\n\t\tdescription,\n\t\titemIndex,\n\t\tmanualLogging: enableLogging,\n\t});\n}\n\nexport class ToolWorkflowV2 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\t...versionDescription,\n\t\t};\n\t}\n\n\tmethods = {\n\t\tlocalResourceMapping,\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\treturn { response: await getTool(this, true, itemIndex) };\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst items = this.getInputData();\n\n\t\tconst response: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {\n\t\t\tconst item = items[itemIndex];\n\t\t\tconst tool = await getTool(this, false, itemIndex);\n\n\t\t\tif (item === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = await tool.invoke(item.json);\n\t\t\tresponse.push(result);\n\t\t}\n\n\t\treturn [response];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,0BAAmC;AAEnC,qBAAqC;AACrC,iCAAoC;AACpC,gCAAmC;AAEnC,eAAe,QACd,KACA,eACA,WAC+C;AAC/C,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AACxB,QAAM,iBAAiB,cAAc;AAErC,QAAM,sBAAsB,IAAI,+CAAoB,KAAK,EAAE,eAAe,CAAC;AAC3E,QAAM,OACL,eAAe,MAAO,IAAI,iBAAiB,QAAQ,CAAC,QAAe,wCAAmB,IAAI;AAC3F,QAAM,cAAc,IAAI,iBAAiB,eAAe,CAAC;AAEzD,SAAO,MAAM,oBAAoB,WAAW;AAAA,IAC3C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,EAChB,CAAC;AACF;AAEO,MAAM,eAAoC;AAAA,EAGhD,YAAY,iBAA2C;AAOvD,mBAAU;AAAA,MACT;AAAA,IACD;AARC,SAAK,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,GAAG;AAAA,IACJ;AAAA,EACD;AAAA,EAMA,MAAM,WAAuC,WAAwC;AACpF,WAAO,EAAE,UAAU,MAAM,QAAQ,MAAM,MAAM,SAAS,EAAE;AAAA,EACzD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,QAAQ,KAAK,aAAa;AAEhC,UAAM,WAAiC,CAAC;AACxC,aAAS,YAAY,GAAG,YAAY,KAAK,aAAa,EAAE,QAAQ,aAAa;AAC5E,YAAM,OAAO,MAAM,SAAS;AAC5B,YAAM,OAAO,MAAM,QAAQ,MAAM,OAAO,SAAS;AAEjD,UAAI,SAAS,QAAW;AACvB;AAAA,MACD;AACA,YAAM,SAAS,MAAM,KAAK,OAAO,KAAK,IAAI;AAC1C,eAAS,KAAK,MAAM;AAAA,IACrB;AAEA,WAAO,CAAC,QAAQ;AAAA,EACjB;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../../nodes/tools/ToolWorkflow/v2/ToolWorkflowV2.node.ts"],"sourcesContent":["import type { DynamicStructuredTool, DynamicTool } from '@langchain/core/tools';\n\nimport type {\n\tINodeTypeBaseDescription,\n\tISupplyDataFunctions,\n\tSupplyData,\n\tINodeType,\n\tINodeTypeDescription,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n} from 'n8n-workflow';\nimport { nodeNameToToolName } from 'n8n-workflow';\n\nimport { localResourceMapping } from './methods';\nimport { WorkflowToolService } from './utils/WorkflowToolService';\nimport { versionDescription } from './versionDescription';\n\nasync function getTool(\n\tctx: ISupplyDataFunctions | IExecuteFunctions,\n\tenableLogging: boolean,\n\titemIndex: number,\n): Promise<DynamicTool | DynamicStructuredTool> {\n\tconst node = ctx.getNode();\n\tconst { typeVersion } = node;\n\tconst returnAllItems = typeVersion > 2;\n\n\tconst workflowToolService = new WorkflowToolService(ctx, { returnAllItems });\n\tconst name =\n\t\ttypeVersion <= 2.1 ? (ctx.getNodeParameter('name', 0) as string) : nodeNameToToolName(node);\n\tconst description = ctx.getNodeParameter('description', 0) as string;\n\n\treturn await workflowToolService.createTool({\n\t\tctx,\n\t\tname,\n\t\tdescription,\n\t\titemIndex,\n\t\tmanualLogging: enableLogging,\n\t});\n}\n\nexport class ToolWorkflowV2 implements INodeType {\n\tdescription: INodeTypeDescription;\n\n\tconstructor(baseDescription: INodeTypeBaseDescription) {\n\t\tthis.description = {\n\t\t\t...baseDescription,\n\t\t\t...versionDescription,\n\t\t};\n\t}\n\n\tmethods = {\n\t\tlocalResourceMapping,\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\treturn { response: await getTool(this, true, itemIndex) };\n\t}\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst items = this.getInputData();\n\n\t\tconst response: INodeExecutionData[] = [];\n\t\tfor (let itemIndex = 0; itemIndex < this.getInputData().length; itemIndex++) {\n\t\t\tconst item = items[itemIndex];\n\t\t\tconst tool = await getTool(this, false, itemIndex);\n\n\t\t\tif (item === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst result = await tool.invoke(item.json);\n\n\t\t\t// When manualLogging is false, tool.invoke returns INodeExecutionData[]\n\t\t\t// We need to spread these into the response array\n\t\t\tif (Array.isArray(result)) {\n\t\t\t\tresponse.push(...result);\n\t\t\t} else {\n\t\t\t\t// Fallback for unexpected types (shouldn't happen with manualLogging=false)\n\t\t\t\tresponse.push({\n\t\t\t\t\tjson: { response: result },\n\t\t\t\t\tpairedItem: { item: itemIndex },\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn [response];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,0BAAmC;AAEnC,qBAAqC;AACrC,iCAAoC;AACpC,gCAAmC;AAEnC,eAAe,QACd,KACA,eACA,WAC+C;AAC/C,QAAM,OAAO,IAAI,QAAQ;AACzB,QAAM,EAAE,YAAY,IAAI;AACxB,QAAM,iBAAiB,cAAc;AAErC,QAAM,sBAAsB,IAAI,+CAAoB,KAAK,EAAE,eAAe,CAAC;AAC3E,QAAM,OACL,eAAe,MAAO,IAAI,iBAAiB,QAAQ,CAAC,QAAe,wCAAmB,IAAI;AAC3F,QAAM,cAAc,IAAI,iBAAiB,eAAe,CAAC;AAEzD,SAAO,MAAM,oBAAoB,WAAW;AAAA,IAC3C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe;AAAA,EAChB,CAAC;AACF;AAEO,MAAM,eAAoC;AAAA,EAGhD,YAAY,iBAA2C;AAOvD,mBAAU;AAAA,MACT;AAAA,IACD;AARC,SAAK,cAAc;AAAA,MAClB,GAAG;AAAA,MACH,GAAG;AAAA,IACJ;AAAA,EACD;AAAA,EAMA,MAAM,WAAuC,WAAwC;AACpF,WAAO,EAAE,UAAU,MAAM,QAAQ,MAAM,MAAM,SAAS,EAAE;AAAA,EACzD;AAAA,EAEA,MAAM,UAAkE;AACvE,UAAM,QAAQ,KAAK,aAAa;AAEhC,UAAM,WAAiC,CAAC;AACxC,aAAS,YAAY,GAAG,YAAY,KAAK,aAAa,EAAE,QAAQ,aAAa;AAC5E,YAAM,OAAO,MAAM,SAAS;AAC5B,YAAM,OAAO,MAAM,QAAQ,MAAM,OAAO,SAAS;AAEjD,UAAI,SAAS,QAAW;AACvB;AAAA,MACD;AACA,YAAM,SAAS,MAAM,KAAK,OAAO,KAAK,IAAI;AAI1C,UAAI,MAAM,QAAQ,MAAM,GAAG;AAC1B,iBAAS,KAAK,GAAG,MAAM;AAAA,MACxB,OAAO;AAEN,iBAAS,KAAK;AAAA,UACb,MAAM,EAAE,UAAU,OAAO;AAAA,UACzB,YAAY,EAAE,MAAM,UAAU;AAAA,QAC/B,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO,CAAC,QAAQ;AAAA,EACjB;AACD;","names":[]}
@@ -43,6 +43,7 @@ var import_mongodb2 = require("mongodb");
43
43
  var import_n8n_workflow = require("n8n-workflow");
44
44
  var import_sharedFields = require("../../../utils/sharedFields");
45
45
  var import_createVectorStoreNode = require("../shared/createVectorStoreNode/createVectorStoreNode");
46
+ var import_GenericFunctions = require("n8n-nodes-base/dist/nodes/MongoDb/GenericFunctions");
46
47
  const MONGODB_CREDENTIALS = "mongoDb";
47
48
  const MONGODB_COLLECTION_NAME = "mongoCollection";
48
49
  const VECTOR_INDEX_NAME = "vectorIndexName";
@@ -173,7 +174,8 @@ const mongoConfig = {
173
174
  };
174
175
  async function getMongoClient(context, version) {
175
176
  const credentials = await context.getCredentials(MONGODB_CREDENTIALS);
176
- const connectionString = credentials.connectionString;
177
+ const node = context.getNode();
178
+ const { connectionString } = (0, import_GenericFunctions.validateAndResolveMongoCredentials)(node, credentials);
177
179
  if (!mongoConfig.client || mongoConfig.connectionString !== connectionString || mongoConfig.nodeVersion !== version) {
178
180
  if (mongoConfig.client) {
179
181
  await mongoConfig.client.close();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.ts"],"sourcesContent":["import type { EmbeddingsInterface } from '@langchain/core/embeddings';\nimport { MongoDBAtlasVectorSearch, type MongoDBAtlasVectorSearchLibArgs } from '@langchain/mongodb';\nimport { MongoClient } from 'mongodb';\nimport {\n\ttype IDataObject,\n\ttype ILoadOptionsFunctions,\n\tNodeOperationError,\n\ttype INodeProperties,\n\ttype IExecuteFunctions,\n\ttype ISupplyDataFunctions,\n} from 'n8n-workflow';\nimport { metadataFilterField } from '@utils/sharedFields';\n\nimport { createVectorStoreNode } from '../shared/createVectorStoreNode/createVectorStoreNode';\n\n/**\n * Constants for the name of the credentials and Node parameters.\n */\nexport const MONGODB_CREDENTIALS = 'mongoDb';\nexport const MONGODB_COLLECTION_NAME = 'mongoCollection';\nexport const VECTOR_INDEX_NAME = 'vectorIndexName';\nexport const EMBEDDING_NAME = 'embedding';\nexport const METADATA_FIELD_NAME = 'metadata_field';\nexport const PRE_FILTER_NAME = 'preFilter';\nexport const POST_FILTER_NAME = 'postFilterPipeline';\n\nconst mongoCollectionRLC: INodeProperties = {\n\tdisplayName: 'MongoDB Collection',\n\tname: MONGODB_COLLECTION_NAME,\n\ttype: 'resourceLocator',\n\tdefault: { mode: 'list', value: '' },\n\trequired: true,\n\tmodes: [\n\t\t{\n\t\t\tdisplayName: 'From List',\n\t\t\tname: 'list',\n\t\t\ttype: 'list',\n\t\t\ttypeOptions: {\n\t\t\t\tsearchListMethod: 'mongoCollectionSearch', // Method to fetch collections\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tdisplayName: 'Name',\n\t\t\tname: 'name',\n\t\t\ttype: 'string',\n\t\t\tplaceholder: 'e.g. my_collection',\n\t\t},\n\t],\n};\n\nconst vectorIndexName: INodeProperties = {\n\tdisplayName: 'Vector Index Name',\n\tname: VECTOR_INDEX_NAME,\n\ttype: 'string',\n\tdefault: '',\n\tdescription: 'The name of the vector index',\n\trequired: true,\n};\n\nconst embeddingField: INodeProperties = {\n\tdisplayName: 'Embedding',\n\tname: EMBEDDING_NAME,\n\ttype: 'string',\n\tdefault: 'embedding',\n\tdescription: 'The field with the embedding array',\n\trequired: true,\n};\n\nconst metadataField: INodeProperties = {\n\tdisplayName: 'Metadata Field',\n\tname: METADATA_FIELD_NAME,\n\ttype: 'string',\n\tdefault: 'text',\n\tdescription: 'The text field of the raw data',\n\trequired: true,\n};\n\nconst sharedFields: INodeProperties[] = [\n\tmongoCollectionRLC,\n\tembeddingField,\n\tmetadataField,\n\tvectorIndexName,\n];\n\nconst mongoNamespaceField: INodeProperties = {\n\tdisplayName: 'Namespace',\n\tname: 'namespace',\n\ttype: 'string',\n\tdescription: 'Logical partition for documents. Uses metadata.namespace field for filtering.',\n\tdefault: '',\n};\n\nconst preFilterField: INodeProperties = {\n\tdisplayName: 'Pre Filter',\n\tname: PRE_FILTER_NAME,\n\ttype: 'json',\n\ttypeOptions: {\n\t\talwaysOpenEditWindow: true,\n\t},\n\tdefault: '',\n\tplaceholder: '{ \"key\": \"value\" }',\n\thint: 'This is a filter applied in the $vectorSearch stage <a href=\"https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#atlas-vector-search-pre-filter\">here</a>',\n\trequired: true,\n\tdescription: 'MongoDB Atlas Vector Search pre-filter',\n};\n\nconst postFilterField: INodeProperties = {\n\tdisplayName: 'Post Filter Pipeline',\n\tname: POST_FILTER_NAME,\n\ttype: 'json',\n\ttypeOptions: {\n\t\talwaysOpenEditWindow: true,\n\t},\n\tdefault: '',\n\tplaceholder: '[{ \"$match\": { \"$gt\": \"1950-01-01\" }, ... }]',\n\thint: 'Learn more about aggregation pipeline <a href=\"https://docs.mongodb.com/manual/core/aggregation-pipeline/\">here</a>',\n\trequired: true,\n\tdescription: 'MongoDB aggregation pipeline in JSON format',\n};\n\nconst retrieveFields: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tplaceholder: 'Add Option',\n\t\tdefault: {},\n\t\toptions: [mongoNamespaceField, metadataFilterField, preFilterField, postFilterField],\n\t},\n];\n\nconst insertFields: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tplaceholder: 'Add Option',\n\t\tdefault: {},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Clear Namespace',\n\t\t\t\tname: 'clearNamespace',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t\tdescription: 'Whether to clear documents in the namespace before inserting new data',\n\t\t\t},\n\t\t\tmongoNamespaceField,\n\t\t],\n\t},\n];\n\nexport const mongoConfig = {\n\tclient: null as MongoClient | null,\n\tconnectionString: '',\n\tnodeVersion: 0,\n};\n\n/**\n * Type used for cleaner, more intentional typing.\n */\ntype IFunctionsContext = IExecuteFunctions | ISupplyDataFunctions | ILoadOptionsFunctions;\n\n/**\n * Get the mongo client.\n * @param context - The context.\n * @returns the MongoClient for the node.\n */\nexport async function getMongoClient(context: any, version: number) {\n\tconst credentials = await context.getCredentials(MONGODB_CREDENTIALS);\n\tconst connectionString = credentials.connectionString as string;\n\tif (\n\t\t!mongoConfig.client ||\n\t\tmongoConfig.connectionString !== connectionString ||\n\t\tmongoConfig.nodeVersion !== version\n\t) {\n\t\tif (mongoConfig.client) {\n\t\t\tawait mongoConfig.client.close();\n\t\t}\n\n\t\tmongoConfig.connectionString = connectionString;\n\t\tmongoConfig.nodeVersion = version;\n\t\tmongoConfig.client = new MongoClient(connectionString, {\n\t\t\tappName: 'devrel.integration.n8n_vector_integ',\n\t\t\tdriverInfo: {\n\t\t\t\tname: 'n8n_vector',\n\t\t\t\tversion: version.toString(),\n\t\t\t},\n\t\t});\n\t\tawait mongoConfig.client.connect();\n\t}\n\treturn mongoConfig.client;\n}\n\n/**\n * Get the database object from the MongoClient by the configured name.\n * @param context - The context.\n * @returns the Db object.\n */\nexport async function getDatabase(context: IFunctionsContext, client: MongoClient) {\n\tconst credentials = await context.getCredentials(MONGODB_CREDENTIALS);\n\treturn client.db(credentials.database as string);\n}\n\n/**\n * Get all the collection in the database.\n * @param this The load options context.\n * @returns The list of collections.\n */\nexport async function getCollections(this: ILoadOptionsFunctions) {\n\ttry {\n\t\tconst client = await getMongoClient(this, this.getNode().typeVersion);\n\t\tconst db = await getDatabase(this, client);\n\t\tconst collections = await db.listCollections().toArray();\n\t\tconst results = collections.map((collection) => ({\n\t\t\tname: collection.name,\n\t\t\tvalue: collection.name,\n\t\t}));\n\n\t\treturn { results };\n\t} catch (error) {\n\t\tthrow new NodeOperationError(this.getNode(), `Error: ${error.message}`);\n\t}\n}\n\n/**\n * Get a parameter from the context.\n * @param key - The key of the parameter.\n * @param context - The context.\n * @param itemIndex - The index.\n * @returns The value.\n */\nexport function getParameter(key: string, context: IFunctionsContext, itemIndex: number): string {\n\tconst value = context.getNodeParameter(key, itemIndex, '', {\n\t\textractValue: true,\n\t}) as string;\n\tif (typeof value !== 'string') {\n\t\tthrow new NodeOperationError(context.getNode(), `Parameter ${key} must be a string`);\n\t}\n\treturn value;\n}\n\nexport const getCollectionName = getParameter.bind(null, MONGODB_COLLECTION_NAME);\nexport const getVectorIndexName = getParameter.bind(null, VECTOR_INDEX_NAME);\nexport const getEmbeddingFieldName = getParameter.bind(null, EMBEDDING_NAME);\nexport const getMetadataFieldName = getParameter.bind(null, METADATA_FIELD_NAME);\n\nexport function getFilterValue<T>(\n\tname: string,\n\tcontext: IExecuteFunctions | ISupplyDataFunctions,\n\titemIndex: number,\n): T | undefined {\n\tconst options: IDataObject = context.getNodeParameter('options', itemIndex, {});\n\n\tif (options[name]) {\n\t\tif (typeof options[name] === 'string') {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(options[name]);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription: `Could not parse JSON for ${name}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthrow new NodeOperationError(context.getNode(), 'Error: No JSON string provided.', {\n\t\t\titemIndex,\n\t\t\tdescription: `Could not parse JSON for ${name}`,\n\t\t});\n\t}\n\n\treturn undefined;\n}\n\nclass ExtendedMongoDBAtlasVectorSearch extends MongoDBAtlasVectorSearch {\n\tpreFilter: IDataObject;\n\tpostFilterPipeline?: IDataObject[];\n\n\tconstructor(\n\t\tembeddings: EmbeddingsInterface,\n\t\toptions: MongoDBAtlasVectorSearchLibArgs,\n\t\tpreFilter: IDataObject,\n\t\tpostFilterPipeline?: IDataObject[],\n\t) {\n\t\tsuper(embeddings, options);\n\t\tthis.preFilter = preFilter;\n\t\tthis.postFilterPipeline = postFilterPipeline;\n\t}\n\n\tasync similaritySearchVectorWithScore(query: number[], k: number) {\n\t\tconst mergedFilter: MongoDBAtlasVectorSearch['FilterType'] = {\n\t\t\tpreFilter: this.preFilter,\n\t\t\tpostFilterPipeline: this.postFilterPipeline,\n\t\t};\n\t\treturn await super.similaritySearchVectorWithScore(query, k, mergedFilter);\n\t}\n}\n\nexport class VectorStoreMongoDBAtlas extends createVectorStoreNode({\n\tmeta: {\n\t\tdisplayName: 'MongoDB Atlas Vector Store',\n\t\tname: 'vectorStoreMongoDBAtlas',\n\t\tdescription: 'Work with your data in MongoDB Atlas Vector Store',\n\t\ticon: { light: 'file:mongodb.svg', dark: 'file:mongodb.dark.svg' },\n\t\tdocsUrl:\n\t\t\t'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoremongodbatlas/',\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'mongoDb',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toperationModes: ['load', 'insert', 'retrieve', 'update', 'retrieve-as-tool'],\n\t},\n\tmethods: { listSearch: { mongoCollectionSearch: getCollections } },\n\tretrieveFields,\n\tloadFields: retrieveFields,\n\tinsertFields,\n\tsharedFields,\n\tasync getVectorStoreClient(context, _filter, embeddings, itemIndex) {\n\t\ttry {\n\t\t\tconst client = await getMongoClient(context, context.getNode().typeVersion);\n\t\t\tconst db = await getDatabase(context, client);\n\t\t\tconst collectionName = getCollectionName(context, itemIndex);\n\t\t\tconst mongoVectorIndexName = getVectorIndexName(context, itemIndex);\n\t\t\tconst embeddingFieldName = getEmbeddingFieldName(context, itemIndex);\n\t\t\tconst metadataFieldName = getMetadataFieldName(context, itemIndex);\n\n\t\t\tconst collection = db.collection(collectionName);\n\n\t\t\t// test index exists\n\t\t\tconst indexes = await collection.listSearchIndexes().toArray();\n\n\t\t\tconst indexExists = indexes.some((index) => index.name === mongoVectorIndexName);\n\n\t\t\tif (!indexExists) {\n\t\t\t\tthrow new NodeOperationError(context.getNode(), `Index ${mongoVectorIndexName} not found`, {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription: 'Please check that the index exists in your collection',\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst preFilter = getFilterValue<IDataObject>(PRE_FILTER_NAME, context, itemIndex);\n\t\t\tconst postFilterPipeline = getFilterValue<IDataObject[]>(\n\t\t\t\tPOST_FILTER_NAME,\n\t\t\t\tcontext,\n\t\t\t\titemIndex,\n\t\t\t);\n\n\t\t\treturn new ExtendedMongoDBAtlasVectorSearch(\n\t\t\t\tembeddings,\n\t\t\t\t{\n\t\t\t\t\tcollection,\n\t\t\t\t\tindexName: mongoVectorIndexName, // Default index name\n\t\t\t\t\ttextKey: metadataFieldName, // Field containing raw text\n\t\t\t\t\tembeddingKey: embeddingFieldName, // Field containing embeddings\n\t\t\t\t},\n\t\t\t\tpreFilter ?? {},\n\t\t\t\tpostFilterPipeline,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (error instanceof NodeOperationError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\titemIndex,\n\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t});\n\t\t}\n\t},\n\tasync populateVectorStore(context, embeddings, documents, itemIndex) {\n\t\ttry {\n\t\t\tconst client = await getMongoClient(context, context.getNode().typeVersion);\n\t\t\tconst db = await getDatabase(context, client);\n\t\t\tconst collectionName = getCollectionName(context, itemIndex);\n\t\t\tconst mongoVectorIndexName = getVectorIndexName(context, itemIndex);\n\t\t\tconst embeddingFieldName = getEmbeddingFieldName(context, itemIndex);\n\t\t\tconst metadataFieldName = getMetadataFieldName(context, itemIndex);\n\n\t\t\t// Check if collection exists\n\t\t\tconst collections = await db.listCollections({ name: collectionName }).toArray();\n\t\t\tif (collections.length === 0) {\n\t\t\t\tawait db.createCollection(collectionName);\n\t\t\t}\n\t\t\tconst collection = db.collection(collectionName);\n\t\t\tawait ExtendedMongoDBAtlasVectorSearch.fromDocuments(documents, embeddings, {\n\t\t\t\tcollection,\n\t\t\t\tindexName: mongoVectorIndexName, // Default index name\n\t\t\t\ttextKey: metadataFieldName, // Field containing raw text\n\t\t\t\tembeddingKey: embeddingFieldName, // Field containing embeddings\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\titemIndex,\n\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t});\n\t\t}\n\t},\n}) {}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA+E;AAC/E,IAAAA,kBAA4B;AAC5B,0BAOO;AACP,0BAAoC;AAEpC,mCAAsC;AAK/B,MAAM,sBAAsB;AAC5B,MAAM,0BAA0B;AAChC,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AACvB,MAAM,sBAAsB;AAC5B,MAAM,kBAAkB;AACxB,MAAM,mBAAmB;AAEhC,MAAM,qBAAsC;AAAA,EAC3C,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA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EAAE,MAAM,eAAe,CAAC,EAAE,QAAQ;AAC/E,UAAI,YAAY,WAAW,GAAG;AAC7B,cAAM,GAAG,iBAAiB,cAAc;AAAA,MACzC;AACA,YAAM,aAAa,GAAG,WAAW,cAAc;AAC/C,YAAM,iCAAiC,cAAc,WAAW,YAAY;AAAA,QAC3E;AAAA,QACA,WAAW;AAAA;AAAA,QACX,SAAS;AAAA;AAAA,QACT,cAAc;AAAA;AAAA,MACf,CAAC;AAAA,IACF,SAAS,OAAO;AACf,YAAM,IAAI,uCAAmB,QAAQ,QAAQ,GAAG,UAAU,MAAM,OAAO,IAAI;AAAA,QAC1E;AAAA,QACA,aAAa;AAAA,MACd,CAAC;AAAA,IACF;AAAA,EACD;AACD,CAAC,EAAE;AAAC;","names":["import_mongodb"]}
1
+ {"version":3,"sources":["../../../../nodes/vector_store/VectorStoreMongoDBAtlas/VectorStoreMongoDBAtlas.node.ts"],"sourcesContent":["import type { EmbeddingsInterface } from '@langchain/core/embeddings';\nimport { MongoDBAtlasVectorSearch, type MongoDBAtlasVectorSearchLibArgs } from '@langchain/mongodb';\nimport { MongoClient } from 'mongodb';\nimport {\n\ttype IDataObject,\n\ttype ILoadOptionsFunctions,\n\tNodeOperationError,\n\ttype INodeProperties,\n\ttype IExecuteFunctions,\n\ttype ISupplyDataFunctions,\n} from 'n8n-workflow';\nimport { metadataFilterField } from '@utils/sharedFields';\n\nimport { createVectorStoreNode } from '../shared/createVectorStoreNode/createVectorStoreNode';\n\nimport { validateAndResolveMongoCredentials } from 'n8n-nodes-base/dist/nodes/MongoDb/GenericFunctions';\n\n/**\n * Constants for the name of the credentials and Node parameters.\n */\nexport const MONGODB_CREDENTIALS = 'mongoDb';\nexport const MONGODB_COLLECTION_NAME = 'mongoCollection';\nexport const VECTOR_INDEX_NAME = 'vectorIndexName';\nexport const EMBEDDING_NAME = 'embedding';\nexport const METADATA_FIELD_NAME = 'metadata_field';\nexport const PRE_FILTER_NAME = 'preFilter';\nexport const POST_FILTER_NAME = 'postFilterPipeline';\n\nconst mongoCollectionRLC: INodeProperties = {\n\tdisplayName: 'MongoDB Collection',\n\tname: MONGODB_COLLECTION_NAME,\n\ttype: 'resourceLocator',\n\tdefault: { mode: 'list', value: '' },\n\trequired: true,\n\tmodes: [\n\t\t{\n\t\t\tdisplayName: 'From List',\n\t\t\tname: 'list',\n\t\t\ttype: 'list',\n\t\t\ttypeOptions: {\n\t\t\t\tsearchListMethod: 'mongoCollectionSearch', // Method to fetch collections\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tdisplayName: 'Name',\n\t\t\tname: 'name',\n\t\t\ttype: 'string',\n\t\t\tplaceholder: 'e.g. my_collection',\n\t\t},\n\t],\n};\n\nconst vectorIndexName: INodeProperties = {\n\tdisplayName: 'Vector Index Name',\n\tname: VECTOR_INDEX_NAME,\n\ttype: 'string',\n\tdefault: '',\n\tdescription: 'The name of the vector index',\n\trequired: true,\n};\n\nconst embeddingField: INodeProperties = {\n\tdisplayName: 'Embedding',\n\tname: EMBEDDING_NAME,\n\ttype: 'string',\n\tdefault: 'embedding',\n\tdescription: 'The field with the embedding array',\n\trequired: true,\n};\n\nconst metadataField: INodeProperties = {\n\tdisplayName: 'Metadata Field',\n\tname: METADATA_FIELD_NAME,\n\ttype: 'string',\n\tdefault: 'text',\n\tdescription: 'The text field of the raw data',\n\trequired: true,\n};\n\nconst sharedFields: INodeProperties[] = [\n\tmongoCollectionRLC,\n\tembeddingField,\n\tmetadataField,\n\tvectorIndexName,\n];\n\nconst mongoNamespaceField: INodeProperties = {\n\tdisplayName: 'Namespace',\n\tname: 'namespace',\n\ttype: 'string',\n\tdescription: 'Logical partition for documents. Uses metadata.namespace field for filtering.',\n\tdefault: '',\n};\n\nconst preFilterField: INodeProperties = {\n\tdisplayName: 'Pre Filter',\n\tname: PRE_FILTER_NAME,\n\ttype: 'json',\n\ttypeOptions: {\n\t\talwaysOpenEditWindow: true,\n\t},\n\tdefault: '',\n\tplaceholder: '{ \"key\": \"value\" }',\n\thint: 'This is a filter applied in the $vectorSearch stage <a href=\"https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#atlas-vector-search-pre-filter\">here</a>',\n\trequired: true,\n\tdescription: 'MongoDB Atlas Vector Search pre-filter',\n};\n\nconst postFilterField: INodeProperties = {\n\tdisplayName: 'Post Filter Pipeline',\n\tname: POST_FILTER_NAME,\n\ttype: 'json',\n\ttypeOptions: {\n\t\talwaysOpenEditWindow: true,\n\t},\n\tdefault: '',\n\tplaceholder: '[{ \"$match\": { \"$gt\": \"1950-01-01\" }, ... }]',\n\thint: 'Learn more about aggregation pipeline <a href=\"https://docs.mongodb.com/manual/core/aggregation-pipeline/\">here</a>',\n\trequired: true,\n\tdescription: 'MongoDB aggregation pipeline in JSON format',\n};\n\nconst retrieveFields: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tplaceholder: 'Add Option',\n\t\tdefault: {},\n\t\toptions: [mongoNamespaceField, metadataFilterField, preFilterField, postFilterField],\n\t},\n];\n\nconst insertFields: INodeProperties[] = [\n\t{\n\t\tdisplayName: 'Options',\n\t\tname: 'options',\n\t\ttype: 'collection',\n\t\tplaceholder: 'Add Option',\n\t\tdefault: {},\n\t\toptions: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Clear Namespace',\n\t\t\t\tname: 'clearNamespace',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdefault: false,\n\t\t\t\tdescription: 'Whether to clear documents in the namespace before inserting new data',\n\t\t\t},\n\t\t\tmongoNamespaceField,\n\t\t],\n\t},\n];\n\nexport const mongoConfig = {\n\tclient: null as MongoClient | null,\n\tconnectionString: '',\n\tnodeVersion: 0,\n};\n\n/**\n * Type used for cleaner, more intentional typing.\n */\ntype IFunctionsContext = IExecuteFunctions | ISupplyDataFunctions | ILoadOptionsFunctions;\n\n/**\n * Get the mongo client.\n * @param context - The context.\n * @returns the MongoClient for the node.\n */\nexport async function getMongoClient(\n\tcontext: IExecuteFunctions | ISupplyDataFunctions | ILoadOptionsFunctions,\n\tversion: number,\n) {\n\tconst credentials = await context.getCredentials(MONGODB_CREDENTIALS);\n\tconst node = context.getNode();\n\tconst { connectionString } = validateAndResolveMongoCredentials(node, credentials);\n\tif (\n\t\t!mongoConfig.client ||\n\t\tmongoConfig.connectionString !== connectionString ||\n\t\tmongoConfig.nodeVersion !== version\n\t) {\n\t\tif (mongoConfig.client) {\n\t\t\tawait mongoConfig.client.close();\n\t\t}\n\n\t\tmongoConfig.connectionString = connectionString;\n\t\tmongoConfig.nodeVersion = version;\n\t\tmongoConfig.client = new MongoClient(connectionString, {\n\t\t\tappName: 'devrel.integration.n8n_vector_integ',\n\t\t\tdriverInfo: {\n\t\t\t\tname: 'n8n_vector',\n\t\t\t\tversion: version.toString(),\n\t\t\t},\n\t\t});\n\t\tawait mongoConfig.client.connect();\n\t}\n\treturn mongoConfig.client;\n}\n\n/**\n * Get the database object from the MongoClient by the configured name.\n * @param context - The context.\n * @returns the Db object.\n */\nexport async function getDatabase(context: IFunctionsContext, client: MongoClient) {\n\tconst credentials = await context.getCredentials(MONGODB_CREDENTIALS);\n\treturn client.db(credentials.database as string);\n}\n\n/**\n * Get all the collection in the database.\n * @param this The load options context.\n * @returns The list of collections.\n */\nexport async function getCollections(this: ILoadOptionsFunctions) {\n\ttry {\n\t\tconst client = await getMongoClient(this, this.getNode().typeVersion);\n\t\tconst db = await getDatabase(this, client);\n\t\tconst collections = await db.listCollections().toArray();\n\t\tconst results = collections.map((collection) => ({\n\t\t\tname: collection.name,\n\t\t\tvalue: collection.name,\n\t\t}));\n\n\t\treturn { results };\n\t} catch (error) {\n\t\tthrow new NodeOperationError(this.getNode(), `Error: ${error.message}`);\n\t}\n}\n\n/**\n * Get a parameter from the context.\n * @param key - The key of the parameter.\n * @param context - The context.\n * @param itemIndex - The index.\n * @returns The value.\n */\nexport function getParameter(key: string, context: IFunctionsContext, itemIndex: number): string {\n\tconst value = context.getNodeParameter(key, itemIndex, '', {\n\t\textractValue: true,\n\t}) as string;\n\tif (typeof value !== 'string') {\n\t\tthrow new NodeOperationError(context.getNode(), `Parameter ${key} must be a string`);\n\t}\n\treturn value;\n}\n\nexport const getCollectionName = getParameter.bind(null, MONGODB_COLLECTION_NAME);\nexport const getVectorIndexName = getParameter.bind(null, VECTOR_INDEX_NAME);\nexport const getEmbeddingFieldName = getParameter.bind(null, EMBEDDING_NAME);\nexport const getMetadataFieldName = getParameter.bind(null, METADATA_FIELD_NAME);\n\nexport function getFilterValue<T>(\n\tname: string,\n\tcontext: IExecuteFunctions | ISupplyDataFunctions,\n\titemIndex: number,\n): T | undefined {\n\tconst options: IDataObject = context.getNodeParameter('options', itemIndex, {});\n\n\tif (options[name]) {\n\t\tif (typeof options[name] === 'string') {\n\t\t\ttry {\n\t\t\t\treturn JSON.parse(options[name]);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription: `Could not parse JSON for ${name}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tthrow new NodeOperationError(context.getNode(), 'Error: No JSON string provided.', {\n\t\t\titemIndex,\n\t\t\tdescription: `Could not parse JSON for ${name}`,\n\t\t});\n\t}\n\n\treturn undefined;\n}\n\nclass ExtendedMongoDBAtlasVectorSearch extends MongoDBAtlasVectorSearch {\n\tpreFilter: IDataObject;\n\tpostFilterPipeline?: IDataObject[];\n\n\tconstructor(\n\t\tembeddings: EmbeddingsInterface,\n\t\toptions: MongoDBAtlasVectorSearchLibArgs,\n\t\tpreFilter: IDataObject,\n\t\tpostFilterPipeline?: IDataObject[],\n\t) {\n\t\tsuper(embeddings, options);\n\t\tthis.preFilter = preFilter;\n\t\tthis.postFilterPipeline = postFilterPipeline;\n\t}\n\n\tasync similaritySearchVectorWithScore(query: number[], k: number) {\n\t\tconst mergedFilter: MongoDBAtlasVectorSearch['FilterType'] = {\n\t\t\tpreFilter: this.preFilter,\n\t\t\tpostFilterPipeline: this.postFilterPipeline,\n\t\t};\n\t\treturn await super.similaritySearchVectorWithScore(query, k, mergedFilter);\n\t}\n}\n\nexport class VectorStoreMongoDBAtlas extends createVectorStoreNode({\n\tmeta: {\n\t\tdisplayName: 'MongoDB Atlas Vector Store',\n\t\tname: 'vectorStoreMongoDBAtlas',\n\t\tdescription: 'Work with your data in MongoDB Atlas Vector Store',\n\t\ticon: { light: 'file:mongodb.svg', dark: 'file:mongodb.dark.svg' },\n\t\tdocsUrl:\n\t\t\t'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoremongodbatlas/',\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'mongoDb',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\toperationModes: ['load', 'insert', 'retrieve', 'update', 'retrieve-as-tool'],\n\t},\n\tmethods: { listSearch: { mongoCollectionSearch: getCollections } },\n\tretrieveFields,\n\tloadFields: retrieveFields,\n\tinsertFields,\n\tsharedFields,\n\tasync getVectorStoreClient(context, _filter, embeddings, itemIndex) {\n\t\ttry {\n\t\t\tconst client = await getMongoClient(context, context.getNode().typeVersion);\n\t\t\tconst db = await getDatabase(context, client);\n\t\t\tconst collectionName = getCollectionName(context, itemIndex);\n\t\t\tconst mongoVectorIndexName = getVectorIndexName(context, itemIndex);\n\t\t\tconst embeddingFieldName = getEmbeddingFieldName(context, itemIndex);\n\t\t\tconst metadataFieldName = getMetadataFieldName(context, itemIndex);\n\n\t\t\tconst collection = db.collection(collectionName);\n\n\t\t\t// test index exists\n\t\t\tconst indexes = await collection.listSearchIndexes().toArray();\n\n\t\t\tconst indexExists = indexes.some((index) => index.name === mongoVectorIndexName);\n\n\t\t\tif (!indexExists) {\n\t\t\t\tthrow new NodeOperationError(context.getNode(), `Index ${mongoVectorIndexName} not found`, {\n\t\t\t\t\titemIndex,\n\t\t\t\t\tdescription: 'Please check that the index exists in your collection',\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst preFilter = getFilterValue<IDataObject>(PRE_FILTER_NAME, context, itemIndex);\n\t\t\tconst postFilterPipeline = getFilterValue<IDataObject[]>(\n\t\t\t\tPOST_FILTER_NAME,\n\t\t\t\tcontext,\n\t\t\t\titemIndex,\n\t\t\t);\n\n\t\t\treturn new ExtendedMongoDBAtlasVectorSearch(\n\t\t\t\tembeddings,\n\t\t\t\t{\n\t\t\t\t\tcollection,\n\t\t\t\t\tindexName: mongoVectorIndexName, // Default index name\n\t\t\t\t\ttextKey: metadataFieldName, // Field containing raw text\n\t\t\t\t\tembeddingKey: embeddingFieldName, // Field containing embeddings\n\t\t\t\t},\n\t\t\t\tpreFilter ?? {},\n\t\t\t\tpostFilterPipeline,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tif (error instanceof NodeOperationError) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\titemIndex,\n\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t});\n\t\t}\n\t},\n\tasync populateVectorStore(context, embeddings, documents, itemIndex) {\n\t\ttry {\n\t\t\tconst client = await getMongoClient(context, context.getNode().typeVersion);\n\t\t\tconst db = await getDatabase(context, client);\n\t\t\tconst collectionName = getCollectionName(context, itemIndex);\n\t\t\tconst mongoVectorIndexName = getVectorIndexName(context, itemIndex);\n\t\t\tconst embeddingFieldName = getEmbeddingFieldName(context, itemIndex);\n\t\t\tconst metadataFieldName = getMetadataFieldName(context, itemIndex);\n\n\t\t\t// Check if collection exists\n\t\t\tconst collections = await db.listCollections({ name: collectionName }).toArray();\n\t\t\tif (collections.length === 0) {\n\t\t\t\tawait db.createCollection(collectionName);\n\t\t\t}\n\t\t\tconst collection = db.collection(collectionName);\n\t\t\tawait ExtendedMongoDBAtlasVectorSearch.fromDocuments(documents, embeddings, {\n\t\t\t\tcollection,\n\t\t\t\tindexName: mongoVectorIndexName, // Default index name\n\t\t\t\ttextKey: metadataFieldName, // Field containing raw text\n\t\t\t\tembeddingKey: embeddingFieldName, // Field containing embeddings\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow new NodeOperationError(context.getNode(), `Error: ${error.message}`, {\n\t\t\t\titemIndex,\n\t\t\t\tdescription: 'Please check your MongoDB Atlas connection details',\n\t\t\t});\n\t\t}\n\t},\n}) {}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA+E;AAC/E,IAAAA,kBAA4B;AAC5B,0BAOO;AACP,0BAAoC;AAEpC,mCAAsC;AAEtC,8BAAmD;AAK5C,MAAM,sBAAsB;AAC5B,MAAM,0BAA0B;AAChC,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AACvB,MAAM,sBAAsB;AAC5B,MAAM,kBAAkB;AACxB,MAAM,mBAAmB;AAEhC,MAAM,qBAAsC;AAAA,EAC3C,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS,EAAE,MAAM,QAAQ,OAAO,GAAG;AAAA,EACnC,UAAU;AAAA,EACV,OAAO;AAAA,IACN;AAAA,MACC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,QACZ,kBAAkB;AAAA;AAAA,MACnB;AAAA,IACD;AAAA,IACA;AAAA,MACC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,IACd;AAAA,EACD;AACD;AAEA,MAAM,kBAAmC;AAAA,EACxC,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,aAAa;AAAA,EACb,UAAU;AACX;AAEA,MAAM,iBAAkC;AAAA,EACvC,aAAa;AAAA,EACb,MAAM;AAAA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,EACD;AACD,CAAC,EAAE;AAAC;","names":["import_mongodb"]}
@@ -41,7 +41,7 @@ const modelRLC = {
41
41
  displayName: "ID",
42
42
  name: "id",
43
43
  type: "string",
44
- placeholder: "e.g. claude-3-5-sonnet-20241022"
44
+ placeholder: "e.g. claude-sonnet-4-5-20250929"
45
45
  }
46
46
  ]
47
47
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../nodes/vendors/Anthropic/actions/descriptions.ts"],"sourcesContent":["import type { INodeProperties } from 'n8n-workflow';\n\nexport const modelRLC: INodeProperties = {\n\tdisplayName: 'Model',\n\tname: 'modelId',\n\ttype: 'resourceLocator',\n\tdefault: { mode: 'list', value: '' },\n\trequired: true,\n\tmodes: [\n\t\t{\n\t\t\tdisplayName: 'From List',\n\t\t\tname: 'list',\n\t\t\ttype: 'list',\n\t\t\ttypeOptions: {\n\t\t\t\tsearchListMethod: 'modelSearch',\n\t\t\t\tsearchable: true,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tdisplayName: 'ID',\n\t\t\tname: 'id',\n\t\t\ttype: 'string',\n\t\t\tplaceholder: 'e.g. claude-3-5-sonnet-20241022',\n\t\t},\n\t],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,WAA4B;AAAA,EACxC,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS,EAAE,MAAM,QAAQ,OAAO,GAAG;AAAA,EACnC,UAAU;AAAA,EACV,OAAO;AAAA,IACN;AAAA,MACC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,QACZ,kBAAkB;AAAA,QAClB,YAAY;AAAA,MACb;AAAA,IACD;AAAA,IACA;AAAA,MACC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,IACd;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../../nodes/vendors/Anthropic/actions/descriptions.ts"],"sourcesContent":["import type { INodeProperties } from 'n8n-workflow';\n\nexport const modelRLC: INodeProperties = {\n\tdisplayName: 'Model',\n\tname: 'modelId',\n\ttype: 'resourceLocator',\n\tdefault: { mode: 'list', value: '' },\n\trequired: true,\n\tmodes: [\n\t\t{\n\t\t\tdisplayName: 'From List',\n\t\t\tname: 'list',\n\t\t\ttype: 'list',\n\t\t\ttypeOptions: {\n\t\t\t\tsearchListMethod: 'modelSearch',\n\t\t\t\tsearchable: true,\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tdisplayName: 'ID',\n\t\t\tname: 'id',\n\t\t\ttype: 'string',\n\t\t\tplaceholder: 'e.g. claude-sonnet-4-5-20250929',\n\t\t},\n\t],\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,WAA4B;AAAA,EACxC,aAAa;AAAA,EACb,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS,EAAE,MAAM,QAAQ,OAAO,GAAG;AAAA,EACnC,UAAU;AAAA,EACV,OAAO;AAAA,IACN;AAAA,MACC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,QACZ,kBAAkB;AAAA,QAClB,YAAY;AAAA,MACb;AAAA,IACD;AAAA,IACA;AAAA,MACC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,aAAa;AAAA,IACd;AAAA,EACD;AACD;","names":[]}
@@ -1,5 +1,5 @@
1
1
  [
2
- {"displayName":"Anthropic","name":"anthropic","group":["transform"],"version":1,"subtitle":"={{ $parameter[\"operation\"] + \": \" + $parameter[\"resource\"] }}","description":"Interact with Anthropic AI models","defaults":{"name":"Anthropic"},"usableAsTool":true,"codex":{"alias":["LangChain","document","image","assistant","claude"],"categories":["AI"],"subcategories":{"AI":["Agents","Miscellaneous","Root Nodes"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.anthropic/"}]}},"inputs":"={{\n\t\t(() => {\n\t\t\tconst resource = $parameter.resource;\n\t \tconst operation = $parameter.operation;\n\t\t\tif (resource === 'text' && operation === 'message') {\n\t\t\t\treturn [{ type: 'main' }, { type: 'ai_tool', displayName: 'Tools' }];\n\t\t\t}\n\n\t\t\treturn ['main'];\n\t\t})()\n\t}}","outputs":["main"],"credentials":[{"name":"anthropicApi","required":true}],"properties":[{"displayName":"Resource","name":"resource","type":"options","noDataExpression":true,"options":[{"name":"Document","value":"document"},{"name":"File","value":"file"},{"name":"Image","value":"image"},{"name":"Prompt","value":"prompt"},{"name":"Text","value":"text"}],"default":"text"},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Document","value":"analyze","action":"Analyze document","description":"Take in documents and answer questions about them"}],"default":"analyze","displayOptions":{"show":{"resource":["document"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. claude-3-5-sonnet-20241022"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this document?","default":"What's in this document?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Document URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"URL(s)","name":"documentUrls","type":"string","placeholder":"e.g. https://example.com/document.pdf","description":"URL(s) of the document(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["document"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the document(s), seperate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["document"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed image description","name":"maxTokens","type":"number","default":1024,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Upload File","value":"upload","action":"Upload a file","description":"Upload a file to the Anthropic API for later use"},{"name":"Get File Metadata","value":"get","action":"Get file metadata","description":"Get metadata for a file from the Anthropic API"},{"name":"List Files","value":"list","action":"List files","description":"List files from the Anthropic API"},{"name":"Delete File","value":"deleteFile","action":"Delete a file","description":"Delete a file from the Anthropic API"}],"default":"upload","displayOptions":{"show":{"resource":["file"]}}},{"displayName":"File ID","name":"fileId","type":"string","placeholder":"e.g. file_123","description":"ID of the file to delete","default":"","displayOptions":{"show":{"operation":["deleteFile"],"resource":["file"]}}},{"displayName":"File ID","name":"fileId","type":"string","placeholder":"e.g. file_123","description":"ID of the file to get metadata for","default":"","displayOptions":{"show":{"operation":["get"],"resource":["file"]}}},{"displayName":"Return All","name":"returnAll","type":"boolean","default":false,"description":"Whether to return all results or only up to a given limit","displayOptions":{"show":{"operation":["list"],"resource":["file"]}}},{"displayName":"Limit","name":"limit","type":"number","typeOptions":{"minValue":1,"maxValue":1000},"default":50,"description":"Max number of results to return","displayOptions":{"show":{"returnAll":[false],"operation":["list"],"resource":["file"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"File URL","value":"url"},{"name":"Binary File","value":"binary"}],"displayOptions":{"show":{"operation":["upload"],"resource":["file"]}}},{"displayName":"URL","name":"fileUrl","type":"string","placeholder":"e.g. https://example.com/file.pdf","description":"URL of the file to upload","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["upload"],"resource":["file"]}}},{"displayName":"Input Data Field Name","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field which contains the file","displayOptions":{"show":{"inputType":["binary"],"operation":["upload"],"resource":["file"]}}},{"displayName":"Options","name":"options","type":"collection","placeholder":"Add Option","default":{},"options":[{"displayName":"File Name","name":"fileName","type":"string","description":"The file name to use for the uploaded file","default":""}],"displayOptions":{"show":{"operation":["upload"],"resource":["file"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Image","value":"analyze","action":"Analyze image","description":"Take in images and answer questions about them"}],"default":"analyze","displayOptions":{"show":{"resource":["image"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. claude-3-5-sonnet-20241022"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this image?","default":"What's in this image?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Image URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"URL(s)","name":"imageUrls","type":"string","placeholder":"e.g. https://example.com/image.png","description":"URL(s) of the image(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the image(s), seperate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed image description","name":"maxTokens","type":"number","default":1024,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Generate Prompt","value":"generate","action":"Generate a prompt","description":"Generate a prompt for a model"},{"name":"Improve Prompt","value":"improve","action":"Improve a prompt","description":"Improve a prompt for a model"},{"name":"Templatize Prompt","value":"templatize","action":"Templatize a prompt","description":"Templatize a prompt for a model"}],"default":"generate","displayOptions":{"show":{"resource":["prompt"]}}},{"displayName":"The <a href=\"https://docs.anthropic.com/en/api/prompt-tools-generate\">prompt tools APIs</a> are in a closed research preview. Your organization must request access to use them.","name":"experimentalNotice","type":"notice","default":"","displayOptions":{"show":{"resource":["prompt"]}}},{"displayName":"Task","name":"task","type":"string","description":"Description of the prompt's purpose","placeholder":"e.g. A chef for a meal prep planning service","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["generate"],"resource":["prompt"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["generate"],"resource":["prompt"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"description":"Messages that constitute the prompt to be improved","placeholder":"Add Message","default":{"values":[{"content":"","role":"user"}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Prompt","name":"content","type":"string","description":"The content of the message to be sent","default":"","placeholder":"e.g. Concise instructions for a meal prep service","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"Role in shaping the model's response, it tells the model how it should behave and interact with the user","options":[{"name":"User","value":"user","description":"Send a message as a user and get a response from the model"},{"name":"Assistant","value":"assistant","description":"Tell the model to adopt a specific tone or personality"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["improve"],"resource":["prompt"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["improve"],"resource":["prompt"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"System Message","name":"system","type":"string","description":"The existing system prompt to incorporate, if any","default":"","placeholder":"e.g. You are a professional meal prep chef"},{"displayName":"Feedback","name":"feedback","type":"string","description":"Feedback for improving the prompt","default":"","placeholder":"e.g. Make it more detailed and include cooking times"}],"displayOptions":{"show":{"operation":["improve"],"resource":["prompt"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"description":"Messages that constitute the prompt to be templatized","placeholder":"Add Message","default":{"values":[{"content":"","role":"user"}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Prompt","name":"content","type":"string","description":"The content of the message to be sent","default":"","placeholder":"e.g. Translate hello to German","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"Role in shaping the model's response, it tells the model how it should behave and interact with the user","options":[{"name":"User","value":"user","description":"Send a message as a user and get a response from the model"},{"name":"Assistant","value":"assistant","description":"Tell the model to adopt a specific tone or personality"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["templatize"],"resource":["prompt"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["templatize"],"resource":["prompt"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"System Message","name":"system","type":"string","description":"The existing system prompt to templatize","default":"","placeholder":"e.g. You are a professional English to German translator"}],"displayOptions":{"show":{"operation":["templatize"],"resource":["prompt"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Message a Model","value":"message","action":"Message a model","description":"Create a completion with Anthropic model"}],"default":"message","displayOptions":{"show":{"resource":["text"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. claude-3-5-sonnet-20241022"}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"placeholder":"Add Message","default":{"values":[{"content":"","role":"user"}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Prompt","name":"content","type":"string","description":"The content of the message to be sent","default":"","placeholder":"e.g. Hello, how can you help me?","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"Role in shaping the model's response, it tells the model how it should behave and interact with the user","options":[{"name":"User","value":"user","description":"Send a message as a user and get a response from the model"},{"name":"Assistant","value":"assistant","description":"Tell the model to adopt a specific tone or personality"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Add Attachments","name":"addAttachments","type":"boolean","default":false,"description":"Whether to add attachments to the message","displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Attachments Input Type","name":"attachmentsInputType","type":"options","default":"url","description":"The type of input to use for the attachments","options":[{"name":"URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"addAttachments":[true],"operation":["message"],"resource":["text"]}}},{"displayName":"Attachment URL(s)","name":"attachmentsUrls","type":"string","default":"","placeholder":"e.g. https://example.com/image.png","description":"URL(s) of the file(s) to attach, multiple URLs can be added separated by comma","displayOptions":{"show":{"addAttachments":[true],"attachmentsInputType":["url"],"operation":["message"],"resource":["text"]}}},{"displayName":"Attachment Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","description":"Name of the binary field(s) which contains the file(s) to attach, multiple field names can be added separated by comma","displayOptions":{"show":{"addAttachments":[true],"attachmentsInputType":["binary"],"operation":["message"],"resource":["text"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Include Merged Response","name":"includeMergedResponse","type":"boolean","default":false,"description":"Whether to include a single output string merging all text parts of the response"},{"displayName":"System Message","name":"system","type":"string","default":"","placeholder":"e.g. You are a helpful assistant"},{"displayName":"Code Execution","name":"codeExecution","type":"boolean","default":false,"description":"Whether to enable code execution. Not supported by all models."},{"displayName":"Web Search","name":"webSearch","type":"boolean","default":false,"description":"Whether to enable web search"},{"displayName":"Web Search Max Uses","name":"maxUses","type":"number","default":5,"description":"The maximum number of web search uses per request","typeOptions":{"minValue":0,"numberPrecision":0}},{"displayName":"Web Search Allowed Domains","name":"allowedDomains","type":"string","default":"","description":"Comma-separated list of domains to search. Only domains in this list will be searched. Conflicts with \"Web Search Blocked Domains\".","placeholder":"e.g. google.com, wikipedia.org"},{"displayName":"Web Search Blocked Domains","name":"blockedDomains","type":"string","default":"","description":"Comma-separated list of domains to block from search. Conflicts with \"Web Search Allowed Domains\".","placeholder":"e.g. google.com, wikipedia.org"},{"displayName":"Maximum Number of Tokens","name":"maxTokens","default":1024,"description":"The maximum number of tokens to generate in the completion","type":"number","typeOptions":{"minValue":1,"numberPrecision":0}},{"displayName":"Output Randomness (Temperature)","name":"temperature","default":1,"description":"Controls the randomness of the output. Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive","type":"number","typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}},{"displayName":"Output Randomness (Top P)","name":"topP","default":0.7,"description":"The maximum cumulative probability of tokens to consider when sampling","type":"number","typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}},{"displayName":"Output Randomness (Top K)","name":"topK","default":5,"description":"The maximum number of tokens to consider when sampling","type":"number","typeOptions":{"minValue":0,"numberPrecision":0}},{"displayName":"Max Tool Calls Iterations","name":"maxToolsIterations","type":"number","default":15,"description":"The maximum number of tool iteration cycles the LLM will run before stopping. A single iteration can contain multiple tool calls. Set to 0 for no limit","typeOptions":{"minValue":0,"numberPrecision":0}}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/vendors/Anthropic/anthropic.svg"},
2
+ {"displayName":"Anthropic","name":"anthropic","group":["transform"],"version":1,"subtitle":"={{ $parameter[\"operation\"] + \": \" + $parameter[\"resource\"] }}","description":"Interact with Anthropic AI models","defaults":{"name":"Anthropic"},"usableAsTool":true,"codex":{"alias":["LangChain","document","image","assistant","claude"],"categories":["AI"],"subcategories":{"AI":["Agents","Miscellaneous","Root Nodes"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.anthropic/"}]}},"inputs":"={{\n\t\t(() => {\n\t\t\tconst resource = $parameter.resource;\n\t \tconst operation = $parameter.operation;\n\t\t\tif (resource === 'text' && operation === 'message') {\n\t\t\t\treturn [{ type: 'main' }, { type: 'ai_tool', displayName: 'Tools' }];\n\t\t\t}\n\n\t\t\treturn ['main'];\n\t\t})()\n\t}}","outputs":["main"],"credentials":[{"name":"anthropicApi","required":true}],"properties":[{"displayName":"Resource","name":"resource","type":"options","noDataExpression":true,"options":[{"name":"Document","value":"document"},{"name":"File","value":"file"},{"name":"Image","value":"image"},{"name":"Prompt","value":"prompt"},{"name":"Text","value":"text"}],"default":"text"},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Document","value":"analyze","action":"Analyze document","description":"Take in documents and answer questions about them"}],"default":"analyze","displayOptions":{"show":{"resource":["document"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. claude-sonnet-4-5-20250929"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this document?","default":"What's in this document?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Document URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"URL(s)","name":"documentUrls","type":"string","placeholder":"e.g. https://example.com/document.pdf","description":"URL(s) of the document(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["document"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the document(s), seperate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["document"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed image description","name":"maxTokens","type":"number","default":1024,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Upload File","value":"upload","action":"Upload a file","description":"Upload a file to the Anthropic API for later use"},{"name":"Get File Metadata","value":"get","action":"Get file metadata","description":"Get metadata for a file from the Anthropic API"},{"name":"List Files","value":"list","action":"List files","description":"List files from the Anthropic API"},{"name":"Delete File","value":"deleteFile","action":"Delete a file","description":"Delete a file from the Anthropic API"}],"default":"upload","displayOptions":{"show":{"resource":["file"]}}},{"displayName":"File ID","name":"fileId","type":"string","placeholder":"e.g. file_123","description":"ID of the file to delete","default":"","displayOptions":{"show":{"operation":["deleteFile"],"resource":["file"]}}},{"displayName":"File ID","name":"fileId","type":"string","placeholder":"e.g. file_123","description":"ID of the file to get metadata for","default":"","displayOptions":{"show":{"operation":["get"],"resource":["file"]}}},{"displayName":"Return All","name":"returnAll","type":"boolean","default":false,"description":"Whether to return all results or only up to a given limit","displayOptions":{"show":{"operation":["list"],"resource":["file"]}}},{"displayName":"Limit","name":"limit","type":"number","typeOptions":{"minValue":1,"maxValue":1000},"default":50,"description":"Max number of results to return","displayOptions":{"show":{"returnAll":[false],"operation":["list"],"resource":["file"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"File URL","value":"url"},{"name":"Binary File","value":"binary"}],"displayOptions":{"show":{"operation":["upload"],"resource":["file"]}}},{"displayName":"URL","name":"fileUrl","type":"string","placeholder":"e.g. https://example.com/file.pdf","description":"URL of the file to upload","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["upload"],"resource":["file"]}}},{"displayName":"Input Data Field Name","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field which contains the file","displayOptions":{"show":{"inputType":["binary"],"operation":["upload"],"resource":["file"]}}},{"displayName":"Options","name":"options","type":"collection","placeholder":"Add Option","default":{},"options":[{"displayName":"File Name","name":"fileName","type":"string","description":"The file name to use for the uploaded file","default":""}],"displayOptions":{"show":{"operation":["upload"],"resource":["file"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Image","value":"analyze","action":"Analyze image","description":"Take in images and answer questions about them"}],"default":"analyze","displayOptions":{"show":{"resource":["image"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. claude-sonnet-4-5-20250929"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this image?","default":"What's in this image?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Image URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"URL(s)","name":"imageUrls","type":"string","placeholder":"e.g. https://example.com/image.png","description":"URL(s) of the image(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the image(s), seperate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed image description","name":"maxTokens","type":"number","default":1024,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Generate Prompt","value":"generate","action":"Generate a prompt","description":"Generate a prompt for a model"},{"name":"Improve Prompt","value":"improve","action":"Improve a prompt","description":"Improve a prompt for a model"},{"name":"Templatize Prompt","value":"templatize","action":"Templatize a prompt","description":"Templatize a prompt for a model"}],"default":"generate","displayOptions":{"show":{"resource":["prompt"]}}},{"displayName":"The <a href=\"https://docs.anthropic.com/en/api/prompt-tools-generate\">prompt tools APIs</a> are in a closed research preview. Your organization must request access to use them.","name":"experimentalNotice","type":"notice","default":"","displayOptions":{"show":{"resource":["prompt"]}}},{"displayName":"Task","name":"task","type":"string","description":"Description of the prompt's purpose","placeholder":"e.g. A chef for a meal prep planning service","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["generate"],"resource":["prompt"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["generate"],"resource":["prompt"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"description":"Messages that constitute the prompt to be improved","placeholder":"Add Message","default":{"values":[{"content":"","role":"user"}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Prompt","name":"content","type":"string","description":"The content of the message to be sent","default":"","placeholder":"e.g. Concise instructions for a meal prep service","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"Role in shaping the model's response, it tells the model how it should behave and interact with the user","options":[{"name":"User","value":"user","description":"Send a message as a user and get a response from the model"},{"name":"Assistant","value":"assistant","description":"Tell the model to adopt a specific tone or personality"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["improve"],"resource":["prompt"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["improve"],"resource":["prompt"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"System Message","name":"system","type":"string","description":"The existing system prompt to incorporate, if any","default":"","placeholder":"e.g. You are a professional meal prep chef"},{"displayName":"Feedback","name":"feedback","type":"string","description":"Feedback for improving the prompt","default":"","placeholder":"e.g. Make it more detailed and include cooking times"}],"displayOptions":{"show":{"operation":["improve"],"resource":["prompt"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"description":"Messages that constitute the prompt to be templatized","placeholder":"Add Message","default":{"values":[{"content":"","role":"user"}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Prompt","name":"content","type":"string","description":"The content of the message to be sent","default":"","placeholder":"e.g. Translate hello to German","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"Role in shaping the model's response, it tells the model how it should behave and interact with the user","options":[{"name":"User","value":"user","description":"Send a message as a user and get a response from the model"},{"name":"Assistant","value":"assistant","description":"Tell the model to adopt a specific tone or personality"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["templatize"],"resource":["prompt"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["templatize"],"resource":["prompt"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"System Message","name":"system","type":"string","description":"The existing system prompt to templatize","default":"","placeholder":"e.g. You are a professional English to German translator"}],"displayOptions":{"show":{"operation":["templatize"],"resource":["prompt"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Message a Model","value":"message","action":"Message a model","description":"Create a completion with Anthropic model"}],"default":"message","displayOptions":{"show":{"resource":["text"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. claude-sonnet-4-5-20250929"}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"placeholder":"Add Message","default":{"values":[{"content":"","role":"user"}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Prompt","name":"content","type":"string","description":"The content of the message to be sent","default":"","placeholder":"e.g. Hello, how can you help me?","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"Role in shaping the model's response, it tells the model how it should behave and interact with the user","options":[{"name":"User","value":"user","description":"Send a message as a user and get a response from the model"},{"name":"Assistant","value":"assistant","description":"Tell the model to adopt a specific tone or personality"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Add Attachments","name":"addAttachments","type":"boolean","default":false,"description":"Whether to add attachments to the message","displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Attachments Input Type","name":"attachmentsInputType","type":"options","default":"url","description":"The type of input to use for the attachments","options":[{"name":"URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"addAttachments":[true],"operation":["message"],"resource":["text"]}}},{"displayName":"Attachment URL(s)","name":"attachmentsUrls","type":"string","default":"","placeholder":"e.g. https://example.com/image.png","description":"URL(s) of the file(s) to attach, multiple URLs can be added separated by comma","displayOptions":{"show":{"addAttachments":[true],"attachmentsInputType":["url"],"operation":["message"],"resource":["text"]}}},{"displayName":"Attachment Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","description":"Name of the binary field(s) which contains the file(s) to attach, multiple field names can be added separated by comma","displayOptions":{"show":{"addAttachments":[true],"attachmentsInputType":["binary"],"operation":["message"],"resource":["text"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Include Merged Response","name":"includeMergedResponse","type":"boolean","default":false,"description":"Whether to include a single output string merging all text parts of the response"},{"displayName":"System Message","name":"system","type":"string","default":"","placeholder":"e.g. You are a helpful assistant"},{"displayName":"Code Execution","name":"codeExecution","type":"boolean","default":false,"description":"Whether to enable code execution. Not supported by all models."},{"displayName":"Web Search","name":"webSearch","type":"boolean","default":false,"description":"Whether to enable web search"},{"displayName":"Web Search Max Uses","name":"maxUses","type":"number","default":5,"description":"The maximum number of web search uses per request","typeOptions":{"minValue":0,"numberPrecision":0}},{"displayName":"Web Search Allowed Domains","name":"allowedDomains","type":"string","default":"","description":"Comma-separated list of domains to search. Only domains in this list will be searched. Conflicts with \"Web Search Blocked Domains\".","placeholder":"e.g. google.com, wikipedia.org"},{"displayName":"Web Search Blocked Domains","name":"blockedDomains","type":"string","default":"","description":"Comma-separated list of domains to block from search. Conflicts with \"Web Search Allowed Domains\".","placeholder":"e.g. google.com, wikipedia.org"},{"displayName":"Maximum Number of Tokens","name":"maxTokens","default":1024,"description":"The maximum number of tokens to generate in the completion","type":"number","typeOptions":{"minValue":1,"numberPrecision":0}},{"displayName":"Output Randomness (Temperature)","name":"temperature","default":1,"description":"Controls the randomness of the output. Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive","type":"number","typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}},{"displayName":"Output Randomness (Top P)","name":"topP","default":0.7,"description":"The maximum cumulative probability of tokens to consider when sampling","type":"number","typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}},{"displayName":"Output Randomness (Top K)","name":"topK","default":5,"description":"The maximum number of tokens to consider when sampling","type":"number","typeOptions":{"minValue":0,"numberPrecision":0}},{"displayName":"Max Tool Calls Iterations","name":"maxToolsIterations","type":"number","default":15,"description":"The maximum number of tool iteration cycles the LLM will run before stopping. A single iteration can contain multiple tool calls. Set to 0 for no limit","typeOptions":{"minValue":0,"numberPrecision":0}}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/vendors/Anthropic/anthropic.svg"},
3
3
  {"displayName":"Google Gemini","name":"googleGemini","group":["transform"],"version":1,"subtitle":"={{ $parameter[\"operation\"] + \": \" + $parameter[\"resource\"] }}","description":"Interact with Google Gemini AI models","defaults":{"name":"Google Gemini"},"usableAsTool":true,"codex":{"alias":["LangChain","video","document","audio","transcribe","assistant"],"categories":["AI"],"subcategories":{"AI":["Agents","Miscellaneous","Root Nodes"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.googlegemini/"}]}},"inputs":"={{\n\t\t(() => {\n\t\t\tconst resource = $parameter.resource;\n\t \tconst operation = $parameter.operation;\n\t\t\tif (resource === 'text' && operation === 'message') {\n\t\t\t\treturn [{ type: 'main' }, { type: 'ai_tool', displayName: 'Tools' }];\n\t\t\t}\n\n\t\t\treturn ['main'];\n\t\t})()\n\t}}","outputs":["main"],"credentials":[{"name":"googlePalmApi","required":true}],"properties":[{"displayName":"Resource","name":"resource","type":"options","noDataExpression":true,"options":[{"name":"Audio","value":"audio"},{"name":"Document","value":"document"},{"name":"File","value":"file"},{"name":"Image","value":"image"},{"name":"Text","value":"text"},{"name":"Video","value":"video"}],"default":"text"},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Audio","value":"analyze","action":"Analyze audio","description":"Take in audio and answer questions about it"},{"name":"Transcribe a Recording","value":"transcribe","action":"Transcribe a recording","description":"Transcribes audio into the text"}],"default":"transcribe","displayOptions":{"show":{"resource":["audio"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"audioModelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. models/gemini-2.5-flash"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["audio"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this audio?","default":"What's in this audio?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["audio"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Audio URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["audio"]}}},{"displayName":"URL(s)","name":"audioUrls","type":"string","placeholder":"e.g. https://example.com/audio.mp3","description":"URL(s) of the audio(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["audio"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the audio(s), seperate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["audio"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["audio"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed audio description","name":"maxOutputTokens","type":"number","default":300,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["audio"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"audioModelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. models/gemini-2.5-flash"}],"displayOptions":{"show":{"operation":["transcribe"],"resource":["audio"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Audio URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["transcribe"],"resource":["audio"]}}},{"displayName":"URL(s)","name":"audioUrls","type":"string","placeholder":"e.g. https://example.com/audio.mp3","description":"URL(s) of the audio(s) to transcribe, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["transcribe"],"resource":["audio"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the audio(s), seperate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["transcribe"],"resource":["audio"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["transcribe"],"resource":["audio"]}}},{"displayName":"Options","name":"options","type":"collection","default":{},"options":[{"displayName":"Start Time","name":"startTime","type":"string","default":"","description":"The start time of the audio in MM:SS or HH:MM:SS format","placeholder":"e.g. 00:15"},{"displayName":"End Time","name":"endTime","type":"string","default":"","description":"The end time of the audio in MM:SS or HH:MM:SS format","placeholder":"e.g. 02:15"}],"displayOptions":{"show":{"operation":["transcribe"],"resource":["audio"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Document","value":"analyze","action":"Analyze document","description":"Take in documents and answer questions about them"}],"default":"analyze","displayOptions":{"show":{"resource":["document"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. models/gemini-2.5-flash"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this document?","default":"What's in this document?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Document URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"URL(s)","name":"documentUrls","type":"string","placeholder":"e.g. https://example.com/document.pdf","description":"URL(s) of the document(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["document"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the document(s), seperate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["document"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed document description","name":"maxOutputTokens","type":"number","default":300,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["document"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Upload File","value":"upload","action":"Upload a file","description":"Upload a file to the Google Gemini API for later use"}],"default":"upload","displayOptions":{"show":{"resource":["file"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"File URL","value":"url"},{"name":"Binary File","value":"binary"}],"displayOptions":{"show":{"operation":["upload"],"resource":["file"]}}},{"displayName":"URL","name":"fileUrl","type":"string","placeholder":"e.g. https://example.com/file.pdf","description":"URL of the file to upload","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["upload"],"resource":["file"]}}},{"displayName":"Input Data Field Name","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary property which contains the file","displayOptions":{"show":{"inputType":["binary"],"operation":["upload"],"resource":["file"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Image","value":"analyze","action":"Analyze an image","description":"Take in images and answer questions about them"},{"name":"Generate an Image","value":"generate","action":"Generate an image","description":"Creates an image from a text prompt"},{"name":"Edit Image","value":"edit","action":"Edit an image","description":"Upload one or more images and apply edits based on a prompt"}],"default":"generate","displayOptions":{"show":{"resource":["image"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. models/gemini-2.5-flash"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this image?","default":"What's in this image?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Image URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"URL(s)","name":"imageUrls","type":"string","placeholder":"e.g. https://example.com/image.png","description":"URL(s) of the image(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the image(s), separate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed image description","name":"maxOutputTokens","type":"number","default":300,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Prompt","name":"prompt","type":"string","placeholder":"e.g. combine the first image with the second image","description":"Instruction describing how to edit the image","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["edit"],"resource":["image"]}}},{"displayName":"Images","name":"images","type":"fixedCollection","placeholder":"Add Image","typeOptions":{"multipleValues":true,"multipleValueButtonText":"Add Image"},"default":{"values":[{"binaryPropertyName":"data"}]},"description":"Add one or more binary fields to include images with your prompt","options":[{"displayName":"Image","name":"values","values":[{"displayName":"Binary Field Name","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","description":"The name of the binary field containing the image data"}]}],"displayOptions":{"show":{"operation":["edit"],"resource":["image"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Put Output in Field","name":"binaryPropertyOutput","type":"string","default":"edited","hint":"The name of the output field to put the binary file data in"}],"displayOptions":{"show":{"operation":["edit"],"resource":["image"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"imageGenerationModelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. models/gemini-2.5-flash"}],"displayOptions":{"show":{"operation":["generate"],"resource":["image"]}}},{"displayName":"Prompt","name":"prompt","type":"string","placeholder":"e.g. A cute cat eating a dinosaur","description":"A text description of the desired image(s)","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["generate"],"resource":["image"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Number of Images","name":"sampleCount","default":1,"description":"Number of images to generate. Not supported by Gemini models, supported by Imagen models.","type":"number","typeOptions":{"minValue":1}},{"displayName":"Put Output in Field","name":"binaryPropertyOutput","type":"string","default":"data","hint":"The name of the output field to put the binary file data in"}],"displayOptions":{"show":{"operation":["generate"],"resource":["image"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Message a Model","value":"message","action":"Message a model","description":"Create a completion with Google Gemini model"}],"default":"message","displayOptions":{"show":{"resource":["text"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. models/gemini-2.5-flash"}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"placeholder":"Add Message","default":{"values":[{"content":""}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Prompt","name":"content","type":"string","description":"The content of the message to be send","default":"","placeholder":"e.g. Hello, how can you help me?","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"Role in shaping the model's response, it tells the model how it should behave and interact with the user","options":[{"name":"User","value":"user","description":"Send a message as a user and get a response from the model"},{"name":"Model","value":"model","description":"Tell the model to adopt a specific tone or personality"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Output Content as JSON","name":"jsonOutput","type":"boolean","description":"Whether to attempt to return the response in JSON format","default":false,"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"System Message","name":"systemMessage","type":"string","default":"","placeholder":"e.g. You are a helpful assistant"},{"displayName":"Code Execution","name":"codeExecution","type":"boolean","default":false,"description":"Whether to allow the model to execute code it generates to produce a response. Supported only by certain models."},{"displayName":"Frequency Penalty","name":"frequencyPenalty","default":0,"description":"Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim","type":"number","typeOptions":{"minValue":-2,"maxValue":2,"numberPrecision":1}},{"displayName":"Maximum Number of Tokens","name":"maxOutputTokens","default":16,"description":"The maximum number of tokens to generate in the completion","type":"number","typeOptions":{"minValue":1,"numberPrecision":0}},{"displayName":"Number of Completions","name":"candidateCount","default":1,"description":"How many completions to generate for each prompt","type":"number","typeOptions":{"minValue":1,"maxValue":8,"numberPrecision":0}},{"displayName":"Presence Penalty","name":"presencePenalty","default":0,"description":"Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics","type":"number","typeOptions":{"minValue":-2,"maxValue":2,"numberPrecision":1}},{"displayName":"Output Randomness (Temperature)","name":"temperature","default":1,"description":"Controls the randomness of the output. Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive","type":"number","typeOptions":{"minValue":0,"maxValue":2,"numberPrecision":1}},{"displayName":"Output Randomness (Top P)","name":"topP","default":1,"description":"The maximum cumulative probability of tokens to consider when sampling","type":"number","typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}},{"displayName":"Output Randomness (Top K)","name":"topK","default":1,"description":"The maximum number of tokens to consider when sampling","type":"number","typeOptions":{"minValue":1,"numberPrecision":0}},{"displayName":"Thinking Budget","name":"thinkingBudget","type":"number","description":"Controls reasoning tokens for thinking models. Set to 0 to disable automatic thinking. Set to -1 for dynamic thinking. Leave empty for auto mode.","typeOptions":{"minValue":-1,"numberPrecision":0}},{"displayName":"Max Tool Calls Iterations","name":"maxToolsIterations","type":"number","default":15,"description":"The maximum number of tool iteration cycles the LLM will run before stopping. A single iteration can contain multiple tool calls. Set to 0 for no limit","typeOptions":{"minValue":0,"numberPrecision":0}}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Video","value":"analyze","action":"Analyze video","description":"Take in videos and answer questions about them"},{"name":"Generate a Video","value":"generate","action":"Generate a video","description":"Creates a video from a text prompt"},{"name":"Download Video","value":"download","action":"Download a video","description":"Download a generated video from the Google Gemini API using a URL"}],"default":"generate","displayOptions":{"show":{"resource":["video"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. models/gemini-2.5-flash"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["video"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this video?","default":"What's in this video?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["video"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Video URL(s)","value":"url"},{"name":"Binary File(s)","value":"binary"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["video"]}}},{"displayName":"URL(s)","name":"videoUrls","type":"string","placeholder":"e.g. https://example.com/video.mp4","description":"URL(s) of the video(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["video"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the video(s), seperate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["video"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["video"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed video description","name":"maxOutputTokens","type":"number","default":300,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["video"]}}},{"displayName":"URL","name":"url","type":"string","placeholder":"e.g. https://generativelanguage.googleapis.com/v1beta/files/abcdefg:download","description":"The URL from Google Gemini API to download the video from","default":"","displayOptions":{"show":{"operation":["download"],"resource":["video"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Put Output in Field","name":"binaryPropertyOutput","type":"string","default":"data","hint":"The name of the output field to put the binary file data in"}],"displayOptions":{"show":{"operation":["download"],"resource":["video"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"videoGenerationModelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. models/gemini-2.5-flash"}],"displayOptions":{"show":{"operation":["generate"],"resource":["video"]}}},{"displayName":"Prompt","name":"prompt","type":"string","placeholder":"e.g. Panning wide shot of a calico kitten sleeping in the sunshine","description":"A text description of the desired video","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["generate"],"resource":["video"]}}},{"displayName":"Return As","name":"returnAs","type":"options","options":[{"name":"Video","value":"video"},{"name":"URL","value":"url"}],"description":"Whether to return the video as a binary file or a URL that can be used to download the video later","default":"video","displayOptions":{"show":{"operation":["generate"],"resource":["video"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Number of Videos","name":"sampleCount","type":"number","default":1,"description":"How many videos to generate","typeOptions":{"minValue":1,"maxValue":4}},{"displayName":"Duration (Seconds)","name":"durationSeconds","type":"number","default":8,"description":"Length of the generated video in seconds. Supported only by certain models.","typeOptions":{"minValue":5,"maxValue":8}},{"displayName":"Aspect Ratio","name":"aspectRatio","type":"options","options":[{"name":"Widescreen (16:9)","value":"16:9","description":"Most common aspect ratio for televisions and monitors"},{"name":"Portrait (9:16)","value":"9:16","description":"Popular for short-form videos like YouTube Shorts"}],"default":"16:9"},{"displayName":"Person Generation","name":"personGeneration","type":"options","options":[{"name":"Don't Allow","value":"dont_allow","description":"Prevent generation of people in the video"},{"name":"Allow Adult","value":"allow_adult","description":"Allow generation of adult people in the video"},{"name":"Allow All","value":"allow_all","description":"Allow generation of all people in the video"}],"default":"dont_allow"},{"displayName":"Put Output in Field","name":"binaryPropertyOutput","type":"string","default":"data","hint":"The name of the output field to put the binary file data in"}],"displayOptions":{"show":{"operation":["generate"],"resource":["video"]}}}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/vendors/GoogleGemini/gemini.svg"},
4
4
  {"displayName":"Ollama","name":"ollama","group":["transform"],"version":1,"subtitle":"={{ $parameter[\"operation\"] + \": \" + $parameter[\"resource\"] }}","description":"Interact with Ollama AI models","defaults":{"name":"Ollama"},"usableAsTool":true,"codex":{"alias":["LangChain","image","vision","AI","local"],"categories":["AI"],"subcategories":{"AI":["Agents","Miscellaneous","Root Nodes"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.ollama/"}]}},"inputs":"={{\n\t\t(() => {\n\t\t\tconst resource = $parameter.resource;\n\t \tconst operation = $parameter.operation;\n\t\t\tif (resource === 'text' && operation === 'message') {\n\t\t\t\treturn [{ type: 'main' }, { type: 'ai_tool', displayName: 'Tools' }];\n\t\t\t}\n\n\t\t\treturn ['main'];\n\t\t})()\n\t}}","outputs":["main"],"credentials":[{"name":"ollamaApi","required":true}],"properties":[{"displayName":"Resource","name":"resource","type":"options","noDataExpression":true,"options":[{"name":"Image","value":"image"},{"name":"Text","value":"text"}],"default":"text"},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Image","value":"analyze","action":"Analyze image","description":"Take in images and answer questions about them"}],"default":"analyze","displayOptions":{"show":{"resource":["image"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. llava, llama3.2-vision"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this image?","default":"What's in this image?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"binary","options":[{"name":"Binary File(s)","value":"binary"},{"name":"Image URL(s)","value":"url"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Data Field Name(s)","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary field(s) which contains the image(s), separate multiple field names with commas","displayOptions":{"show":{"inputType":["binary"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"URL(s)","name":"imageUrls","type":"string","placeholder":"e.g. https://example.com/image.png","description":"URL(s) of the image(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"System Message","name":"system","type":"string","default":"","placeholder":"e.g. You are a helpful assistant.","description":"System message to set the context for the conversation","typeOptions":{"rows":2}},{"displayName":"Temperature","name":"temperature","type":"number","default":0.8,"typeOptions":{"minValue":0,"maxValue":2,"numberPrecision":2},"description":"Controls randomness in responses. Lower values make output more focused."},{"displayName":"Output Randomness (Top P)","name":"top_p","default":0.7,"description":"The maximum cumulative probability of tokens to consider when sampling","type":"number","typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}},{"displayName":"Top K","name":"top_k","type":"number","default":40,"typeOptions":{"minValue":1},"description":"Controls diversity by limiting the number of top tokens to consider"},{"displayName":"Max Tokens","name":"num_predict","type":"number","default":1024,"typeOptions":{"minValue":1,"numberPrecision":0},"description":"Maximum number of tokens to generate in the completion"},{"displayName":"Frequency Penalty","name":"frequency_penalty","type":"number","default":0,"typeOptions":{"minValue":0,"numberPrecision":2},"description":"Adjusts the penalty for tokens that have already appeared in the generated text. Higher values discourage repetition."},{"displayName":"Presence Penalty","name":"presence_penalty","type":"number","default":0,"typeOptions":{"numberPrecision":2},"description":"Adjusts the penalty for tokens based on their presence in the generated text so far. Positive values penalize tokens that have already appeared, encouraging diversity."},{"displayName":"Repetition Penalty","name":"repeat_penalty","type":"number","default":1.1,"typeOptions":{"minValue":0,"numberPrecision":2},"description":"Sets how strongly to penalize repetitions. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient."},{"displayName":"Context Length","name":"num_ctx","type":"number","default":4096,"typeOptions":{"minValue":1,"numberPrecision":0},"description":"Sets the size of the context window used to generate the next token"},{"displayName":"Repeat Last N","name":"repeat_last_n","type":"number","default":64,"typeOptions":{"minValue":-1,"numberPrecision":0},"description":"Sets how far back for the model to look back to prevent repetition. (0 = disabled, -1 = num_ctx)."},{"displayName":"Min P","name":"min_p","type":"number","default":0,"typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":3},"description":"Alternative to the top_p, and aims to ensure a balance of quality and variety. The parameter p represents the minimum probability for a token to be considered, relative to the probability of the most likely token."},{"displayName":"Seed","name":"seed","type":"number","default":0,"typeOptions":{"minValue":0,"numberPrecision":0},"description":"Sets the random number seed to use for generation. Setting this to a specific number will make the model generate the same text for the same prompt."},{"displayName":"Stop Sequences","name":"stop","type":"string","default":"","description":"Sets the stop sequences to use. When this pattern is encountered the LLM will stop generating text and return. Separate multiple patterns with commas"},{"displayName":"Keep Alive","name":"keep_alive","type":"string","default":"5m","description":"Specifies the duration to keep the loaded model in memory after use. Format: 1h30m (1 hour 30 minutes)."},{"displayName":"Low VRAM Mode","name":"low_vram","type":"boolean","default":false,"description":"Whether to activate low VRAM mode, which reduces memory usage at the cost of slower generation speed. Useful for GPUs with limited memory."},{"displayName":"Main GPU ID","name":"main_gpu","type":"number","default":0,"typeOptions":{"minValue":0,"numberPrecision":0},"description":"Specifies the ID of the GPU to use for the main computation. Only change this if you have multiple GPUs."},{"displayName":"Context Batch Size","name":"num_batch","type":"number","default":512,"typeOptions":{"minValue":1,"numberPrecision":0},"description":"Sets the batch size for prompt processing. Larger batch sizes may improve generation speed but increase memory usage."},{"displayName":"Number of GPUs","name":"num_gpu","type":"number","default":-1,"typeOptions":{"minValue":-1,"numberPrecision":0},"description":"Specifies the number of GPUs to use for parallel processing. Set to -1 for auto-detection."},{"displayName":"Number of CPU Threads","name":"num_thread","type":"number","default":0,"typeOptions":{"minValue":0,"numberPrecision":0},"description":"Specifies the number of CPU threads to use for processing. Set to 0 for auto-detection."},{"displayName":"Penalize Newlines","name":"penalize_newline","type":"boolean","default":true,"description":"Whether the model will be less likely to generate newline characters, encouraging longer continuous sequences of text"},{"displayName":"Use Memory Locking","name":"use_mlock","type":"boolean","default":false,"description":"Whether to lock the model in memory to prevent swapping. This can improve performance but requires sufficient available memory."},{"displayName":"Use Memory Mapping","name":"use_mmap","type":"boolean","default":true,"description":"Whether to use memory mapping for loading the model. This can reduce memory usage but may impact performance."},{"displayName":"Load Vocabulary Only","name":"vocab_only","type":"boolean","default":false,"description":"Whether to only load the model vocabulary without the weights. Useful for quickly testing tokenization."},{"displayName":"Output Format","name":"format","type":"options","options":[{"name":"Default","value":""},{"name":"JSON","value":"json"}],"default":"","description":"Specifies the format of the API response"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Message a Model","value":"message","action":"Message a model","description":"Send a message to Ollama model"}],"default":"message","displayOptions":{"show":{"resource":["text"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. llava, llama3.2-vision"}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"placeholder":"Add Message","default":{"values":[{"content":"","role":"user"}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Content","name":"content","type":"string","description":"The content of the message to be sent","default":"","placeholder":"e.g. Hello, how can you help me?","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"The role of this message in the conversation","options":[{"name":"User","value":"user","description":"Message from the user"},{"name":"Assistant","value":"assistant","description":"Response from the assistant (for conversation history)"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"System Message","name":"system","type":"string","default":"","placeholder":"e.g. You are a helpful assistant.","description":"System message to set the context for the conversation","typeOptions":{"rows":2}},{"displayName":"Temperature","name":"temperature","type":"number","default":0.8,"typeOptions":{"minValue":0,"maxValue":2,"numberPrecision":2},"description":"Controls randomness in responses. Lower values make output more focused."},{"displayName":"Output Randomness (Top P)","name":"top_p","default":0.7,"description":"The maximum cumulative probability of tokens to consider when sampling","type":"number","typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}},{"displayName":"Top K","name":"top_k","type":"number","default":40,"typeOptions":{"minValue":1},"description":"Controls diversity by limiting the number of top tokens to consider"},{"displayName":"Max Tokens","name":"num_predict","type":"number","default":1024,"typeOptions":{"minValue":1,"numberPrecision":0},"description":"Maximum number of tokens to generate in the completion"},{"displayName":"Frequency Penalty","name":"frequency_penalty","type":"number","default":0,"typeOptions":{"minValue":0,"numberPrecision":2},"description":"Adjusts the penalty for tokens that have already appeared in the generated text. Higher values discourage repetition."},{"displayName":"Presence Penalty","name":"presence_penalty","type":"number","default":0,"typeOptions":{"numberPrecision":2},"description":"Adjusts the penalty for tokens based on their presence in the generated text so far. Positive values penalize tokens that have already appeared, encouraging diversity."},{"displayName":"Repetition Penalty","name":"repeat_penalty","type":"number","default":1.1,"typeOptions":{"minValue":0,"numberPrecision":2},"description":"Sets how strongly to penalize repetitions. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient."},{"displayName":"Context Length","name":"num_ctx","type":"number","default":4096,"typeOptions":{"minValue":1,"numberPrecision":0},"description":"Sets the size of the context window used to generate the next token"},{"displayName":"Repeat Last N","name":"repeat_last_n","type":"number","default":64,"typeOptions":{"minValue":-1,"numberPrecision":0},"description":"Sets how far back for the model to look back to prevent repetition. (0 = disabled, -1 = num_ctx)."},{"displayName":"Min P","name":"min_p","type":"number","default":0,"typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":3},"description":"Alternative to the top_p, and aims to ensure a balance of quality and variety. The parameter p represents the minimum probability for a token to be considered, relative to the probability of the most likely token."},{"displayName":"Seed","name":"seed","type":"number","default":0,"typeOptions":{"minValue":0,"numberPrecision":0},"description":"Sets the random number seed to use for generation. Setting this to a specific number will make the model generate the same text for the same prompt."},{"displayName":"Stop Sequences","name":"stop","type":"string","default":"","description":"Sets the stop sequences to use. When this pattern is encountered the LLM will stop generating text and return. Separate multiple patterns with commas"},{"displayName":"Keep Alive","name":"keep_alive","type":"string","default":"5m","description":"Specifies the duration to keep the loaded model in memory after use. Format: 1h30m (1 hour 30 minutes)."},{"displayName":"Low VRAM Mode","name":"low_vram","type":"boolean","default":false,"description":"Whether to activate low VRAM mode, which reduces memory usage at the cost of slower generation speed. Useful for GPUs with limited memory."},{"displayName":"Main GPU ID","name":"main_gpu","type":"number","default":0,"typeOptions":{"minValue":0,"numberPrecision":0},"description":"Specifies the ID of the GPU to use for the main computation. Only change this if you have multiple GPUs."},{"displayName":"Context Batch Size","name":"num_batch","type":"number","default":512,"typeOptions":{"minValue":1,"numberPrecision":0},"description":"Sets the batch size for prompt processing. Larger batch sizes may improve generation speed but increase memory usage."},{"displayName":"Number of GPUs","name":"num_gpu","type":"number","default":-1,"typeOptions":{"minValue":-1,"numberPrecision":0},"description":"Specifies the number of GPUs to use for parallel processing. Set to -1 for auto-detection."},{"displayName":"Number of CPU Threads","name":"num_thread","type":"number","default":0,"typeOptions":{"minValue":0,"numberPrecision":0},"description":"Specifies the number of CPU threads to use for processing. Set to 0 for auto-detection."},{"displayName":"Penalize Newlines","name":"penalize_newline","type":"boolean","default":true,"description":"Whether the model will be less likely to generate newline characters, encouraging longer continuous sequences of text"},{"displayName":"Use Memory Locking","name":"use_mlock","type":"boolean","default":false,"description":"Whether to lock the model in memory to prevent swapping. This can improve performance but requires sufficient available memory."},{"displayName":"Use Memory Mapping","name":"use_mmap","type":"boolean","default":true,"description":"Whether to use memory mapping for loading the model. This can reduce memory usage but may impact performance."},{"displayName":"Load Vocabulary Only","name":"vocab_only","type":"boolean","default":false,"description":"Whether to only load the model vocabulary without the weights. Useful for quickly testing tokenization."},{"displayName":"Output Format","name":"format","type":"options","options":[{"name":"Default","value":""},{"name":"JSON","value":"json"}],"default":"","description":"Specifies the format of the API response"}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/vendors/Ollama/ollama.svg"},
5
5
  {"displayName":"OpenAI","name":"openAi","group":["transform"],"defaultVersion":2,"subtitle":"={{((resource, operation) => {\n if (operation === \"deleteAssistant\") {\n return \"Delete Assistant\";\n }\n if (operation === \"deleteFile\") {\n return \"Delete File\";\n }\n if (operation === \"classify\") {\n return \"Classify Text\";\n }\n if (operation === \"message\" && resource === \"text\") {\n return \"Message Model\";\n }\n const capitalize = (str) => {\n const chars = str.split(\"\");\n chars[0] = chars[0].toUpperCase();\n return chars.join(\"\");\n };\n if ([\"transcribe\", \"translate\"].includes(operation)) {\n resource = \"recording\";\n }\n if (operation === \"list\") {\n resource = resource + \"s\";\n }\n return `${capitalize(operation)} ${capitalize(resource)}`;\n})($parameter.resource, $parameter.operation)}}","description":"Message an assistant or GPT, analyze images, generate audio, etc.","codex":{"alias":["LangChain","ChatGPT","Sora","DallE","whisper","audio","transcribe","tts","assistant"],"categories":["AI"],"subcategories":{"AI":["Agents","Miscellaneous","Root Nodes"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/"}]}},"version":[1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8],"defaults":{"name":"OpenAI"},"inputs":"={{((resource, operation, hideTools, memory) => {\n if (resource === \"assistant\" && operation === \"message\") {\n const inputs = [\n { type: \"main\" },\n { type: \"ai_tool\", displayName: \"Tools\" }\n ];\n if (memory !== \"threadId\") {\n inputs.push({ type: \"ai_memory\", displayName: \"Memory\", maxConnections: 1 });\n }\n return inputs;\n }\n if (resource === \"text\" && (operation === \"message\" || operation === \"response\")) {\n if (hideTools === \"hide\") {\n return [\"main\"];\n }\n return [{ type: \"main\" }, { type: \"ai_tool\", displayName: \"Tools\" }];\n }\n return [\"main\"];\n})($parameter.resource, $parameter.operation, $parameter.hideTools, $parameter.memory ?? undefined)}}","outputs":["main"],"credentials":[{"name":"openAiApi","required":true}],"properties":[{"displayName":"Resource","name":"resource","type":"options","noDataExpression":true,"options":[{"name":"Assistant","value":"assistant"},{"name":"Text","value":"text"},{"name":"Image","value":"image"},{"name":"Audio","value":"audio"},{"name":"File","value":"file"}],"default":"text"},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Create an Assistant","value":"create","action":"Create an assistant","description":"Create a new assistant"},{"name":"Delete an Assistant","value":"deleteAssistant","action":"Delete an assistant","description":"Delete an assistant from the account"},{"name":"List Assistants","value":"list","action":"List assistants","description":"List assistants in the organization"},{"name":"Message an Assistant","value":"message","action":"Message an assistant","description":"Send messages to an assistant"},{"name":"Update an Assistant","value":"update","action":"Update an assistant","description":"Update an existing assistant"}],"default":"message","displayOptions":{"show":{"resource":["assistant"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. gpt-4"}],"displayOptions":{"show":{"operation":["create"],"resource":["assistant"]}}},{"displayName":"Name","name":"name","type":"string","default":"","description":"The name of the assistant. The maximum length is 256 characters.","placeholder":"e.g. My Assistant","required":true,"displayOptions":{"show":{"operation":["create"],"resource":["assistant"]}}},{"displayName":"Description","name":"description","type":"string","default":"","description":"The description of the assistant. The maximum length is 512 characters.","placeholder":"e.g. My personal assistant","displayOptions":{"show":{"operation":["create"],"resource":["assistant"]}}},{"displayName":"Instructions","name":"instructions","type":"string","description":"The system instructions that the assistant uses. The maximum length is 32768 characters.","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["create"],"resource":["assistant"]}}},{"displayName":"Code Interpreter","name":"codeInterpreter","type":"boolean","default":false,"description":"Whether to enable the code interpreter that allows the assistants to write and run Python code in a sandboxed execution environment, find more <a href=\"https://platform.openai.com/docs/assistants/tools/code-interpreter\" target=\"_blank\">here</a>","displayOptions":{"show":{"operation":["create"],"resource":["assistant"]}}},{"displayName":"Knowledge Retrieval","name":"knowledgeRetrieval","type":"boolean","default":false,"description":"Whether to augments the assistant with knowledge from outside its model, such as proprietary product information or documents, find more <a href=\"https://platform.openai.com/docs/assistants/tools/knowledge-retrieval\" target=\"_blank\">here</a>","displayOptions":{"show":{"operation":["create"],"resource":["assistant"]}}},{"displayName":"Files","name":"file_ids","type":"multiOptions","description":"The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant. You can use expression to pass file IDs as an array or comma-separated string.","typeOptions":{"loadOptionsMethod":"getFiles"},"default":[],"hint":"Add more files by using the 'Upload a File' operation","displayOptions":{"show":{"codeInterpreter":[true],"operation":["create"],"resource":["assistant"]},"hide":{"knowledgeRetrieval":[true]}}},{"displayName":"Files","name":"file_ids","type":"multiOptions","description":"The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant","typeOptions":{"loadOptionsMethod":"getFiles"},"default":[],"hint":"Add more files by using the 'Upload a File' operation","displayOptions":{"show":{"knowledgeRetrieval":[true],"operation":["create"],"resource":["assistant"]},"hide":{"codeInterpreter":[true]}}},{"displayName":"Files","name":"file_ids","type":"multiOptions","description":"The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant","typeOptions":{"loadOptionsMethod":"getFiles"},"default":[],"hint":"Add more files by using the 'Upload a File' operation","displayOptions":{"show":{"knowledgeRetrieval":[true],"codeInterpreter":[true],"operation":["create"],"resource":["assistant"]}}},{"displayName":"Add custom n8n tools when you <i>message</i> your assistant (rather than when creating it)","name":"noticeTools","type":"notice","default":"","displayOptions":{"show":{"operation":["create"],"resource":["assistant"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Output Randomness (Temperature)","name":"temperature","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive. We generally recommend altering this or temperature but not both.","type":"number"},{"displayName":"Output Randomness (Top P)","name":"topP","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"An alternative to sampling with temperature, controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.","type":"number"},{"displayName":"Fail if Assistant Already Exists","name":"failIfExists","type":"boolean","default":false,"description":"Whether to fail an operation if the assistant with the same name already exists"}],"displayOptions":{"show":{"operation":["create"],"resource":["assistant"]}}},{"displayName":"Assistant","name":"assistantId","type":"resourceLocator","description":"Assistant to respond to the message. You can add, modify or remove assistants in the <a href=\"https://platform.openai.com/playground?mode=assistant\" target=\"_blank\">playground</a>.","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"assistantSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. asst_abc123"}],"displayOptions":{"show":{"operation":["deleteAssistant"],"resource":["assistant"]}}},{"displayName":"Assistant","name":"assistantId","type":"resourceLocator","description":"Assistant to respond to the message. You can add, modify or remove assistants in the <a href=\"https://platform.openai.com/playground?mode=assistant\" target=\"_blank\">playground</a>.","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"assistantSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. asst_abc123"}],"displayOptions":{"show":{"operation":["message"],"resource":["assistant"]}}},{"displayName":"Source for Prompt (User Message)","name":"prompt","type":"options","options":[{"name":"Connected Chat Trigger Node","value":"auto","description":"Looks for an input field called 'chatInput' that is coming from a directly connected Chat Trigger"},{"name":"Define below","value":"define","description":"Use an expression to reference data in previous nodes or enter static text"}],"default":"auto","displayOptions":{"show":{"operation":["message"],"resource":["assistant"]}}},{"displayName":"Prompt (User Message)","name":"text","type":"string","default":"","placeholder":"e.g. Hello, how can you help me?","typeOptions":{"rows":2},"displayOptions":{"show":{"prompt":["define"],"operation":["message"],"resource":["assistant"]}}},{"displayName":"Memory","name":"memory","type":"options","options":[{"name":"Use memory connector","value":"connector","description":"Connect one of the supported memory nodes"},{"name":"Use thread ID","value":"threadId","description":"Specify the ID of the thread to continue"}],"displayOptions":{"show":{"@version":[{"_cnd":{"gte":1.6}}],"operation":["message"],"resource":["assistant"]}},"default":"connector"},{"displayName":"Thread ID","name":"threadId","type":"string","default":"","placeholder":"","description":"The ID of the thread to continue, a new thread will be created if not specified","hint":"If the thread ID is empty or undefined a new thread will be created and included in the response","displayOptions":{"show":{"@version":[{"_cnd":{"gte":1.6}}],"memory":["threadId"],"operation":["message"],"resource":["assistant"]}}},{"displayName":"Connect your own custom n8n tools to this node on the canvas","name":"noticeTools","type":"notice","default":"","displayOptions":{"show":{"operation":["message"],"resource":["assistant"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","description":"Additional options to add","type":"collection","default":{},"options":[{"displayName":"Base URL","name":"baseURL","default":"https://api.openai.com/v1","description":"Override the default base URL for the API","type":"string","displayOptions":{"hide":{"@version":[{"_cnd":{"gte":1.8}}]}}},{"displayName":"Max Retries","name":"maxRetries","default":2,"description":"Maximum number of retries to attempt","type":"number"},{"displayName":"Timeout","name":"timeout","default":10000,"description":"Maximum amount of time a request is allowed to take in milliseconds","type":"number"},{"displayName":"Preserve Original Tools","name":"preserveOriginalTools","type":"boolean","default":true,"description":"Whether to preserve the original tools of the assistant after the execution of this node, otherwise the tools will be replaced with the connected tools, if any, default is true","displayOptions":{"show":{"@version":[{"_cnd":{"gte":1.3}}]}}}],"displayOptions":{"show":{"operation":["message"],"resource":["assistant"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["list"],"resource":["assistant"]}}},{"displayName":"Assistant","name":"assistantId","type":"resourceLocator","description":"Assistant to respond to the message. You can add, modify or remove assistants in the <a href=\"https://platform.openai.com/playground?mode=assistant\" target=\"_blank\">playground</a>.","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"assistantSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. asst_abc123"}],"displayOptions":{"show":{"operation":["update"],"resource":["assistant"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Code Interpreter","name":"codeInterpreter","type":"boolean","default":false,"description":"Whether to enable the code interpreter that allows the assistants to write and run Python code in a sandboxed execution environment, find more <a href=\"https://platform.openai.com/docs/assistants/tools/code-interpreter\" target=\"_blank\">here</a>"},{"displayName":"Description","name":"description","type":"string","default":"","description":"The description of the assistant. The maximum length is 512 characters.","placeholder":"e.g. My personal assistant"},{"displayName":"Files","name":"file_ids","type":"multiOptions","description":"The files to be used by the assistant, there can be a maximum of 20 files attached to the assistant. You can use expression to pass file IDs as an array or comma-separated string.","typeOptions":{"loadOptionsMethod":"getFiles"},"default":[],"hint":"Add more files by using the 'Upload a File' operation, any existing files not selected here will be removed."},{"displayName":"Instructions","name":"instructions","type":"string","description":"The system instructions that the assistant uses. The maximum length is 32768 characters.","default":"","typeOptions":{"rows":2}},{"displayName":"Knowledge Retrieval","name":"knowledgeRetrieval","type":"boolean","default":false,"description":"Whether to augments the assistant with knowledge from outside its model, such as proprietary product information or documents, find more <a href=\"https://platform.openai.com/docs/assistants/tools/knowledge-retrieval\" target=\"_blank\">here</a>"},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":false,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. gpt-4"}]},{"displayName":"Name","name":"name","type":"string","default":"","description":"The name of the assistant. The maximum length is 256 characters.","placeholder":"e.g. My Assistant"},{"displayName":"Remove All Custom Tools (Functions)","name":"removeCustomTools","type":"boolean","default":false,"description":"Whether to remove all custom tools (functions) from the assistant"},{"displayName":"Output Randomness (Temperature)","name":"temperature","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive. We generally recommend altering this or temperature but not both.","type":"number"},{"displayName":"Output Randomness (Top P)","name":"topP","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"An alternative to sampling with temperature, controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.","type":"number"}],"displayOptions":{"show":{"operation":["update"],"resource":["assistant"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Generate Audio","value":"generate","action":"Generate audio","description":"Creates audio from a text prompt"},{"name":"Transcribe a Recording","value":"transcribe","action":"Transcribe a recording","description":"Transcribes audio into the text"},{"name":"Translate a Recording","value":"translate","action":"Translate a recording","description":"Translate audio into the text in the english language"}],"default":"generate","displayOptions":{"show":{"resource":["audio"]}}},{"displayName":"OpenAI API limits the size of the audio file to 25 MB","name":"fileSizeLimitNotice","type":"notice","default":" ","displayOptions":{"show":{"resource":["audio"],"operation":["translate","transcribe"]}}},{"displayName":"Model","name":"model","type":"options","default":"tts-1","options":[{"name":"TTS-1","value":"tts-1"},{"name":"TTS-1-HD","value":"tts-1-hd"}],"displayOptions":{"show":{"operation":["generate"],"resource":["audio"]}}},{"displayName":"Text Input","name":"input","type":"string","placeholder":"e.g. The quick brown fox jumped over the lazy dog","description":"The text to generate audio for. The maximum length is 4096 characters.","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["generate"],"resource":["audio"]}}},{"displayName":"Voice","name":"voice","type":"options","default":"alloy","description":"The voice to use when generating the audio","options":[{"name":"Alloy","value":"alloy"},{"name":"Echo","value":"echo"},{"name":"Fable","value":"fable"},{"name":"Nova","value":"nova"},{"name":"Onyx","value":"onyx"},{"name":"Shimmer","value":"shimmer"}],"displayOptions":{"show":{"operation":["generate"],"resource":["audio"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Response Format","name":"response_format","type":"options","default":"mp3","options":[{"name":"MP3","value":"mp3"},{"name":"OPUS","value":"opus"},{"name":"AAC","value":"aac"},{"name":"FLAC","value":"flac"}]},{"displayName":"Audio Speed","name":"speed","type":"number","default":1,"typeOptions":{"minValue":0.25,"maxValue":4,"numberPrecision":1}},{"displayName":"Put Output in Field","name":"binaryPropertyOutput","type":"string","default":"data","hint":"The name of the output field to put the binary file data in"}],"displayOptions":{"show":{"operation":["generate"],"resource":["audio"]}}},{"displayName":"Input Data Field Name","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary property which contains the audio file in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm","displayOptions":{"show":{"operation":["transcribe"],"resource":["audio"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Language of the Audio File","name":"language","type":"string","description":"The language of the input audio. Supplying the input language in <a href=\"https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes\" target=\"_blank\">ISO-639-1</a> format will improve accuracy and latency.","default":""},{"displayName":"Output Randomness (Temperature)","name":"temperature","type":"number","default":0,"typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}}],"displayOptions":{"show":{"operation":["transcribe"],"resource":["audio"]}}},{"displayName":"Input Data Field Name","name":"binaryPropertyName","type":"string","default":"data","hint":"The name of the input field containing the binary file data to be processed","placeholder":"e.g. data","description":"Name of the binary property which contains the audio file in one of these formats: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm","displayOptions":{"show":{"operation":["translate"],"resource":["audio"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Output Randomness (Temperature)","name":"temperature","type":"number","default":0,"typeOptions":{"minValue":0,"maxValue":1,"numberPrecision":1}}],"displayOptions":{"show":{"operation":["translate"],"resource":["audio"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Delete a File","value":"deleteFile","action":"Delete a file","description":"Delete a file from the server"},{"name":"List Files","value":"list","action":"List files","description":"Returns a list of files that belong to the user's organization"},{"name":"Upload a File","value":"upload","action":"Upload a file","description":"Upload a file that can be used across various endpoints"}],"default":"upload","displayOptions":{"show":{"resource":["file"]}}},{"displayName":"Input Data Field Name","name":"binaryPropertyName","type":"string","default":"data","hint":"The name of the input field containing the binary file data to be processed","placeholder":"e.g. data","description":"Name of the binary property which contains the file. The size of individual files can be a maximum of 512 MB or 2 million tokens for Assistants.","displayOptions":{"show":{"operation":["upload"],"resource":["file"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Purpose","name":"purpose","type":"options","default":"assistants","description":"The intended purpose of the uploaded file, the 'Fine-tuning' only supports .jsonl files","options":[{"name":"Assistants","value":"assistants"},{"name":"Fine-Tune","value":"fine-tune"}]}],"displayOptions":{"show":{"operation":["upload"],"resource":["file"]}}},{"displayName":"File","name":"fileId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"fileSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","validation":[{"type":"regex","properties":{"regex":"file-[a-zA-Z0-9]","errorMessage":"Not a valid File ID"}}],"placeholder":"e.g. file-1234567890"}],"displayOptions":{"show":{"operation":["deleteFile"],"resource":["file"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Purpose","name":"purpose","type":"options","default":"any","description":"Only return files with the given purpose","options":[{"name":"Any [Default]","value":"any"},{"name":"Assistants","value":"assistants"},{"name":"Fine-Tune","value":"fine-tune"}]}],"displayOptions":{"show":{"operation":["list"],"resource":["file"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Analyze Image","value":"analyze","action":"Analyze image","description":"Take in images and answer questions about them"},{"name":"Generate an Image","value":"generate","action":"Generate an image","description":"Creates an image from a text prompt"}],"default":"generate","displayOptions":{"show":{"resource":["image"]}}},{"displayName":"Model","name":"model","type":"options","default":"dall-e-3","description":"The model to use for image generation","options":[{"name":"DALL·E 2","value":"dall-e-2"},{"name":"DALL·E 3","value":"dall-e-3"},{"name":"GPT Image 1","value":"gpt-image-1"}],"displayOptions":{"show":{"operation":["generate"],"resource":["image"]}}},{"displayName":"Prompt","name":"prompt","type":"string","placeholder":"e.g. A cute cat eating a dinosaur","description":"A text description of the desired image(s). The maximum length is 1000 characters for dall-e-2 and 4000 characters for dall-e-3.","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["generate"],"resource":["image"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Number of Images","name":"n","default":1,"description":"Number of images to generate","type":"number","typeOptions":{"minValue":1,"maxValue":10},"displayOptions":{"show":{"/model":["dall-e-2"]}}},{"displayName":"Quality","name":"dalleQuality","type":"options","description":"The quality of the image that will be generated, HD creates images with finer details and greater consistency across the image","options":[{"name":"HD","value":"hd"},{"name":"Standard","value":"standard"}],"displayOptions":{"show":{"/model":["dall-e-3"]}},"default":"standard"},{"displayName":"Quality","name":"quality","type":"options","description":"The quality of the image that will be generated, High creates images with finer details and greater consistency across the image","options":[{"name":"High","value":"high"},{"name":"Medium","value":"medium"},{"name":"Low","value":"low"}],"displayOptions":{"show":{"/model":["gpt-image-1"]}},"default":"medium"},{"displayName":"Resolution","name":"size","type":"options","options":[{"name":"256x256","value":"256x256"},{"name":"512x512","value":"512x512"},{"name":"1024x1024","value":"1024x1024"}],"displayOptions":{"show":{"/model":["dall-e-2"]}},"default":"1024x1024"},{"displayName":"Resolution","name":"size","type":"options","options":[{"name":"1024x1024","value":"1024x1024"},{"name":"1792x1024","value":"1792x1024"},{"name":"1024x1792","value":"1024x1792"}],"displayOptions":{"show":{"/model":["dall-e-3"]}},"default":"1024x1024"},{"displayName":"Resolution","name":"size","type":"options","options":[{"name":"1024x1024","value":"1024x1024"},{"name":"1024x1536","value":"1024x1536"},{"name":"1536x1024","value":"1536x1024"}],"displayOptions":{"show":{"/model":["gpt-image-1"]}},"default":"1024x1024"},{"displayName":"Style","name":"style","type":"options","options":[{"name":"Natural","value":"natural","description":"Produce more natural looking images"},{"name":"Vivid","value":"vivid","description":"Lean towards generating hyper-real and dramatic images"}],"displayOptions":{"show":{"/model":["dall-e-3"]}},"default":"vivid"},{"displayName":"Respond with Image URL(s)","name":"returnImageUrls","type":"boolean","default":false,"description":"Whether to return image URL(s) instead of binary file(s)","displayOptions":{"hide":{"/model":["gpt-image-1"]}}},{"displayName":"Put Output in Field","name":"binaryPropertyOutput","type":"string","default":"data","hint":"The name of the output field to put the binary file data in","displayOptions":{"show":{"returnImageUrls":[false]}}}],"displayOptions":{"show":{"operation":["generate"],"resource":["image"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"imageModelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. gpt-4"}],"displayOptions":{"show":{"@version":[{"_cnd":{"gte":1.4}}],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Text Input","name":"text","type":"string","placeholder":"e.g. What's in this image?","default":"What's in this image?","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Type","name":"inputType","type":"options","default":"url","options":[{"name":"Image URL(s)","value":"url"},{"name":"Binary File(s)","value":"base64"}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"URL(s)","name":"imageUrls","type":"string","placeholder":"e.g. https://example.com/image.jpeg","description":"URL(s) of the image(s) to analyze, multiple URLs can be added separated by comma","default":"","displayOptions":{"show":{"inputType":["url"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Input Data Field Name","name":"binaryPropertyName","type":"string","default":"data","placeholder":"e.g. data","hint":"The name of the input field containing the binary file data to be processed","description":"Name of the binary property which contains the image(s)","displayOptions":{"show":{"inputType":["base64"],"operation":["analyze"],"resource":["image"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to simplify the response or not","displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Detail","name":"detail","type":"options","default":"auto","options":[{"name":"Auto","value":"auto","description":"Model will look at the image input size and decide if it should use the low or high setting"},{"name":"Low","value":"low","description":"Return faster responses and consume fewer tokens"},{"name":"High","value":"high","description":"Return more detailed responses, consumes more tokens"}]},{"displayName":"Length of Description (Max Tokens)","description":"Fewer tokens will result in shorter, less detailed image description","name":"maxTokens","type":"number","default":300,"typeOptions":{"minValue":1}}],"displayOptions":{"show":{"operation":["analyze"],"resource":["image"]}}},{"displayName":"Operation","name":"operation","type":"options","noDataExpression":true,"options":[{"name":"Message a Model","value":"message","action":"Message a model","description":"Create a completion with GPT 3, 4, etc."},{"name":"Classify Text for Violations","value":"classify","action":"Classify text for violations","description":"Check whether content complies with usage policies"}],"default":"message","displayOptions":{"show":{"resource":["text"]}}},{"displayName":"Text Input","name":"input","type":"string","placeholder":"e.g. Sample text goes here","description":"The input text to classify if it is violates the moderation policy","default":"","typeOptions":{"rows":2},"displayOptions":{"show":{"operation":["classify"],"resource":["text"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":false,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["classify"],"resource":["text"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Use Stable Model","name":"useStableModel","type":"boolean","default":false,"description":"Whether to use the stable version of the model instead of the latest version, accuracy may be slightly lower"}],"displayOptions":{"show":{"operation":["classify"],"resource":["text"]}}},{"displayName":"Model","name":"modelId","type":"resourceLocator","default":{"mode":"list","value":""},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","typeOptions":{"searchListMethod":"modelSearch","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"e.g. gpt-4"}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Messages","name":"messages","type":"fixedCollection","typeOptions":{"sortable":true,"multipleValues":true},"placeholder":"Add Message","default":{"values":[{"content":""}]},"options":[{"displayName":"Values","name":"values","values":[{"displayName":"Prompt","name":"content","type":"string","description":"The content of the message to be send","default":"","placeholder":"e.g. Hello, how can you help me?","typeOptions":{"rows":2}},{"displayName":"Role","name":"role","type":"options","description":"Role in shaping the model's response, it tells the model how it should behave and interact with the user","options":[{"name":"User","value":"user","description":"Send a message as a user and get a response from the model"},{"name":"Assistant","value":"assistant","description":"Tell the model to adopt a specific tone or personality"},{"name":"System","value":"system","description":"Usually used to set the model's behavior or context for the next user message"}],"default":"user"}]}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Simplify Output","name":"simplify","type":"boolean","default":true,"description":"Whether to return a simplified version of the response instead of the raw data","displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Output Content as JSON","name":"jsonOutput","type":"boolean","description":"Whether to attempt to return the response in JSON format. Compatible with GPT-4 Turbo and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106.","default":false,"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Hide Tools","name":"hideTools","type":"hidden","default":"hide","displayOptions":{"show":{"modelId":["gpt-3.5-turbo-16k-0613","dall-e-3","text-embedding-3-large","dall-e-2","whisper-1","tts-1-hd-1106","tts-1-hd","gpt-4-0314","text-embedding-3-small","gpt-4-32k-0314","gpt-3.5-turbo-0301","gpt-4-vision-preview","gpt-3.5-turbo-16k","gpt-3.5-turbo-instruct-0914","tts-1","davinci-002","gpt-3.5-turbo-instruct","babbage-002","tts-1-1106","text-embedding-ada-002"],"@version":[{"_cnd":{"gte":1.2}}],"operation":["message"],"resource":["text"]}}},{"displayName":"Connect your own custom n8n tools to this node on the canvas","name":"noticeTools","type":"notice","default":"","displayOptions":{"hide":{"hideTools":["hide"]},"show":{"operation":["message"],"resource":["text"]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","type":"collection","default":{},"options":[{"displayName":"Frequency Penalty","name":"frequency_penalty","default":0,"typeOptions":{"maxValue":2,"minValue":-2,"numberPrecision":1},"description":"Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim","type":"number"},{"displayName":"Maximum Number of Tokens","name":"maxTokens","default":16,"description":"The maximum number of tokens to generate in the completion. Most models have a context length of 2048 tokens (except for the newest models, which support 32,768).","type":"number","typeOptions":{"maxValue":32768}},{"displayName":"Number of Completions","name":"n","default":1,"description":"How many completions to generate for each prompt. Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop.","type":"number"},{"displayName":"Presence Penalty","name":"presence_penalty","default":0,"typeOptions":{"maxValue":2,"minValue":-2,"numberPrecision":1},"description":"Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics","type":"number"},{"displayName":"Output Randomness (Temperature)","name":"temperature","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive. We generally recommend altering this or temperature but not both.","type":"number"},{"displayName":"Output Randomness (Top P)","name":"topP","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"An alternative to sampling with temperature, controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.","type":"number"},{"displayName":"Reasoning Effort","name":"reasoning_effort","default":"medium","description":"Controls the amount of reasoning tokens to use. A value of \"low\" will favor speed and economical token usage, \"high\" will favor more complete reasoning at the cost of more tokens generated and slower responses.","type":"options","options":[{"name":"Low","value":"low","description":"Favors speed and economical token usage"},{"name":"Medium","value":"medium","description":"Balance between speed and reasoning accuracy"},{"name":"High","value":"high","description":"Favors more complete reasoning at the cost of more tokens generated and slower responses"}],"displayOptions":{"show":{"/modelId":[{"_cnd":{"regex":"(^o1([-\\d]+)?$)|(^o[3-9].*)|(^gpt-5.*)"}}]}}},{"displayName":"Max Tool Calls Iterations","name":"maxToolsIterations","type":"number","default":15,"description":"The maximum number of tool iteration cycles the LLM will run before stopping. A single iteration can contain multiple tool calls. Set to 0 for no limit.","displayOptions":{"show":{"@version":[{"_cnd":{"gte":1.5}}]}}}],"displayOptions":{"show":{"operation":["message"],"resource":["text"]}}}],"iconUrl":{"light":"icons/@n8n/n8n-nodes-langchain/dist/nodes/vendors/OpenAi/openAi.svg","dark":"icons/@n8n/n8n-nodes-langchain/dist/nodes/vendors/OpenAi/openAi.dark.svg"}},
@@ -31,7 +31,7 @@
31
31
  {"displayName":"Embeddings OpenAI","name":"embeddingsOpenAi","credentials":[{"name":"openAiApi","required":true}],"group":["transform"],"version":[1,1.1,1.2],"description":"Use Embeddings OpenAI","defaults":{"name":"Embeddings OpenAI"},"codex":{"categories":["AI"],"subcategories":{"AI":["Embeddings"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingsopenai/"}]}},"inputs":[],"outputs":["ai_embedding"],"outputNames":["Embeddings"],"requestDefaults":{"ignoreHttpStatusErrors":true,"baseURL":"={{ $parameter.options?.baseURL?.split(\"/\").slice(0,-1).join(\"/\") || $credentials.url?.split(\"/\").slice(0,-1).join(\"/\") || \"https://api.openai.com\" }}"},"properties":[{"displayName":"This node must be connected to a vector store. <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='ai_vectorStore'>Insert one</a>","name":"notice","type":"notice","default":"","typeOptions":{"containerClass":"ndv-connection-hint-notice"}},{"displayName":"Model","name":"model","type":"options","description":"The model which will generate the embeddings. <a href=\"https://platform.openai.com/docs/models/overview\">Learn more</a>.","typeOptions":{"loadOptions":{"routing":{"request":{"method":"GET","url":"={{ $parameter.options?.baseURL?.split(\"/\").slice(-1).pop() || $credentials?.url?.split(\"/\").slice(-1).pop() || \"v1\" }}/models"},"output":{"postReceive":[{"type":"rootProperty","properties":{"property":"data"}},{"type":"filter","properties":{"pass":"={{\n\t\t\t\t\t\t\t\t\t($parameter.options?.baseURL && !$parameter.options?.baseURL?.startsWith('https://api.openai.com/')) ||\n\t\t\t\t\t\t\t\t\t($credentials?.url && !$credentials.url.startsWith('https://api.openai.com/')) ||\n\t\t\t\t\t\t\t\t\t$responseItem.id.includes('embed')\n\t\t\t\t\t\t\t\t}}"}},{"type":"setKeyValue","properties":{"name":"={{$responseItem.id}}","value":"={{$responseItem.id}}"}},{"type":"sort","properties":{"key":"name"}}]}}}},"routing":{"send":{"type":"body","property":"model"}},"default":"text-embedding-ada-002","displayOptions":{"show":{"@version":[1]}}},{"displayName":"Model","name":"model","type":"options","description":"The model which will generate the embeddings. <a href=\"https://platform.openai.com/docs/models/overview\">Learn more</a>.","typeOptions":{"loadOptions":{"routing":{"request":{"method":"GET","url":"={{ $parameter.options?.baseURL?.split(\"/\").slice(-1).pop() || $credentials?.url?.split(\"/\").slice(-1).pop() || \"v1\" }}/models"},"output":{"postReceive":[{"type":"rootProperty","properties":{"property":"data"}},{"type":"filter","properties":{"pass":"={{\n\t\t\t\t\t\t\t\t\t($parameter.options?.baseURL && !$parameter.options?.baseURL?.startsWith('https://api.openai.com/')) ||\n\t\t\t\t\t\t\t\t\t($credentials?.url && !$credentials.url.startsWith('https://api.openai.com/')) ||\n\t\t\t\t\t\t\t\t\t$responseItem.id.includes('embed')\n\t\t\t\t\t\t\t\t}}"}},{"type":"setKeyValue","properties":{"name":"={{$responseItem.id}}","value":"={{$responseItem.id}}"}},{"type":"sort","properties":{"key":"name"}}]}}}},"routing":{"send":{"type":"body","property":"model"}},"default":"text-embedding-3-small","displayOptions":{"hide":{"@version":[1]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","description":"Additional options to add","type":"collection","default":{},"options":[{"displayName":"Dimensions","name":"dimensions","description":"The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.","type":"options","options":[{"name":"256","value":256},{"name":"512","value":512},{"name":"1024","value":1024},{"name":"1536","value":1536},{"name":"3072","value":3072}]},{"displayName":"Base URL","name":"baseURL","default":"https://api.openai.com/v1","description":"Override the default base URL for the API","type":"string","displayOptions":{"hide":{"@version":[{"_cnd":{"gte":1.2}}]}}},{"displayName":"Batch Size","name":"batchSize","default":512,"typeOptions":{"maxValue":2048},"description":"Maximum number of documents to send in each request","type":"number"},{"displayName":"Strip New Lines","name":"stripNewLines","default":true,"description":"Whether to strip new lines from the input text","type":"boolean"},{"displayName":"Timeout","name":"timeout","default":-1,"description":"Maximum amount of time a request is allowed to take in seconds. Set to -1 for no timeout.","type":"number"},{"displayName":"Encoding Format","name":"encodingFormat","type":"options","description":"The format to return the embeddings in","options":[{"name":"Float","value":"float"},{"name":"Base64","value":"base64"}]}]}],"iconUrl":{"light":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsOpenAI/openAiLight.svg","dark":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsOpenAI/openAiLight.dark.svg"}},
32
32
  {"displayName":"Embeddings Lemonade","name":"embeddingsLemonade","group":["transform"],"version":1,"description":"Use Lemonade Embeddings","defaults":{"name":"Embeddings Lemonade"},"credentials":[{"name":"lemonadeApi","required":true}],"requestDefaults":{"ignoreHttpStatusErrors":true,"baseURL":"={{ $credentials.baseUrl.replace(new RegExp(\"/$\"), \"\") }}"},"codex":{"categories":["AI"],"subcategories":{"AI":["Embeddings"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingslemonade/"}]}},"inputs":[],"outputs":["ai_embedding"],"outputNames":["Embeddings"],"properties":[{"displayName":"This node must be connected to a vector store. <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='ai_vectorStore'>Insert one</a>","name":"notice","type":"notice","default":"","typeOptions":{"containerClass":"ndv-connection-hint-notice"}},{"displayName":"Model","name":"model","type":"options","default":"","description":"The model which will generate the completion. Models are loaded and managed through the Lemonade server.","typeOptions":{"loadOptions":{"routing":{"request":{"method":"GET","url":"/models"},"output":{"postReceive":[{"type":"rootProperty","properties":{"property":"data"}},{"type":"setKeyValue","properties":{"name":"={{$responseItem.id}}","value":"={{$responseItem.id}}"}},{"type":"sort","properties":{"key":"name"}}]}}}},"routing":{"send":{"type":"body","property":"model"}},"required":true}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsLemonade/lemonade.svg"},
33
33
  {"displayName":"Embeddings Ollama","name":"embeddingsOllama","group":["transform"],"version":1,"description":"Use Ollama Embeddings","defaults":{"name":"Embeddings Ollama"},"credentials":[{"name":"ollamaApi","required":true}],"requestDefaults":{"ignoreHttpStatusErrors":true,"baseURL":"={{ $credentials.baseUrl.replace(new RegExp(\"/$\"), \"\") }}"},"codex":{"categories":["AI"],"subcategories":{"AI":["Embeddings"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.embeddingsollama/"}]}},"inputs":[],"outputs":["ai_embedding"],"outputNames":["Embeddings"],"properties":[{"displayName":"This node must be connected to a vector store. <a data-action='openSelectiveNodeCreator' data-action-parameter-connectiontype='ai_vectorStore'>Insert one</a>","name":"notice","type":"notice","default":"","typeOptions":{"containerClass":"ndv-connection-hint-notice"}},{"displayName":"Model","name":"model","type":"options","default":"llama3.2","description":"The model which will generate the completion. To download models, visit <a href=\"https://ollama.ai/library\">Ollama Models Library</a>.","typeOptions":{"loadOptions":{"routing":{"request":{"method":"GET","url":"/api/tags"},"output":{"postReceive":[{"type":"rootProperty","properties":{"property":"models"}},{"type":"setKeyValue","properties":{"name":"={{$responseItem.name}}","value":"={{$responseItem.name}}"}},{"type":"sort","properties":{"key":"name"}}]}}}},"routing":{"send":{"type":"body","property":"model"}},"required":true}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsOllama/ollama.svg"},
34
- {"displayName":"Anthropic Chat Model","name":"lmChatAnthropic","group":["transform"],"version":[1,1.1,1.2,1.3],"defaultVersion":1.3,"description":"Language Model Anthropic","defaults":{"name":"Anthropic Chat Model"},"codex":{"categories":["AI"],"subcategories":{"AI":["Language Models","Root Nodes"],"Language Models":["Chat Models (Recommended)"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatanthropic/"}]},"alias":["claude","sonnet","opus"]},"inputs":[],"outputs":["ai_languageModel"],"outputNames":["Model"],"credentials":[{"name":"anthropicApi","required":true}],"properties":[{"displayName":"This node must be connected to an AI chain. <a data-action='openSelectiveNodeCreator' data-action-parameter-creatorview='AI'>Insert one</a>","name":"notice","type":"notice","default":"","typeOptions":{"containerClass":"ndv-connection-hint-notice"}},{"displayName":"Model","name":"model","type":"options","options":[{"name":"Claude 3.5 Sonnet(20241022)","value":"claude-3-5-sonnet-20241022"},{"name":"Claude 3 Opus(20240229)","value":"claude-3-opus-20240229"},{"name":"Claude 3.5 Sonnet(20240620)","value":"claude-3-5-sonnet-20240620"},{"name":"Claude 3 Sonnet(20240229)","value":"claude-3-sonnet-20240229"},{"name":"Claude 3.5 Haiku(20241022)","value":"claude-3-5-haiku-20241022"},{"name":"Claude 3 Haiku(20240307)","value":"claude-3-haiku-20240307"},{"name":"LEGACY: Claude 2","value":"claude-2"},{"name":"LEGACY: Claude 2.1","value":"claude-2.1"},{"name":"LEGACY: Claude Instant 1.2","value":"claude-instant-1.2"},{"name":"LEGACY: Claude Instant 1","value":"claude-instant-1"}],"description":"The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.","default":"claude-2","displayOptions":{"show":{"@version":[1]}}},{"displayName":"Model","name":"model","type":"options","options":[{"name":"Claude 3.5 Sonnet(20241022)","value":"claude-3-5-sonnet-20241022"},{"name":"Claude 3 Opus(20240229)","value":"claude-3-opus-20240229"},{"name":"Claude 3.5 Sonnet(20240620)","value":"claude-3-5-sonnet-20240620"},{"name":"Claude 3 Sonnet(20240229)","value":"claude-3-sonnet-20240229"},{"name":"Claude 3.5 Haiku(20241022)","value":"claude-3-5-haiku-20241022"},{"name":"Claude 3 Haiku(20240307)","value":"claude-3-haiku-20240307"},{"name":"LEGACY: Claude 2","value":"claude-2"},{"name":"LEGACY: Claude 2.1","value":"claude-2.1"},{"name":"LEGACY: Claude Instant 1.2","value":"claude-instant-1.2"},{"name":"LEGACY: Claude Instant 1","value":"claude-instant-1"}],"description":"The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.","default":"claude-3-sonnet-20240229","displayOptions":{"show":{"@version":[1.1]}}},{"displayName":"Model","name":"model","type":"options","options":[{"name":"Claude 3.5 Sonnet(20241022)","value":"claude-3-5-sonnet-20241022"},{"name":"Claude 3 Opus(20240229)","value":"claude-3-opus-20240229"},{"name":"Claude 3.5 Sonnet(20240620)","value":"claude-3-5-sonnet-20240620"},{"name":"Claude 3 Sonnet(20240229)","value":"claude-3-sonnet-20240229"},{"name":"Claude 3.5 Haiku(20241022)","value":"claude-3-5-haiku-20241022"},{"name":"Claude 3 Haiku(20240307)","value":"claude-3-haiku-20240307"}],"description":"The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.","default":"claude-3-5-sonnet-20240620","displayOptions":{"show":{"@version":[{"_cnd":{"lte":1.2}}]}}},{"displayName":"Model","name":"model","type":"resourceLocator","default":{"mode":"list","value":"claude-sonnet-4-20250514","cachedResultName":"Claude 4 Sonnet"},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","placeholder":"Select a model...","typeOptions":{"searchListMethod":"searchModels","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"Claude Sonnet"}],"description":"The model. Choose from the list, or specify an ID. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.","displayOptions":{"show":{"@version":[{"_cnd":{"gte":1.3}}]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","description":"Additional options to add","type":"collection","default":{},"options":[{"displayName":"Maximum Number of Tokens","name":"maxTokensToSample","default":4096,"description":"The maximum number of tokens to generate in the completion","type":"number"},{"displayName":"Sampling Temperature","name":"temperature","default":0.7,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.","type":"number","displayOptions":{"hide":{"thinking":[true]}}},{"displayName":"Top K","name":"topK","default":-1,"typeOptions":{"maxValue":1,"minValue":-1,"numberPrecision":1},"description":"Used to remove \"long tail\" low probability responses. Defaults to -1, which disables it.","type":"number","displayOptions":{"hide":{"thinking":[true]}}},{"displayName":"Top P","name":"topP","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.","type":"number","displayOptions":{"hide":{"thinking":[true]}}},{"displayName":"Enable Thinking","name":"thinking","type":"boolean","default":false,"description":"Whether to enable thinking mode for the model"},{"displayName":"Thinking Budget (Tokens)","name":"thinkingBudget","type":"number","default":1024,"description":"The maximum number of tokens to use for thinking","displayOptions":{"show":{"thinking":[true]}}}]}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LMChatAnthropic/anthropic.svg"},
34
+ {"displayName":"Anthropic Chat Model","name":"lmChatAnthropic","group":["transform"],"version":[1,1.1,1.2,1.3],"defaultVersion":1.3,"description":"Language Model Anthropic","defaults":{"name":"Anthropic Chat Model"},"codex":{"categories":["AI"],"subcategories":{"AI":["Language Models","Root Nodes"],"Language Models":["Chat Models (Recommended)"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatanthropic/"}]},"alias":["claude","sonnet","opus"]},"inputs":[],"outputs":["ai_languageModel"],"outputNames":["Model"],"credentials":[{"name":"anthropicApi","required":true}],"properties":[{"displayName":"This node must be connected to an AI chain. <a data-action='openSelectiveNodeCreator' data-action-parameter-creatorview='AI'>Insert one</a>","name":"notice","type":"notice","default":"","typeOptions":{"containerClass":"ndv-connection-hint-notice"}},{"displayName":"Model","name":"model","type":"options","options":[{"name":"Claude 3.5 Sonnet(20241022)","value":"claude-3-5-sonnet-20241022"},{"name":"Claude 3 Opus(20240229)","value":"claude-3-opus-20240229"},{"name":"Claude 3.5 Sonnet(20240620)","value":"claude-3-5-sonnet-20240620"},{"name":"Claude 3 Sonnet(20240229)","value":"claude-3-sonnet-20240229"},{"name":"Claude 3.5 Haiku(20241022)","value":"claude-3-5-haiku-20241022"},{"name":"Claude 3 Haiku(20240307)","value":"claude-3-haiku-20240307"},{"name":"LEGACY: Claude 2","value":"claude-2"},{"name":"LEGACY: Claude 2.1","value":"claude-2.1"},{"name":"LEGACY: Claude Instant 1.2","value":"claude-instant-1.2"},{"name":"LEGACY: Claude Instant 1","value":"claude-instant-1"}],"description":"The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.","default":"claude-2","displayOptions":{"show":{"@version":[1]}}},{"displayName":"Model","name":"model","type":"options","options":[{"name":"Claude 3.5 Sonnet(20241022)","value":"claude-3-5-sonnet-20241022"},{"name":"Claude 3 Opus(20240229)","value":"claude-3-opus-20240229"},{"name":"Claude 3.5 Sonnet(20240620)","value":"claude-3-5-sonnet-20240620"},{"name":"Claude 3 Sonnet(20240229)","value":"claude-3-sonnet-20240229"},{"name":"Claude 3.5 Haiku(20241022)","value":"claude-3-5-haiku-20241022"},{"name":"Claude 3 Haiku(20240307)","value":"claude-3-haiku-20240307"},{"name":"LEGACY: Claude 2","value":"claude-2"},{"name":"LEGACY: Claude 2.1","value":"claude-2.1"},{"name":"LEGACY: Claude Instant 1.2","value":"claude-instant-1.2"},{"name":"LEGACY: Claude Instant 1","value":"claude-instant-1"}],"description":"The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.","default":"claude-3-sonnet-20240229","displayOptions":{"show":{"@version":[1.1]}}},{"displayName":"Model","name":"model","type":"options","options":[{"name":"Claude 3.5 Sonnet(20241022)","value":"claude-3-5-sonnet-20241022"},{"name":"Claude 3 Opus(20240229)","value":"claude-3-opus-20240229"},{"name":"Claude 3.5 Sonnet(20240620)","value":"claude-3-5-sonnet-20240620"},{"name":"Claude 3 Sonnet(20240229)","value":"claude-3-sonnet-20240229"},{"name":"Claude 3.5 Haiku(20241022)","value":"claude-3-5-haiku-20241022"},{"name":"Claude 3 Haiku(20240307)","value":"claude-3-haiku-20240307"}],"description":"The model which will generate the completion. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.","default":"claude-3-5-sonnet-20240620","displayOptions":{"show":{"@version":[{"_cnd":{"lte":1.2}}]}}},{"displayName":"Model","name":"model","type":"resourceLocator","default":{"mode":"list","value":"claude-sonnet-4-5-20250929","cachedResultName":"Claude Sonnet 4.5"},"required":true,"modes":[{"displayName":"From List","name":"list","type":"list","placeholder":"Select a model...","typeOptions":{"searchListMethod":"searchModels","searchable":true}},{"displayName":"ID","name":"id","type":"string","placeholder":"Claude Sonnet"}],"description":"The model. Choose from the list, or specify an ID. <a href=\"https://docs.anthropic.com/claude/docs/models-overview\">Learn more</a>.","displayOptions":{"show":{"@version":[{"_cnd":{"gte":1.3}}]}}},{"displayName":"Options","name":"options","placeholder":"Add Option","description":"Additional options to add","type":"collection","default":{},"options":[{"displayName":"Maximum Number of Tokens","name":"maxTokensToSample","default":4096,"description":"The maximum number of tokens to generate in the completion","type":"number"},{"displayName":"Sampling Temperature","name":"temperature","default":0.7,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.","type":"number","displayOptions":{"hide":{"thinking":[true]}}},{"displayName":"Top K","name":"topK","default":-1,"typeOptions":{"maxValue":1,"minValue":-1,"numberPrecision":1},"description":"Used to remove \"long tail\" low probability responses. Defaults to -1, which disables it.","type":"number","displayOptions":{"hide":{"thinking":[true]}}},{"displayName":"Top P","name":"topP","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.","type":"number","displayOptions":{"hide":{"thinking":[true]}}},{"displayName":"Enable Thinking","name":"thinking","type":"boolean","default":false,"description":"Whether to enable thinking mode for the model"},{"displayName":"Thinking Budget (Tokens)","name":"thinkingBudget","type":"number","default":1024,"description":"The maximum number of tokens to use for thinking","displayOptions":{"show":{"thinking":[true]}}}]}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LMChatAnthropic/anthropic.svg"},
35
35
  {"displayName":"Azure OpenAI Chat Model","name":"lmChatAzureOpenAi","group":["transform"],"version":1,"description":"For advanced usage with an AI chain","defaults":{"name":"Azure OpenAI Chat Model"},"codex":{"categories":["AI"],"subcategories":{"AI":["Language Models","Root Nodes"],"Language Models":["Chat Models (Recommended)"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatazureopenai/"}]}},"inputs":[],"outputs":["ai_languageModel"],"outputNames":["Model"],"credentials":[{"name":"azureOpenAiApi","required":true,"displayOptions":{"show":{"authentication":["azureOpenAiApi"]}}},{"name":"azureEntraCognitiveServicesOAuth2Api","required":true,"displayOptions":{"show":{"authentication":["azureEntraCognitiveServicesOAuth2Api"]}}}],"properties":[{"displayName":"Authentication","name":"authentication","type":"options","default":"azureOpenAiApi","options":[{"name":"API Key","value":"azureOpenAiApi"},{"name":"Azure Entra ID (OAuth2)","value":"azureEntraCognitiveServicesOAuth2Api"}]},{"displayName":"This node must be connected to an AI chain. <a data-action='openSelectiveNodeCreator' data-action-parameter-creatorview='AI'>Insert one</a>","name":"notice","type":"notice","default":"","typeOptions":{"containerClass":"ndv-connection-hint-notice"}},{"displayName":"If using JSON response format, you must include word \"json\" in the prompt in your chain or agent. Also, make sure to select latest models released post November 2023.","name":"notice","type":"notice","default":"","displayOptions":{"show":{"/options.responseFormat":["json_object"]}}},{"displayName":"Model (Deployment) Name","name":"model","type":"string","description":"The name of the model(deployment) to use (e.g., gpt-4, gpt-35-turbo)","required":true,"default":""},{"displayName":"Options","name":"options","placeholder":"Add Option","description":"Additional options to add","type":"collection","default":{},"options":[{"displayName":"Frequency Penalty","name":"frequencyPenalty","default":0,"typeOptions":{"maxValue":2,"minValue":-2,"numberPrecision":1},"description":"Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim","type":"number"},{"displayName":"Maximum Number of Tokens","name":"maxTokens","default":-1,"description":"The maximum number of tokens to generate in the completion. Most models have a context length of 2048 tokens (except for the newest models, which support 32,768). Use -1 for default.","type":"number","typeOptions":{"maxValue":128000}},{"displayName":"Response Format","name":"responseFormat","default":"text","type":"options","options":[{"name":"Text","value":"text","description":"Regular text response"},{"name":"JSON","value":"json_object","description":"Enables JSON mode, which should guarantee the message the model generates is valid JSON"}]},{"displayName":"Presence Penalty","name":"presencePenalty","default":0,"typeOptions":{"maxValue":2,"minValue":-2,"numberPrecision":1},"description":"Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics","type":"number"},{"displayName":"Sampling Temperature","name":"temperature","default":0.7,"typeOptions":{"maxValue":2,"minValue":0,"numberPrecision":1},"description":"Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.","type":"number"},{"displayName":"Timeout (Ms)","name":"timeout","default":60000,"description":"Maximum amount of time a request is allowed to take in milliseconds","type":"number"},{"displayName":"Max Retries","name":"maxRetries","default":2,"description":"Maximum number of retries to attempt on failure","type":"number"},{"displayName":"Top P","name":"topP","default":1,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered. We generally recommend altering this or temperature but not both.","type":"number"}]}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LmChatAzureOpenAi/azure.svg"},
36
36
  {"displayName":"AWS Bedrock Chat Model","name":"lmChatAwsBedrock","group":["transform"],"version":[1,1.1],"description":"Language Model AWS Bedrock","defaults":{"name":"AWS Bedrock Chat Model"},"codex":{"categories":["AI"],"subcategories":{"AI":["Language Models","Root Nodes"],"Language Models":["Chat Models (Recommended)"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatawsbedrock/"}]}},"inputs":[],"outputs":["ai_languageModel"],"outputNames":["Model"],"credentials":[{"name":"aws","required":true}],"requestDefaults":{"ignoreHttpStatusErrors":true,"baseURL":"=https://bedrock.{{$credentials?.region ?? \"eu-central-1\"}}.amazonaws.com"},"properties":[{"displayName":"This node must be connected to an AI chain. <a data-action='openSelectiveNodeCreator' data-action-parameter-creatorview='AI'>Insert one</a>","name":"notice","type":"notice","default":"","typeOptions":{"containerClass":"ndv-connection-hint-notice"}},{"displayName":"Model Source","name":"modelSource","type":"options","displayOptions":{"show":{"@version":[{"_cnd":{"gte":1.1}}]}},"options":[{"name":"On-Demand Models","value":"onDemand","description":"Standard foundation models with on-demand pricing"},{"name":"Inference Profiles","value":"inferenceProfile","description":"Cross-region inference profiles (required for models like Claude Sonnet 4 and others)"}],"default":"onDemand","description":"Choose between on-demand foundation models or inference profiles"},{"displayName":"Model","name":"model","type":"options","allowArbitraryValues":true,"description":"The model which will generate the completion. <a href=\"https://docs.aws.amazon.com/bedrock/latest/userguide/foundation-models.html\">Learn more</a>.","displayOptions":{"hide":{"modelSource":["inferenceProfile"]}},"typeOptions":{"loadOptionsDependsOn":["modelSource"],"loadOptions":{"routing":{"request":{"method":"GET","url":"/foundation-models?&byOutputModality=TEXT&byInferenceType=ON_DEMAND"},"output":{"postReceive":[{"type":"rootProperty","properties":{"property":"modelSummaries"}},{"type":"setKeyValue","properties":{"name":"={{$responseItem.modelName}}","description":"={{$responseItem.modelArn}}","value":"={{$responseItem.modelId}}"}},{"type":"sort","properties":{"key":"name"}}]}}}},"routing":{"send":{"type":"body","property":"model"}},"default":""},{"displayName":"Model","name":"model","type":"options","allowArbitraryValues":true,"description":"The inference profile which will generate the completion. <a href=\"https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-use.html\">Learn more</a>.","displayOptions":{"show":{"modelSource":["inferenceProfile"]}},"typeOptions":{"loadOptionsDependsOn":["modelSource"],"loadOptions":{"routing":{"request":{"method":"GET","url":"/inference-profiles?maxResults=1000"},"output":{"postReceive":[{"type":"rootProperty","properties":{"property":"inferenceProfileSummaries"}},{"type":"setKeyValue","properties":{"name":"={{$responseItem.inferenceProfileName}}","description":"={{$responseItem.description || $responseItem.inferenceProfileArn}}","value":"={{$responseItem.inferenceProfileId}}"}},{"type":"sort","properties":{"key":"name"}}]}}}},"routing":{"send":{"type":"body","property":"model"}},"default":""},{"displayName":"Options","name":"options","placeholder":"Add Option","description":"Additional options to add","type":"collection","default":{},"options":[{"displayName":"Maximum Number of Tokens","name":"maxTokensToSample","default":2000,"description":"The maximum number of tokens to generate in the completion","type":"number"},{"displayName":"Sampling Temperature","name":"temperature","default":0.7,"typeOptions":{"maxValue":1,"minValue":0,"numberPrecision":1},"description":"Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.","type":"number"}]}],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LmChatAwsBedrock/bedrock.svg"},
37
37
  {"displayName":"Cohere Chat Model","name":"lmChatCohere","group":["transform"],"version":[1],"description":"For advanced usage with an AI chain","defaults":{"name":"Cohere Chat Model"},"codex":{"categories":["AI"],"subcategories":{"AI":["Language Models","Root Nodes"],"Language Models":["Chat Models (Recommended)"]},"resources":{"primaryDocumentation":[{"url":"https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatcohere/"}]}},"inputs":[],"outputs":["ai_languageModel"],"outputNames":["Model"],"credentials":[{"name":"cohereApi","required":true}],"requestDefaults":{"baseURL":"={{$credentials?.url}}","headers":{"accept":"application/json","authorization":"=Bearer {{$credentials?.apiKey}}"}},"properties":[{"displayName":"This node must be connected to an AI chain. <a data-action='openSelectiveNodeCreator' data-action-parameter-creatorview='AI'>Insert one</a>","name":"notice","type":"notice","default":"","typeOptions":{"containerClass":"ndv-connection-hint-notice"}},{"displayName":"Model","name":"model","type":"options","description":"The model which will generate the completion. <a href=\"https://docs.cohere.com/docs/models\">Learn more</a>.","typeOptions":{"loadOptions":{"routing":{"request":{"method":"GET","url":"/v1/models?page_size=100&endpoint=chat"},"output":{"postReceive":[{"type":"rootProperty","properties":{"property":"models"}},{"type":"setKeyValue","properties":{"name":"={{$responseItem.name}}","value":"={{$responseItem.name}}","description":"={{$responseItem.description}}"}},{"type":"sort","properties":{"key":"name"}}]}}}},"default":"command-a-03-2025"},{"displayName":"Options","name":"options","placeholder":"Add Option","description":"Additional options to add","type":"collection","default":{},"options":[{"displayName":"Sampling Temperature","name":"temperature","default":0.7,"typeOptions":{"maxValue":2,"minValue":0,"numberPrecision":1},"description":"Controls randomness: Lowering results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive.","type":"number"},{"displayName":"Max Retries","name":"maxRetries","default":2,"description":"Maximum number of retries to attempt","type":"number"}]}],"iconUrl":{"light":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LmChatCohere/cohere.svg","dark":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LmChatCohere/cohere.dark.svg"}},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n8n/n8n-nodes-langchain",
3
- "version": "1.116.2",
3
+ "version": "1.117.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -154,8 +154,8 @@
154
154
  "fast-glob": "3.2.12",
155
155
  "jest-mock-extended": "^3.0.4",
156
156
  "tsup": "^8.5.0",
157
- "n8n-core": "1.116.0",
158
- "@n8n/eslint-plugin-community-nodes": "0.6.0"
157
+ "@n8n/eslint-plugin-community-nodes": "0.6.0",
158
+ "n8n-core": "1.117.0"
159
159
  },
160
160
  "dependencies": {
161
161
  "@aws-sdk/client-sso-oidc": "3.808.0",
@@ -223,13 +223,13 @@
223
223
  "zod": "3.25.67",
224
224
  "zod-to-json-schema": "3.23.3",
225
225
  "@n8n/client-oauth2": "0.30.0",
226
- "@n8n/config": "1.59.0",
226
+ "@n8n/config": "1.60.0",
227
227
  "@n8n/di": "0.9.0",
228
228
  "@n8n/errors": "^0.5.0",
229
229
  "@n8n/json-schema-to-zod": "1.5.0",
230
230
  "@n8n/typescript-config": "1.3.0",
231
- "n8n-workflow": "1.114.0",
232
- "n8n-nodes-base": "1.115.0"
231
+ "n8n-workflow": "1.115.0",
232
+ "n8n-nodes-base": "1.116.0"
233
233
  },
234
234
  "license": "SEE LICENSE IN LICENSE.md",
235
235
  "homepage": "https://n8n.io",