Tools are callable functions that agents invoke to interact with the world. The @tool decorator turns Python functions into agent tools. StructuredTool with Pydantic schemas provides type safety and self-documenting interfaces.
Simple Tools with @tool
from langchain.agents import tool
@tool
def search_wikipedia(query: str) -> str:
"""Search Wikipedia for information about a topic."""
# Implementation
return f"Results for {query}"
@tool
def get_weather(city: str) -> str:
"""Get the current weather in a city."""
# Implementation
return f"Weather in {city}"
# Agents can now call these tools
Structured Tools with Pydantic
from langchain.agents import StructuredTool
from pydantic import BaseModel, Field
class SearchInput(BaseModel):
query: str = Field(description="Search query")
limit: int = Field(default=5, description="Number of results")
def search_function(query: str, limit: int) -> str:
# Implementation
return f"Found {limit} results for {query}"
search_tool = StructuredTool.from_function(
func=search_function,
args_schema=SearchInput,
)
Conclusion
Custom tools enable agents to interact with external systems. Structured tools with schemas ensure type safety and clear interfaces. Building a toolkit of domain-specific tools powers specialized agents. Next: tracing and debugging agent execution with LangSmith.

