0Pricing
AI Agents with LangChain & Autonomous Workflows · Pelajaran

Memanfaatkan Perangkat Alat Siap Pakai

Temukan dan terapkan perangkat alat siap dikonfigurasi yang disediakan LangChain untuk menambahkan kemampuan ke agen Anda dengan cepat.

Memanfaatkan Perangkat Alat Siap Pakai adalah pelajaran AI Agents with LangChain & Autonomous Workflows gratis di CoddyKit. Ini adalah pelajaran 3 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar AI Agents with LangChain & Autonomous Workflows, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus AI Agents with LangChain & Autonomous Workflows mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Intro to Pre-built Toolkits

Welcome to leveraging pre-built toolkits in LangChain! So far, you've learned to define and use individual tools. But what if you need a set of related tools?

Toolkits are collections of pre-configured tools designed for specific purposes. They bundle common functionalities, making it much easier to add powerful capabilities to your AI agents.

Why Use Toolkits?

Using toolkits offers several key advantages:

  • Time-saving: No need to define common tools from scratch.
  • Reduced Boilerplate: Less code to write and manage.
  • Consistency: Ensures tools are implemented correctly and consistently.
  • Expanded Capabilities: Instantly equip your agent with complex functionalities like web search, database interaction, or advanced math.

Example: The Math Toolkit

Let's start with a simple yet powerful example: the Math Toolkit. This toolkit provides basic arithmetic operations, allowing your agent to perform calculations.

It's a great way to see how a collection of tools can be integrated and used by an agent to solve problems that require numerical processing.

Initializing a Toolkit

First, you need to import and initialize the toolkit. Here's how you can set up the MathToolkit and inspect the tools it provides:

from langchain_community.agent_toolkits import MathToolkit

def main():
    # Initialize the Math Toolkit
    toolkit = MathToolkit()
    print("MathToolkit initialized!")
    print("\nTools available in this toolkit:")
    # Iterate and print details of each tool
    for tool in toolkit.get_tools():
        print(f"- {tool.name}: {tool.description}")

if __name__ == "__main__":
    main()

Agents Using Toolkits

Once a toolkit is initialized, you pass its collection of tools to your agent, just like you would with individual tools.

The agent's reasoning engine will then intelligently decide which tool from the toolkit is best suited to answer a given query or complete a task.

Agent Solving Math Problems

Watch this agent use the MathToolkit to perform a multiplication. Notice how the agent 'thinks' about the problem and selects the correct tool.

(Remember to replace YOUR_API_KEY with your actual OpenAI API key for the code to run.)

from langchain_community.llms import OpenAI
from langchain.agents import initialize_agent, AgentType
from langchain_community.agent_toolkits import MathToolkit
import os

def main():
    # Set your OpenAI API key here
    # os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY" # Uncomment and replace

    if "OPENAI_API_KEY" not in os.environ:
        print("Error: OPENAI_API_KEY environment variable not set.")
        print("Please set it to run this example.")
        return

    llm = OpenAI(temperature=0) # Using a simple LLM

    toolkit = MathToolkit()
    tools = toolkit.get_tools()

    # Initialize the agent with the LLM and the toolkit's tools
    agent = initialize_agent(
        tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
    )

    print("\nAgent at work (verbose output shows thinking process):\n")
    agent.run("What is 12345 * 6789?")

if __name__ == "__main__":
    main()

Exploring Other Powerful Toolkits

LangChain offers many other pre-built toolkits for diverse tasks:

  • Wikipedia Toolkit: For agents needing to search and retrieve information from Wikipedia.
  • OpenAPI Toolkit: Allows agents to interact with any API described by an OpenAPI spec.
  • SQL Database Toolkit: Enables agents to query and interact with SQL databases.
  • Python Agent Toolkit: Allows agents to write and execute Python code.

Each toolkit significantly expands your agent's capabilities!

Discovering More Toolkits

Want to find more toolkits? Here's how:

  • LangChain Documentation: The official docs are the best resource.
  • Source Code: Explore the langchain_community.agent_toolkits module directly.
  • Community Examples: Look at how others are using LangChain in GitHub repos or tutorials.

New toolkits are constantly being developed and added!

Toolkit Quick Check

What is the primary benefit of using pre-built toolkits in LangChain?

Recap: Toolkit Power-Up!

Great job! In this lesson, you learned about:

  • What pre-built toolkits are in LangChain.
  • The significant benefits they offer, like saving time and expanding capabilities.
  • How to initialize and integrate toolkits (like the MathToolkit) with your agents.
  • Where to discover more powerful toolkits for various tasks.

Toolkits are a fantastic way to quickly supercharge your agents!

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Memanfaatkan Perangkat Alat Siap Pakai” gratis?

Ya — teks lengkap “Memanfaatkan Perangkat Alat Siap Pakai” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus AI Agents with LangChain & Autonomous Workflows, upgrade ke CoddyKit PRO. Kursus AI Agents with LangChain & Autonomous Workflows mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Memanfaatkan Perangkat Alat Siap Pakai”?

Temukan dan terapkan perangkat alat siap dikonfigurasi yang disediakan LangChain untuk menambahkan kemampuan ke agen Anda dengan cepat. Kamu berlatih AI Agents with LangChain & Autonomous Workflows dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai AI Agents with LangChain & Autonomous Workflows?

Tidak diperlukan pengalaman sebelumnya. AI Agents with LangChain & Autonomous Workflows di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 3 dari 4.

Berapa lama pelajaran “Memanfaatkan Perangkat Alat Siap Pakai” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran AI Agents with LangChain & Autonomous Workflows ini?

Ya. Setiap pelajaran AI Agents with LangChain & Autonomous Workflows menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Mendefinisikan dan Menggunakan Alat
  2. Jenis Agen dan Pengambilan Keputusan
  3. Memanfaatkan Perangkat Alat Siap Pakai
  4. Penanganan Kesalahan dan Eksekusi Alat yang Aman
← Kembali ke AI Agents with LangChain & Autonomous Workflows