Skip to content

自定义代码工具节点(Custom Code Tool node)#

使用自定义代码工具节点来编写 agent 可以运行的代码。

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

本页提供“自定义代码工具”节点的节点参数以及更多资源的链接。

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

Parameter resolution in sub-nodes

Sub-nodes behave differently to other nodes when processing multiple items using an expression.

Most nodes, including root nodes, take any number of items as input, process these items, and output the results. You can use expressions to refer to input items, and the node resolves the expression for each item in turn. For example, given an input of five name values, the expression {{ $json.name }} resolves to each name in turn.

In sub-nodes, the expression always resolves to the first item. For example, given an input of five name values, the expression {{ $json.name }} always resolves to the first name.

节点参数(Node parameters)#

描述(Description)#

为你的自定义代码添加描述。这会告诉代理何时使用此工具。例如:

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

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

语言(Language)#

你可以使用 JavaScript 或 Python。

🌐 You can use JavaScript or Python.

JavaScript / Python 测试环境(JavaScript / Python box)#

在此处编写代码

🌐 Write the code here.

你可以使用 query 访问工具输入。例如,要将输入字符串转换为小写字母:

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

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

模板和示例(Templates and examples)#

Template widget placeholder.

Refer to LangChain's documentation on tools for more information about tools in LangChain.

View n8n's Advanced AI documentation.