開始使用免費開始

綁定多個工具

你剛剛建立了多個工具!現在你可以先把它們綁定到 LLM,再將它們加入你的聊天機器人。wikipedia_toolpalindrome_checkerhistorical_events 這些工具都已和 llm 一起加入你的環境。你也會建立一個工具節點,加入到聊天機器人中,列出所有可用的工具。

本練習屬於課程

Designing Agentic Systems with LangChain

檢視課程

練習說明

  • langgraph.prebuilt 匯入用於定義工具節點所需的模組。
  • 在你的環境中,將適當的工具名稱加入工具清單以完成清單。
  • tools 清單傳入 ToolNode() 類別,並指定給 tool_node
  • 使用 .bind_tools()tools 綁定到 llm

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import modules required for defining tool nodes
from ____.____ import ____

# List of tools
tools = [____, ____, ____]

# Pass the tools to the ToolNode()
____ = ____(____)

# Bind tools to the LLM
model_with_tools = ____.____(____)
編輯並執行程式碼