Định nghĩa nhiều công cụ

Thiết kế Hệ thống Agentic với LangChain

Dilini K. Sumanapala, PhD

Founder & AI Engineer, Genverv, Ltd.

Tích hợp nhiều công cụ

Một bot với nhiều công cụ

   

  • Thêm nhiều công cụ tùy chỉnh

  • Tự động chọn công cụ theo truy vấn

Thiết kế Hệ thống Agentic với LangChain

Nâng cấp chatbot giáo dục

Mọi người đọc sách, ngồi trên những quyển sách lớn.

 

  • Tra cứu sự kiện lịch sử

  • Kiểm tra palindrome:

     
    • level = level

    • top spot = tops pot

Thiết kế Hệ thống Agentic với LangChain

Nhiều cách xây dựng công cụ

 

  • Gọi LLM

    Tra cứu các mốc lịch sử bằng ngôn ngữ tự nhiên, ví dụ: "5th of November"
      Agent: The 5th of November is famous for the Gunpowder treason and 
      plot...
    
  • Mã Python

    Tìm palindrome bằng cách so sánh chuỗi trực tiếp, ví dụ: string == string[::-1]
      Agent: Yes, "madam" is a palindrome...
    
Thiết kế Hệ thống Agentic với LangChain

Công cụ sự kiện lịch sử

# Use a decorator to label the tool and set the input format to string
@tool

def date_checker(date: str) -> str:
"""Provide a list of important historical events for a given date in any format."""
try: # Invoke the LLM to interpret the date and generate historical events answer = llm.invoke(f"List important historical events that occurred on {date}.")
# Return the response return answer.content
# Set an exception block for errors in retrieval except Exception as e: return f"Error retrieving events: {str(e)}"
Thiết kế Hệ thống Agentic với LangChain

Công cụ palindrome

@tool

# Set input format to string def check_palindrome(text: str):
"""Check if a word or phrase is a palindrome."""
# Remove non-alphanumeric characters and convert to lowercase cleaned = ''.join(char.lower() for char in text if char.isalnum())
# Check if the reversed text is the same as original text if cleaned == cleaned[::-1]: return f"The phrase or word '{text}' is a palindrome." else: return f"The phrase or word '{text}' is not a palindrome."
Thiết kế Hệ thống Agentic với LangChain

Gắn nhiều công cụ

# Import modules required for defining tool nodes
from langgraph.prebuilt import ToolNode


# List of tools tools = [wikipedia_tool, date_checker, check_palindrome]
# Pass the tools to the ToolNode() tool_node = ToolNode(tools)
# Bind tools to the LLM model_with_tools = llm.bind_tools(tools)
Thiết kế Hệ thống Agentic với LangChain

Cùng luyện tập nào!

Thiết kế Hệ thống Agentic với LangChain

Preparing Video For Download...