By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
You have every piece of an agent: messages, a model and tools. The only thing missing is the decision of what to do next. In a plain script, your code makes that decision. In an agent, the model does — and the runtime keeps calling it until the model says it is done.
In LangChain 1.x you do not normally write this loop by hand. create_agent(model=..., tools=[...], system_prompt=...) builds a compiled agent runtime that owns the loop: it calls the model, executes requested tools, appends the results and repeats until the model stops asking for tools. Your job is the model choice, the tools, the prompt and the limits. Lesson 7 opens that factory up.
ToolMessage explaining why, so the model can offer the customer another route instead of retrying.Key takeaways
The loop is: model → tool call → tool result → model, repeated until no tool calls are returned.
Binding exposes tools; the runtime executes them and appends ToolMessage results to state.
create_agent supplies the loop in LangChain 1.x, so your code focuses on tools, prompt and limits.
Budget steps, tokens, wall time and repeated calls — a loop without a limit is an incident waiting to happen.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.