0Pricing
AI Agents with LangChain & Autonomous Workflows · Lección

Toolkits y entradas estructuradas de herramientas

Agrupe herramientas relacionadas en toolkits reutilizables y defina argumentos estructurados y tipados mediante esquemas para que los agentes llamen a sus herramientas de forma fiable con los parámetros correctos.

Toolkits y entradas estructuradas de herramientas es una lección gratuita de AI Agents with LangChain & Autonomous Workflows en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de AI Agents with LangChain & Autonomous Workflows, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de AI Agents with LangChain & Autonomous Workflows incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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 @tool decorator 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.

Preguntas frecuentes

¿La lección «Toolkits y entradas estructuradas de herramientas» es gratis?

Sí — el texto completo de «Toolkits y entradas estructuradas de herramientas» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de AI Agents with LangChain & Autonomous Workflows, actualiza a CoddyKit PRO. El curso de AI Agents with LangChain & Autonomous Workflows incluye 4 lecciones en total.

¿Qué aprenderé en «Toolkits y entradas estructuradas de herramientas»?

Agrupe herramientas relacionadas en toolkits reutilizables y defina argumentos estructurados y tipados mediante esquemas para que los agentes llamen a sus herramientas de forma fiable con los parámet… Practicas AI Agents with LangChain & Autonomous Workflows con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar AI Agents with LangChain & Autonomous Workflows?

No se requiere experiencia previa. AI Agents with LangChain & Autonomous Workflows en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.

¿Cuánto tiempo toma la lección «Toolkits y entradas estructuradas de herramientas»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de AI Agents with LangChain & Autonomous Workflows?

Sí. Cada lección de AI Agents with LangChain & Autonomous Workflows incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Creación de herramientas personalizadas para LangChain
  2. Integración con API externas
  3. Web scraping y ampliación de datos
  4. Toolkits y entradas estructuradas de herramientas
← Volver a AI Agents with LangChain & Autonomous Workflows