openclaw+ollama搭建本地运行
瞬秒爆加速
编辑于 2026年05月06日 11:31

openclaw+ollama本地模型运行,如果没有搭配API工具,限制很多,一般都会提示无法使用工具,或是没有权限操作系统级应用,再加上本地运行模型的硬件基础也需要跟上,例如R9 7945hx+4060+32G内存 也就小模型可以运行的流畅,如果大于14B的吃力很多,也可能会提示out of memory。

ollama上的有些很久没有更新的模型,还会提示无法调用工具,所以一般选择最新的模型尝试。

openclaw要将任务描述清除,才能完成符合预期的结果,所以最好不要进行一些重要且无法恢复的任务交给它完成。

环境准备

安装 Node.js 24+(OpenClaw 强制要求)

  • 官网下载:https://nodejs.org/ 选 22.x LTS 或更高

  • 安装时务必勾选:Add to PATH(自动配环境变量)

  • 打开powershell验证安装结果

代码块
PlainText
自动换行
复制代码
node -v  # 应输出 v24.x.x 
npm -v   # 应输出 11.x+
复制成功

安装并启动 Ollama(本地模型服务)

  • 下载 并安装Ollama Windows 版:https://ollama.com/

# 新建模型目录 New-Item -Path "D:\model\ollama" -ItemType Directory -Force # 设置环境变量 [Environment]::SetEnvironmentVariable("OLLAMA_MODELS", "D:\model\ollama", "Machine")

拉取一个模型,例如Qwen3.5:9b ,打开cmd运行

通用量化小模型 ollama pull qwen3.5:9b ollama pull gemma4:e4b 专用代码量化模型 ollama pull carstenuhlig/omnicoder-9b:q8_0 启动ollama服务 ollama serve

安装LM Studio 替代 Ollama

https://lmstudio.ai/ 下载安装包,安装即可

加载模型所需的GPU显存要少一点

模型运行速度要快些

界面操作方便,直观设置参数

下载模型直观,多种量化可供选择

加载模型会占用内存

切换模型需要频繁加载模型,无法无缝切换

安装 OpenClaw

如果没有设置安装路径,一般都会在C盘

代码块
PlainText
自动换行
复制代码
C:\Users\你的用户名\AppData\Roaming\npm\node_modules\openclaw\
复制成功

以D盘的D:\model\open_claw为例,

代码块
PlainText
自动换行
复制代码
# 允许脚本执行
Set-ExecutionPolicy Bypass -Scope Process -Force

New-Item -Path "D:\model\open_claw" -ItemType Directory -Force
New-Item -Path "D:\model\open_claw\npm" -ItemType Directory -Force
New-Item -Path "D:\model\open_claw\data" -ItemType Directory -Force
New-Item -Path "D:\model\open_claw\workspace" -ItemType Directory -Force

# 设置 npm 全局安装目录
npm config set prefix "D:\model\open_claw\npm"
npm config set cache "D:\model\open_claw\npm-cache"

# 把新路径加入系统 PATH(必须)
$newPath = [Environment]::GetEnvironmentVariable("PATH", "Machine") + ";D:\model\open_claw\npm"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "Machine")

设置 OpenClaw 数据 / 配置目录
[Environment]::SetEnvironmentVariable("OPENCLAW_HOME", "D:\model\open_claw\data", "Machine")
[Environment]::SetEnvironmentVariable("OPENCLAW_WORKSPACE", "D:\model\open_claw\workspace", "Machine")

# 安装openclaw
iwr -useb https://openclaw.ai/install.ps1 | iex -Args "--version","2026.3.28"

# 验证(能输出版本即成功)
openclaw --version
复制成功

OpenClaw 配置选择

代码块
PlainText
自动换行
复制代码
openclaw onboard
复制成功

OpenClaw配置Ollama本地模型

打开powershell,最好使用管理员模式

代码块
PlainText
自动换行
复制代码
openclaw gateway start
复制成功
代码块
PlainText
自动换行
复制代码
网页UI
openclaw dashboard
或浏览器打开
 http://127.0.0.1:18789
交互TUI
openclaw tui
复制成功

启动openclaw,需要先启动ollama,在执行上述两个命令行,直到打开网页。

卸载openclaw

代码块
PlainText
自动换行
复制代码
npm uninstall -g openclaw

# 删除配置/数据目录(默认路径)
Remove-Item -Recurse -Force "$env:USERPROFILE\.openclaw" -ErrorAction SilentlyContinue

# 删除你原来的安装目录(如 D:\model\open_claw)
Remove-Item -Recurse -Force "D:\model\open_claw" -ErrorAction SilentlyContinue

# 清理计划任务(确认无残留)
Unregister-ScheduledTask -TaskName "OpenClaw Gateway" -Confirm:$false -ErrorAction SilentlyContinue
复制成功

