React Agent
create_agent builds a ReAct-style agent — reason, act, observe, repeat — from a model and a tool list. The constructor itself lives in LangGraph's prebuilt layer; langchain.agents.create_agent is the stable entry point.
from langchain.agents import create_agent
def search_docs(query: str) -> str:
"""Search internal documentation."""
return f"Top result for '{query}': see the onboarding guide, page 4."
def get_ticket_status(ticket_id: str) -> str:
"""Look up the status of a support ticket."""
return f"Ticket {ticket_id}: in progress, assigned to support."
agent = create_agent(
model="claude-sonnet-4-6",
tools=[search_docs, get_ticket_status],
system_prompt="You are a support assistant. Use tools to answer accurately.",
)
result = agent.invoke({
"messages": [{"role": "user", "content": "What's the status of ticket 4821, and where's the onboarding guide?"}]
})
for msg in result["messages"]:
print(type(msg).__name__, "-", getattr(msg, "content", msg))
Walking one trace through the loop:
- Reason — the model reads the question, decides it needs two tool calls (one per sub-question).
- Act — it emits an
AIMessagewith twotool_calls:get_ticket_statusandsearch_docs. - Observe —
create_agentexecutes both, appends aToolMessageper call. - Reason again — the model reads both results and decides it has enough to answer.
- Act (final) — it emits an
AIMessagewith notool_calls, just text. The loop stops here.
See also
- Agent Concepts — chain vs agent, when to reach for this.
- Custom Tools — writing
search_docs-style functions. - Why LangGraph — the orchestration layer this constructor is built on.