LangChain · the @tool decorator + create_agent Python
from langchain.tools import tool
@tool
def search_database(query: str, limit: int = 10) -> str:
"""Search the customer database for records matching the query.
Args:
query: Search terms to look for
limit: Maximum number of results to return
"""
return f"Found {limit} results for '{query}'"
Bind to an agent
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
agent = create_agent(
ChatOpenAI(model="gpt-5.4"),
tools=[search_database],
system_prompt="You are a helpful assistant.",
)
agent.invoke({"messages": [
{"role": "user", "content": "find acme orders"},
]})
How tool wiring works
The @tool decorator turns a Python function into a LangChain tool. Type
hints become the JSON schema the model sees; the docstring becomes the description used
for selection. For more control, subclass BaseTool or pass a Pydantic
args_schema.
How agent wiring works
create_agent (the v1 successor to AgentExecutor) binds the
tools to the model and runs the loop. Multi-agent in LangChain is "agent-as-tool" —
wrap a sub-agent and add it to the parent's tools list.
Mechanism
Function-level decorators; the agent factory manages the tool-call loop internally.
Notes
Multi-agent is not a first-class primitive; the documented path for composition is LangGraph.