Ollama模型参数设置

qwen3.5:9b在Ollama serve运行显示的layer层数是33层,如果显存足够大,33层会都在专用GPU内存上运行,如果不足加上没有设置,33层就会分到CPU+GPU。 qwen3.5:9b不能让它操控文件与调用工具,这个模型大概率是个近视,正常的英文符号能看成中文符号,fitz能看成fitsz。 如果网络搜索,问题回答方向则还是可以了。

代码块
PlainText
自动换行
复制代码
qwen3.5:9b模型
创建Modelfile文件

# 基于你现有的 qwen3.5:9b
FROM qwen3.5:9b

# 聊天模板
TEMPLATE  {{ .Prompt }}

# 随机性
PARAMETER temperature 1         
PARAMETER top_p 0.95                
PARAMETER top_k 20                
PARAMETER presence_penalty 1.5           
# 上下文窗口
PARAMETER num_ctx 4096
# 指定将模型的多少层加载到GPU上运行
# openclaw显存不足的话不要设置,会卡死,ollama对话则可以设置           
PARAMETER num_gpu 33

运行命令
ollama create qwen3.5:9b-gpu -f ./Modelfile
复制成功

carstenuhlig/omnicoder-9b:q8_0是基于qwen3.5:9b训练的,所以layer层数也是33层

代码块
PlainText
自动换行
复制代码
carstenuhlig/omnicoder-9b:q8_0

# 基于 omnicoder-9b:q8_0
FROM carstenuhlig/omnicoder-9b:q8_0

# 保留原有的工具调用模板(完整复制)
TEMPLATE """{{- $lastUserIdx := -1 -}}
{{- range $idx, $msg := .Messages -}}
{{- if eq $msg.Role "user" }}{{ $lastUserIdx = $idx }}{{ end -}}
{{- end }}
{{- if or .System .Tools }}<|im_start|>system
{{ if .System }}{{ .System }}

{{ end }}
{{- if .Tools }}# Tools

You may call one or more functions to assist with the user query.

You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end -}}
<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if (and $.IsThinkSet (and .Thinking (or $last (gt $i $lastUserIdx)))) -}}
<think>{{ .Thinking }}</think>
{{ end -}}
{{ if .Content }}{{ .Content }}{{ end }}
{{- if .ToolCalls }}
{{- range .ToolCalls }}
<tool_call>
{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
</tool_call>
{{- end }}
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
<think>
{{ end }}
{{- end }}"""

# 优化参数
# 上下文
PARAMETER num_ctx 32768    
# 随机性    
PARAMETER temperature 0.6   
# 候选池    
PARAMETER top_k 20
# 核采样
PARAMETER top_p 0.95
# 增加重复惩罚,防止长对话复读
PARAMETER repeat_penalty 1  
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
# 指定将模型的多少层加载到GPU上运行
# openclaw显存不足的话不要设置,会卡死,ollama对话则可以设置
PARAMETER num_gpu 33

# 可选:调整系统提示,强调长时间运行的稳定性
SYSTEM You are OmniCoder, an expert coding assistant trained on agentic software engineering trajectories. You excel at reading existing code before modifying it, recovering from errors, and producing minimal, correct diffs.

运行命令
ollama create omnicoder-9b:q8_0 -f ./Modelfile
复制成功

memory-lancedb-pro

代码块
PlainText
自动换行
复制代码
cd D:\model\open_claw\npm\node_modules\openclaw\dist\extensions
git clone https://github.com/win4r/memory-lancedb-pro.git /memory-lancedb-pro

cd memory-lancedb-pro
npm install
复制成功

lossless-claw

代码块
PlainText
自动换行
复制代码
openclaw plugins install @martian-engineering/lossless-claw
复制成功

config配置

