複数ツールの定義

LangChainで設計するエージェント型システム

Dilini K. Sumanapala, PhD

Founder & AI Engineer, Genverv, Ltd.

複数ツールの統合

複数ツールを持つボット

   

  • 複数のカスタムツールを追加する

  • クエリごとにツール選択を自動化する

LangChainで設計するエージェント型システム

教育チャットボットの強化

大きな本の上に座って読書する人々

 

  • 歴史的出来事を調べる

  • 回文をチェックする:

     
    • level = level

    • top spot = tops pot

LangChainで設計するエージェント型システム

ツール作成の複数の方法

 

  • LLMを呼び出す

    自然言語入力で歴史的な日付を調べる(例:「11月5日」)
      Agent: The 5th of November is famous for the Gunpowder treason and 
      plot...
    
  • Pythonコード

    文字列を直接比較して回文を検出する(例:string == string[::-1]
      Agent: Yes, "madam" is a palindrome...
    
LangChainで設計するエージェント型システム

歴史的出来事ツール

# 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)}"
LangChainで設計するエージェント型システム

回文チェックツール

@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."
LangChainで設計するエージェント型システム

複数ツールのバインド

# 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)
LangChainで設計するエージェント型システム

さあ、練習しましょう!

LangChainで設計するエージェント型システム

Preparing Video For Download...