Course navigation
AgentsLesson 2 of 9

Agent Types

What are Agents? left off with model, tools, and the loop. This page is the naming mess around that loop — then a short script you can run.

create_agent

In current LangChain you wire agents with create_agent. Pass a model id and a list of @tool functions. Call invoke with messages — the library handles the back-and-forth.

You are not choosing "agent type" in a dropdown. The names below describe how the model asks for a tool, not a different Python class.

Names you will see

Tutorials disagree on wording. These three cover almost everything:

Tool-calling — the model returns a tool_calls block (OpenAI-style). This is what create_agent expects with gpt-4o-mini.

ReAct — the model prints Thought, Action, and Observation as plain text. Common in older blog posts; we cover it again in ReAct Framework.

Direct reply — no tool on that turn. The model answers straight away when it already knows the fact.

Tool-calling

tool_calls: [
  { name: "multiply",
    args: { a: 24, b: 17 } }
]

multiply(24, 17) → 408
then the model answers

ReAct

Thought: need to multiply
Action: multiply
Action Input: 24, 17
Observation: 408
Final Answer: 408
Same result. With OpenAI models you usually only see the left side — LangChain runs the function and hides the JSON.

Tools are optional per turn

Handing the agent a multiply function does not mean every question uses it. "What does <title> do?" is basic HTML — the model can skip the tool. For "24 × 17" you want the function so you are not trusting mental math.

Demo asks both:

"What does <title> do?"
answer, no tool
"What is 24 × 17?"
↓ multiply
408
"408"
Your script does not pick the branch. The model does, per message.

Wire one tool

Tool Calling goes into schemas and errors. For now, the shape is: decorate a function, pass it to create_agent, invoke.

from langchain.agents import create_agent
from langchain.tools import tool

@tool
def multiply(a: int, b: int) -> int:
    """Multiply two integers."""
    return a * b

agent = create_agent(model="openai:gpt-4o-mini", tools=[multiply])

result = agent.invoke({
    "messages": [{"role": "user", "content": "What is 24 times 17?"}],
})
print(result["messages"][-1].content)

Run the demo

Venv from Project Setup. Download, then:

agent_types_demo.py

Two questions, one agent

OPENAI_API_KEY in .env, same as LangChain Basics.
agent_types_demo.py
"""agent_types_demo.py"""
from langchain.agents import create_agent
# multiply @tool, loop over two questions
agent = create_agent(model="openai:gpt-4o-mini", tools=[multiply])
python agent_types_demo.py
PowerShell — (.venv) active
(.venv) PS C:\projects\langchain-course> python agent_types_demo.py
=== Question ===
What does the HTML <title> tag do? One sentence.
=== Answer ===
The <title> tag sets the text shown in the browser tab.
=== Question ===
Use the multiply tool: what is 24 times 17?
=== Answer ===
24 times 17 is 408.
Second question hits multiply first.

More options on create_agent in the docs.