代码块
PlainText
自动换行
复制代码
{
  "meta": {
    "lastTouchedVersion": "2026.3.28",
    "lastTouchedAt": "2026-04-29T09:35:39.391Z"
  },
  "wizard": {
    "lastRunAt": "2026-04-29T09:35:39.248Z",
    "lastRunVersion": "2026.3.28",
    "lastRunCommand": "onboard",
    "lastRunMode": "local"
  },
  "models": {
    "mode": "merge",
    "providers": {
      "lmstudio": {
        "baseUrl": "http://127.0.0.1:1234/v1",
        "apiKey": "local-key",
        "api": "openai-completions",
        "models": [
          {
            "id": "google/gemma-4-e4b",
            "name": "google/gemma-4-e4b",
            "reasoning": false,
            "input": [
              "text",
              "image"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 4096,
            "maxTokens": 1024
          },
          {
            "id": "omnicoder-9b",
            "name": "omnicoder-9b",
            "reasoning": false,
            "input": [
              "text"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 262144,
            "maxTokens": 8192
          },
{
  "id": "qwen/qwen3-embedding-0.6b-gguf",
  "name": "qwen3-embedding-0.6b",
  "reasoning": false,
  "input": ["text"],
  "cost": { "input": 0, "output": 0 },
  "contextWindow": 32768,
  "maxTokens": 8192
},
          {
            "id": "qwen/qwen3.5-9b",
            "name": "qwen/qwen3.5-9b",
            "reasoning": false,
            "input": [
              "text",
              "image"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 262144,
            "maxTokens": 8192
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "lmstudio/google/gemma-4-e4b"
      },
      "models": {
        "lmstudio/google/gemma-4-e4b": {
          "alias": "gemma-4-e4b"
        },
        "lmstudio/qwen/qwen3.5-9b": {},
        "lmstudio/omnicoder-9b": {},
"lmstudio/qwen/qwen3-embedding-4b-gguf":{
"alias": "qwen3-embedding-4b"
}
      },
      "workspace": "%OPENCLAW_HOME%\\.openclaw\\workspace"
    }
  },
  "tools": {
    "profile": "coding",
    "web": {
      "search": {
        "enabled": true,
        "provider": "duckduckgo"
      }
    }
  },
  "commands": {
    "native": "auto",
    "nativeSkills": "auto",
    "restart": true,
    "ownerDisplay": "raw"
  },
  "session": {
    "dmScope": "per-channel-peer"
  },
  "hooks": {
    "internal": {
      "enabled": true,
      "entries": {
        "bootstrap-extra-files": {
          "enabled": true
        },
        "session-memory": {
          "enabled": true
        }
      }
    }
  },
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "loopback",
    "controlUi": {
      "allowInsecureAuth": true
    },
    "auth": {
      "mode": "token",
      "token": "029113dc0f23c61af77b39d0a13ddb5bca4f0f16c23cd8ae"
    },
    "tailscale": {
      "mode": "off",
      "resetOnExit": false
    },
    "nodes": {
      "denyCommands": [
        "camera.snap",
        "camera.clip",
        "screen.record",
        "contacts.add",
        "calendar.add",
        "reminders.add",
        "sms.send"
      ]
    }
  },
  "plugins": {
    "slots": {
      "memory": "memory-lancedb-pro",
      "contextEngine": "lossless-claw"
    },
    "entries": {
      "duckduckgo": {
        "enabled": true,
        "config": {}
      },
      "memory-lancedb-pro": {
        "config": {
          "embedding": {
            "provider": "openai-compatible",
            "baseURL": "http://127.0.0.1:1234/v1",
            "apiKey": "lmstudio",
            "model": "qwen/qwen3-embedding-4b-gguf",
            "dimensions": 1024,
            "chunking": true
          },
          "dbPath": "%OPENCLAW_HOME%/.openclaw/memory/lancedb-pro",
          "autoCapture": true,
          "autoRecall": true,
          "enableManagementTools": false,
          "sessionStrategy": "none",
          "autoRecallMinLength": 15,
          "autoRecallMinRepeated": 8,
          "autoRecallTimeoutMs": 5000,
          "autoRecallMaxItems": 3,
          "autoRecallMaxChars": 600,
          "autoRecallPerItemMaxChars": 180,
          "autoRecallMaxQueryLength": 2000,
          "maxRecallPerTurn": 10,
          "recallMode": "full",
          "smartExtraction": true,
          "extractMinMessages": 4,
          "extractMaxChars": 8000
        }
      },
      "lossless-claw": {
        "enabled": true,
        "config": {
          "dbPath": "%OPENCLAW_HOME%/.openclaw/memory/lossless/lcm.db",
          "contextThreshold": 0.6,
          "freshTailCount": 16,
          "incrementalMaxDepth": 5
        }
      },
      "memory-core": {
        "enabled": false
      }
    },
    "installs": {
      "lossless-claw": {
        "source": "npm",
        "spec": "@martian-engineering/lossless-claw",
        "installPath": "%OPENCLAW_HOME%\\.openclaw\\extensions\\lossless-claw",
        "version": "0.8.2",
        "resolvedName": "@martian-engineering/lossless-claw",
        "resolvedVersion": "0.8.2",
        "resolvedSpec": "@martian-engineering/lossless-claw@0.8.2",
        "integrity": "sha512-znlOYLnX60R1tvJAq8Nr5KRqw0o+LIl71jbGQOeuqZoolXqM/QxT/OXQhOjgkuHkIysd52XvyjKNm4PJIxwxLw==",
        "shasum": "a9368df82ddbae16abd7a9b9081ae42a079c4263",
        "resolvedAt": "2026-04-13T04:40:41.718Z",
        "installedAt": "2026-04-13T04:43:57.237Z"
      }
    }
  }
}

复制成功