Skip to content

Custom Code Tool node#

Custom Code Tool 节点#

Use the Custom Code Tool node to write code that an agent can run.

使用 Custom Code Tool 节点编写 代理 可以运行的代码。

On this page, you'll find the node parameters for the Custom Code Tool node and links to more resources.

在此页面上,您将找到 Custom Code Tool 节点的节点参数以及更多资源的链接。

子节点中的参数解析

子节点在使用表达式处理多个项目时的行为与其他节点不同。

大多数节点,包括根节点,接受任意数量的项目作为输入,处理这些项目,并输出结果。您可以使用表达式引用输入项目,节点会依次为每个项目解析表达式。例如,给定五个 name 值的输入,表达式 {{ $json.name }} 会依次解析为每个名称。

在子节点中,表达式始终解析为第一个项目。例如,给定五个 name 值的输入,表达式 {{ $json.name }} 始终解析为第一个名称。

Node parameters#

节点参数#

Description#

描述#

Give your custom code a description. This tells the agent when to use this tool. For example:

为您的自定义代码提供描述。这告诉代理何时使用此工具。例如:

Call this tool to get a random color. The input should be a string with comma separated names of colors to exclude.

调用此工具以获取随机颜色。输入应该是用逗号分隔的要排除的颜色名称字符串。

Language#

语言#

You can use JavaScript or Python.

您可以使用 JavaScript 或 Python。

JavaScript / Python box#

JavaScript / Python 框#

Write the code here.

在此处编写代码。

You can access the tool input using query. For example, to take the input string and lowercase it:

您可以使用 query 访问工具输入。例如,要获取输入字符串并将其转换为小写:

1
2
let myString = query;
return myString.toLowerCase();

Templates and examples#

模板和示例#

Browse 自定义代码工具 integration templates, or search all templates

相关资源#

有关 LangChain 中工具的更多信息,请参阅 LangChain 关于工具的文档

查看 n8n 的高级 AI文档。

AI 术语表#

  • completion(完成/补全): 完成是由 GPT 等模型生成的响应。
  • hallucinations(幻觉): AI 中的幻觉是指大语言模型(LLM)错误地感知到不存在的模式或对象。
  • vector database(向量数据库): 向量数据库存储信息的数学表示。与嵌入和检索器一起使用,创建 AI 在回答问题时可以访问的数据库。
  • vector store(向量存储): 向量存储或向量数据库,存储信息的数学表示。与嵌入和检索器一起使用,创建 AI 在回答问题时可以访问的数据库。