Toolkity i ustrukturyzowane dane wejściowe narzędzi
Łącz powiązane narzędzia w wielokrotnego użytku toolkity i definiuj ustrukturyzowane, typowane argumenty za pomocą schematów, aby agenci niezawodnie wywoływali narzędzia z właściwymi parametrami.
Toolkity i ustrukturyzowane dane wejściowe narzędzi to bezpłatna lekcja AI Agents with LangChain & Autonomous Workflows na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej AI Agents with LangChain & Autonomous Workflows, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs AI Agents with LangChain & Autonomous Workflows zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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.
Często zadawane pytania
Czy lekcja „Toolkity i ustrukturyzowane dane wejściowe narzędzi” jest bezpłatna?
Tak — pełny tekst „Toolkity i ustrukturyzowane dane wejściowe narzędzi” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu AI Agents with LangChain & Autonomous Workflows, przejdź na CoddyKit PRO. Kurs AI Agents with LangChain & Autonomous Workflows zawiera 4 lekcji w sumie.
Co nauczysz się w „Toolkity i ustrukturyzowane dane wejściowe narzędzi”?
Łącz powiązane narzędzia w wielokrotnego użytku toolkity i definiuj ustrukturyzowane, typowane argumenty za pomocą schematów, aby agenci niezawodnie wywoływali narzędzia z właściwymi parametrami. Ćwiczysz AI Agents with LangChain & Autonomous Workflows z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć AI Agents with LangChain & Autonomous Workflows?
Nie wymagamy żadnego doświadczenia. AI Agents with LangChain & Autonomous Workflows w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Toolkity i ustrukturyzowane dane wejściowe narzędzi”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji AI Agents with LangChain & Autonomous Workflows?
Tak. Każda lekcja AI Agents with LangChain & Autonomous Workflows zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Tworzenie własnych narzędzi LangChain
- Integracja z zewnętrznymi API
- Web scraping i wzbogacanie danych
- Toolkity i ustrukturyzowane dane wejściowe narzędzi