Engineering7 min read

Run DeepSeek Locally with Ollama and Build an AI Agent

Learn how to set up DeepSeek with Ollama to run AI models locally, ensuring privacy, cost efficiency, and fast inference. This guide walks you through installation, setup, and building a simple AI agent with practical code examples.

Charafeddine Mouzouni
Charafeddine Mouzouni
How to Build a Local AI Agent Using DeepSeek and Ollama: A Step-by-Step Guide

To run DeepSeek locally, install Ollama, run ollama run deepseek-r1:8b (5.2 GB, the current default tag) or deepseek-r1:1.5b (1.1 GB) on a small laptop, then call it from Python with pip install ollama and ollama.chat(). The same client now takes tools= and think=, which is all you need for a small local agent loop. Below: the original walkthrough, then the 2026 model table, what changed, and a FAQ.

Updated September 2026: current DeepSeek tags and sizes on Ollama (R1-0528 distills, V3.1, cloud-only V4), the current Python chat and tool-calling API, thinking flags, and a FAQ. The original steps and code are kept below.

1. Presentation of the Framework

DeepSeek leverages distilled versions of larger models (e.g., Qwen or Llama‑based variants) to bring advanced reasoning capabilities into devices with limited hardware resources. Ollama acts as the model manager by:

Simplifying Model Downloads: It provides an easy-to-use CLI to pull models directly.

Local Inference: Running models locally means that data never leaves your device.

API Integration: Ollama exposes a simple REST API and Python client to interact with your model.

This framework is ideal for developers who require fast, private, and cost-efficient AI applications.

2. Benefits of Using DeepSeek with Ollama

• Privacy & Security:

Run inference entirely on your own hardware without sending sensitive data to external servers.

• Cost Efficiency:

Eliminate recurring API fees. Once installed, your local model runs without incurring additional costs.

• Performance:

Local processing significantly reduces latency, allowing for real-time interactions.

• Flexibility:

Choose from a variety of model sizes (from 1.5B to even 671B parameters) based on your hardware capabilities.

3. Getting Started: Installation & Setup

Step 1: Install Ollama

Download and install Ollama from the official website or via the command line. For example, on Linux you can use:

curl -fsSL https://ollama.com/install.sh | sh

(Installation instructions may vary by OS.)

Step 2: Download and Run the DeepSeek Model

What changed since this was written: the command below still works, but the bare deepseek-r1 tag now resolves to the 8b distill (DeepSeek-R1-0528 chain-of-thought distilled onto Qwen3 8B Base, 5.2 GB), and the reasoning trace is controlled by flags. As of Ollama v0.33.3 (2 September 2026):

ollama run deepseek-r1:8b --hidethinking "Explain MoE in two lines"
ollama run deepseek-r1:8b --think=false "Just the answer"

Once Ollama is installed, pull and run a distilled version of DeepSeek-R1. For demo purposes, you can start with the smaller 1.5B model:

ollama run deepseek-r1:1.5b

This command downloads the model and starts it locally. If your hardware supports larger models, replace 1.5b with your desired parameter size (e.g., 7b, 14b, etc.).

Step 3: Verify the Installation

To ensure the model is running, you can try a simple API call using a tool like curl:

curl http://localhost:11434/api/chat -d '{
  "model": "deepseek-r1:1.5b",
  "messages": [{"role": "user", "content": "Hello, how are you?"}],
  "stream": false
}'

You should receive a response from DeepSeek-R1 confirming that it’s operational.

4. Building a Simple AI Agent: Step-by-Step Example

Below is an example in Python that demonstrates how to build a simple chat agent using the Ollama Python library.

What changed since this was written: the dictionary access in the original (response["message"]["content"]) still works, but the library now documents from ollama import chat, attribute access (response.message.content), tools= (plain Python functions are parsed into a tool schema from their docstring) and think=. The original script is a chat loop, not an agent: it never calls anything. This is the smallest loop that does, following the current Ollama tool-calling docs:

from ollama import chat

def get_temperature(city: str) -> str:
    """Get the current temperature for a city

    Args:
      city: The name of the city
    """
    return {"Paris": "21°C", "Rabat": "27°C"}.get(city, "Unknown")

messages = [{"role": "user", "content": "Is it warmer in Paris or Rabat?"}]
response = chat(model="deepseek-r1:8b", messages=messages,
                tools=[get_temperature], think=True)
messages.append(response.message)

for call in response.message.tool_calls or []:
    result = get_temperature(**call.function.arguments)
    messages.append({"role": "tool", "tool_name": call.function.name,
                     "content": str(result)})

final = chat(model="deepseek-r1:8b", messages=messages)
print(final.message.content)

If a distill returns no tool_calls, it is not a bug in your loop: check the docs for the tag you pulled. On Ollama's library, deepseek-r1 and deepseek-v3.1 carry the tools and thinking labels; deepseek-v3 does not.

