Skip to content

Custom Code Tool node#

ใช้ Custom Code Tool node เพื่อเขียนโค้ดที่ agent สามารถรันได้

ในหน้านี้จะมี parameter ของ node Custom Code Tool และลิงก์ไปยัง resource อื่นๆ ที่เกี่ยวข้อง

Parameter resolution in sub-nodes (การประมวลผล Parameter ใน sub-nodes)

Sub-nodes มีพฤติกรรมแตกต่างจาก node อื่นๆ เมื่อประมวลผลหลายรายการโดยใช้ expression

Node ส่วนใหญ่ รวมถึง root node จะรับ input กี่รายการก็ได้ ประมวลผลรายการเหล่านี้ และส่ง output ออกมา คุณสามารถใช้ expression เพื่ออ้างอิงถึง input item และ node จะประมวลผล expression สำหรับแต่ละ item ตามลำดับ ตัวอย่างเช่น หากมี input เป็นค่า name ห้ารายการ expression {{ $json.name }} จะถูกประมวลผลเป็นแต่ละชื่อตามลำดับ

ใน sub-nodes expression จะถูกประมวลผลเป็น item แรกเสมอ ตัวอย่างเช่น หากมี input เป็นค่า name ห้ารายการ expression {{ $json.name }} จะถูกประมวลผลเป็นชื่อแรกเสมอ

Node parameters#

Description#

ใส่คำอธิบายสำหรับ custom code ของคุณ ตรงนี้จะช่วยบอก agent ว่าควรใช้ tool นี้เมื่อไหร่ เช่น

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

Language#

เลือกได้ว่าจะใช้ JavaScript หรือ Python

JavaScript / Python box#

เขียนโค้ดของคุณตรงนี้

คุณสามารถเข้าถึง input ของ tool ได้ด้วย query เช่น ถ้าต้องการรับ string แล้วแปลงเป็นตัวพิมพ์เล็กทั้งหมด:

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

Templates and examples#

AI: Conversational agent with custom tool written in JavaScript

by n8n Team

View template details
Custom LangChain agent written in JavaScript

by n8n Team

View template details
OpenAI assistant with custom tools

by David Roberts

View template details
Browse Custom Code Tool integration templates, or search all templates

อ้างอิง LangChain's documentation on tools สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ tools ใน LangChain

ดูเอกสาร Advanced AI ของ n8n

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.