ชุดเครื่องมือและข้อมูลนำเข้าเครื่องมือแบบมีโครงสร้าง
รวมเครื่องมือที่เกี่ยวข้องไว้เป็นชุดเครื่องมือที่นำกลับมาใช้ได้ และกำหนดอาร์กิวเมนต์ที่มีโครงสร้างและระบุชนิดข้อมูลด้วยแบบแผน เพื่อให้เอเจนต์เรียกใช้เครื่องมือของคุณด้วยพารามิเตอร์ที่ถูกต้องได้อย่างน่าเชื่อถือ
ชุดเครื่องมือและข้อมูลนำเข้าเครื่องมือแบบมีโครงสร้าง เป็นบทเรียน AI Agents with LangChain & Autonomous Workflows ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Agents with LangChain & Autonomous Workflows และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Agents with LangChain & Autonomous Workflows มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Beyond Single Tools
Real integrations rarely need just one function. A database integration needs list-tables, run-query, and describe-schema together.
A toolkit groups related tools so an agent gets a coherent capability in one bundle.
The Single-String Limitation
A basic tool takes one string input. But many actions need multiple typed arguments — a date range, a user id, a limit.
Structured tools let the agent pass several validated parameters instead of cramming them into one string.
Defining an Input Schema
Use a Pydantic model to describe the arguments. The field descriptions guide the LLM on how to fill them.
from pydantic import BaseModel, Field
class SearchArgs(BaseModel):
query: str = Field(description='Search keywords')
limit: int = Field(description='Max results', default=5)Attaching the Schema to a Tool
Pass args_schema so the agent knows the exact shape it must produce.
from langchain.tools import StructuredTool
def search(query: str, limit: int = 5):
return run_search(query, limit)
tool = StructuredTool.from_function(
func=search,
name='search',
description='Search the catalog',
args_schema=SearchArgs
)The @tool Decorator Shortcut
The @tool decorator infers a schema from your type hints and docstring, the quickest way to make a structured tool.
from langchain.tools import tool
@tool
def get_weather(city: str, units: str = 'metric') -> str:
'Get current weather for a city.'
return fetch_weather(city, units)Why Descriptions Matter
The LLM chooses tools and fills arguments from your name and descriptions. Vague text causes wrong tool choice or bad parameters.
- Say what the tool does and when to use it
- Describe each field clearly
- Mention units and formats
Building a Toolkit
A toolkit subclass exposes a get_tools() method returning the grouped tools. Shared config (like a client) lives on the toolkit.
from langchain.tools import BaseToolkit
class CrmToolkit(BaseToolkit):
client: object
def get_tools(self):
return [list_contacts, create_contact, add_note]Giving Tools to an Agent
Expand a toolkit into the agent's tool list. The agent now has the whole capability set at once.
toolkit = CrmToolkit(client=crm)
agent = create_agent(llm, toolkit.get_tools())Validation Protects You
Because the schema is enforced, malformed agent output is rejected before your function runs. This stops invalid types or missing required fields from reaching your integration.
Handling Tool Errors
Tools can fail (network, bad input). Catch exceptions and return a helpful message so the agent can recover or ask the user, instead of crashing the run.
@tool
def fetch_order(order_id: str) -> str:
'Look up an order by id.'
try:
return api.get(order_id)
except NotFound:
return 'No order found with that id.'Reusability
Toolkits make integrations portable: build a GitHubToolkit once and drop it into any agent. Combine multiple toolkits to give an agent broad, well-defined powers.
Quick Check
Test your tools knowledge.
Recap
You learned to build robust integrations:
- Structured tools accept multiple typed arguments via an
args_schema - The
@tooldecorator infers schemas from hints - Clear descriptions drive correct tool use
- Toolkits bundle related tools for reuse
- Validation and error handling keep agents stable
Well-structured tools are the backbone of dependable agent integrations.
คำถามที่พบบ่อย
บทเรียน “ชุดเครื่องมือและข้อมูลนำเข้าเครื่องมือแบบมีโครงสร้าง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ชุดเครื่องมือและข้อมูลนำเข้าเครื่องมือแบบมีโครงสร้าง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Agents with LangChain & Autonomous Workflows ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Agents with LangChain & Autonomous Workflows มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ชุดเครื่องมือและข้อมูลนำเข้าเครื่องมือแบบมีโครงสร้าง”
รวมเครื่องมือที่เกี่ยวข้องไว้เป็นชุดเครื่องมือที่นำกลับมาใช้ได้ และกำหนดอาร์กิวเมนต์ที่มีโครงสร้างและระบุชนิดข้อมูลด้วยแบบแผน เพื่อให้เอเจนต์เรียกใช้เครื่องมือของคุณด้วยพารามิเตอร์ที่ถูกต้องได้อย่างน… คุณปฏิบัติ AI Agents with LangChain & Autonomous Workflows ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Agents with LangChain & Autonomous Workflows หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Agents with LangChain & Autonomous Workflows บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “ชุดเครื่องมือและข้อมูลนำเข้าเครื่องมือแบบมีโครงสร้าง” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน AI Agents with LangChain & Autonomous Workflows นี้ได้ไหม
ได้ บทเรียน AI Agents with LangChain & Autonomous Workflows ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การสร้างเครื่องมือ LangChain แบบกำหนดเอง
- การผสานรวมกับ API ภายนอก
- การดึงข้อมูลจากเว็บและการเสริมข้อมูล
- ชุดเครื่องมือและข้อมูลนำเข้าเครื่องมือแบบมีโครงสร้าง