Skip to content

自定义代码工具节点#

使用自定义代码工具节点编写可由代理运行的代码。

本页将介绍自定义代码工具节点的参数配置,并提供更多资源链接。

/// 注意 | 子节点中的参数解析 子节点在使用表达式处理多个项目时的行为与其他节点不同。

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

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

节点参数#

描述#

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

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

编程语言#

可使用 JavaScript 或 Python。

JavaScript / Python 代码框#

在此处编写代码。

可通过 query 访问工具输入。例如,将输入字符串转为小写:

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

模板与示例#

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

相关资源#

请参考 LangChain 关于工具的文档 获取更多关于 LangChain 中工具的信息。

查看 n8n 的高级 AI 文档。

AI glossary#

  • completion: Completions are the responses generated by a model like GPT.
  • hallucinations: Hallucination in AI is when an LLM (large language model) mistakenly perceives patterns or objects that don't exist.
  • vector database: A vector database stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.
  • vector store: A vector store, or vector database, stores mathematical representations of information. Use with embeddings and retrievers to create a database that your AI can access when answering questions.