Code Snippet: A Basic Chat Agent

import ollama

def chat_with_deepseek(prompt):
    # Use the DeepSeek-R1 1.5B model to process the user prompt.
    response = ollama.chat(
        model="deepseek-r1:1.5b",
        messages=[{"role": "user", "content": prompt}]
    )
    return response["message"]["content"]

# Example usage
if __name__ == "__main__":
    print("DeepSeek Agent is running. Type 'exit' to quit.")
    while True:
        user_input = input("User: ")
        if user_input.lower() in ["exit", "quit"]:
            break
        answer = chat_with_deepseek(user_input)
        print("Agent:", answer)

Explanation

Importing Ollama: The script starts by importing the Ollama Python package.

chat_with_deepseek Function: This function sends a user prompt to the DeepSeek model and returns the generated response.

Interactive Loop: The main block sets up a continuous loop to interact with the AI agent until the user types an exit command.

This simple yet powerful agent can be further extended by integrating additional features such as retrieval-augmented generation, custom prompts, or even connecting to a local vector database for enhanced context.

From a local agent script to one you can defend in production: that gap is what Cohorte's Building Accountable AI Agents course (E3) closes.

Which DeepSeek model to run locally in 2026

Everything below is read from the Ollama library pages on 5 September 2026. Download size is the floor for what has to fit in RAM or VRAM; Ollama does not publish a per-tag memory figure, so check the docs against your machine.

TagDownloadBaseFits
deepseek-r1:1.5b1.1 GBQwen2.5-Math-1.5B distillAny laptop; demos only
deepseek-r1:7b4.7 GBQwen2.5-Math-7B distill8 GB laptop, tight
deepseek-r1:8b (default)5.2 GBR1-0528 on Qwen3 8B Base16 GB laptop, comfortable
deepseek-r1:14b9.0 GBQwen2.5-14B distill16 GB, with little room
deepseek-r1:32b20 GBQwen2.5-32B distill32 GB Mac or 24 GB GPU
deepseek-r1:70b43 GBLlama-3.3-70B distill64 GB unified memory
deepseek-r1:671b, deepseek-v3:671b, deepseek-v3.1:671b404 GBFull MoE, 671B total, 37B activeServer class only
deepseek-v4-flash:cloud, deepseek-v4-pronone284B MoE, 13B active (Flash)Cloud-only tags, not local

Also on the library: deepseek-coder-v2 (16b, 236b), deepseek-ocr (3b, vision). Our rule: deepseek-r1:8b for a laptop agent, deepseek-v3.1 only if you have the box, and treat the 1.5b tag as a smoke test, not a model you ship on.

What changed since this was written

FAQ

Can I run DeepSeek locally with Ollama?

Yes. Install Ollama, then ollama run deepseek-r1:8b. The distilled R1 tags from 1.5b to 70b run on consumer hardware; the 671b tags need a server.

Which DeepSeek model fits 16 GB of RAM?

deepseek-r1:8b (5.2 GB download) runs comfortably; deepseek-r1:14b (9.0 GB) fits with little headroom. Anything from 32b up wants 32 GB or more.

Is DeepSeek R1 on Ollama the full model?

Only deepseek-r1:671b (404 GB) is the full model. Every smaller tag is a distill: a Qwen or Llama base post-trained on R1's chain-of-thought.

Does DeepSeek on Ollama send data to China?

Not when you run a local tag: inference happens on your machine and nothing leaves it. The :cloud tags (V4 Flash, V4 Pro) are hosted by Ollama, not local, and DeepSeek's own API is a separate product with its own terms.

Can the local model call tools?

Yes, with tools= in ollama.chat(). Ollama labels deepseek-r1 and deepseek-v3.1 as tool-capable. Small distills call tools less reliably than the large models; validate every argument before you execute anything.

DeepSeek vs Llama vs Qwen locally?

The R1 distills are Qwen and Llama under the hood, so you are comparing post-training, not architecture. Pick R1 for visible reasoning traces, Qwen 3 for tool calling with thinking on and off, Llama for the broadest tooling support. Benchmark on your own task; the leaderboards do not run your prompts.

5. Final Thoughts

By combining DeepSeek’s advanced reasoning capabilities with Ollama’s streamlined local deployment, developers can create robust, privacy‑focused AI agents that run efficiently on local hardware. This setup not only reduces latency and costs but also provides complete control over data and inference processes. This step‑by‑step guide offers a solid foundation to get started.

Charafeddine MouzouniMarch 10, 2025

The script works. Production is a different sport.

The AI OS letter covers the part tutorials skip: verification, trust, what breaks with real users. One idea, every Saturday, from CM, Cohorte's founder, who has shipped 60+ AI systems.

Free weekly. No spam. Unsubscribe in one click.

Subscribed ✓

The next letter arrives Saturday. Go finish the build.