LangGraph and Ollama: build your first local agent

Learn the LangGraph agent loop and build a Python example with Ollama and Llama 3.1, using a mock weather tool without an API key.

Player not loading? Watch on YouTube

This beginner tutorial explains LangGraph through a Python AI agent that runs on the user's machine with Ollama and Llama 3.1. Akshat describes nodes as individual steps, edges as connections that control execution, and state as shared information that each step can read and update.

The explanation follows a weather question through an agent loop. The model requests a tool, a conditional edge routes execution to that tool, and the result returns to the model before it answers. The speaker contrasts this flow with a straight sequence of model calls and describes LangGraph's support for durable execution.

The practical section covers installing Ollama, downloading the model and connecting it through ChatOllama. LangChain's create_agent builds the loop around the model, a registered Python tool and a system prompt. A clear tool docstring helps the model decide when to call it. The local LLM must support tool calling; the speaker suggests Llama 3.1 or Qwen.

The weather function returns a fixed sentence rather than live weather data, so the example needs no weather API. This agent has no conversation memory after a run finishes. The closing discussion explains when custom graphs become useful, such as specific branching rules, several cooperating agents or manual changes to state during execution.