Search⌘ K
AI Features

What Is create_agent?

Explore the create_agent API to efficiently build LangChain agents by automating the common model-tool loop. Understand how to integrate models, tools, and system prompts with minimal code. Learn to switch providers easily and generate structured outputs while maintaining a streamlined workflow. This lesson prepares you to craft customizable agent workflows using LangChain's high-level API.

Across the last few lessons, we have repeatedly built the same agent loop: a tool_calling_llm node that invokes the tool-enabled model, a ToolNode that executes the tool calls returned by the model, and tools_condition routing execution either to the tools or to the end of the graph. After tool execution, the graph loops back to the model. The model, tool-execution node, and routing structure remain the same. Only the tools bound to the model change.

This repetition reflects a common agent pattern. LangChain provides a high-level API for this standard model-and-tools loop through the create_agent function. Throughout this lesson, we will reuse the three tools introduced in “Multiple Tools in a LangGraph Workflow”:

def multiply(a: int, b: int) -> int:
"""Multiply two integers and return the product."""
return a * b
def translate_to_french(text: str) -> str:
"""Return a mock French translation of the input text."""
return f"French translation of '{text}'"
def get_weather(city: str) -> str:
"""Return a mock weather string for the given city."""
return f"The weather in {city} is sunny."
The same tools used throughout the advanced LangGraph module

From StateGraph to create_agent

The loop from “Sequential Tool Calls in LangGraph” works as follows: the model requests a tool call, the tool result is returned to the model, and the loop continues until the model returns a response with no tool calls: ...