Ollama Local
Work with local Ollama models for inference, embeddings, and tool use.
Configuration
Set your Ollama host (defaults to http://localhost:11434):
CODEBLOCK0
Quick Reference
CODEBLOCK1
Model Selection
See references/models.md for full model list and selection guide.
Quick picks:
- - Fast answers: INLINECODE1
- Coding: INLINECODE2
- General: INLINECODE3
- Reasoning: INLINECODE4
Tool Use
Some local models support function calling. Use ollama_tools.py:
CODEBLOCK2
Tool-capable models: qwen2.5-coder, qwen3, llama3.1, mistral
OpenClaw Sub-Agents
Spawn local model sub-agents with sessions_spawn:
CODEBLOCK3
Model path format: INLINECODE7
Parallel Agents (Think Tank Pattern)
Spawn multiple local agents for collaborative tasks:
CODEBLOCK4
Direct API
For custom integrations, use the Ollama API directly:
CODEBLOCK5
Troubleshooting
Connection refused?
- - Check Ollama is running: INLINECODE8
- Verify OLLAMA_HOST is correct
- For remote servers, ensure firewall allows port 11434
Model not loading?
- - Check VRAM: larger models may need CPU offload
- Try a smaller model first
Slow responses?
- - Model may be running on CPU
- Use smaller quantization (e.g.,
:7b instead of :30b)
OpenClaw sub-agent falls back to default model?
- - Ensure
ollama:default auth profile exists in OpenClaw config - Check model path format: INLINECODE12
Ollama 本地
使用本地 Ollama 模型进行推理、嵌入和工具调用。
配置
设置您的 Ollama 主机(默认为 http://localhost:11434):
bash
export OLLAMA_HOST=http://localhost:11434
或者用于远程服务器:
export OLLAMA_HOST=http://192.168.1.100:11434
快速参考
bash
列出模型
python3 scripts/ollama.py list
拉取模型
python3 scripts/ollama.py pull llama3.1:8b
删除模型
python3 scripts/ollama.py rm modelname
显示模型详情
python3 scripts/ollama.py show qwen3:4b
与模型对话
python3 scripts/ollama.py chat qwen3:4b 法国的首都是什么?
使用系统提示词对话
python3 scripts/ollama.py chat llama3.1:8b 审查这段代码 -s 你是一名代码审查员
生成补全(非对话模式)
python3 scripts/ollama.py generate qwen3:4b 从前
获取嵌入向量
python3 scripts/ollama.py embed bge-m3 要嵌入的文本
模型选择
完整模型列表和选择指南请参见 references/models.md。
快速推荐:
- - 快速回答:qwen3:4b
- 编程:qwen2.5-coder:7b
- 通用:llama3.1:8b
- 推理:deepseek-r1:8b
工具调用
部分本地模型支持函数调用。使用 ollama_tools.py:
bash
带工具的单一请求
python3 scripts/ollama_tools.py single qwen2.5-coder:7b 阿姆斯特丹的天气怎么样?
完整工具循环(模型调用工具、获取结果、回复)
python3 scripts/ollama_tools.py loop qwen3:4b 搜索 Python 教程并总结
显示可用的示例工具
python3 scripts/ollama_tools.py tools
支持工具的模型: qwen2.5-coder、qwen3、llama3.1、mistral
OpenClaw 子代理
使用 sessions_spawn 生成本地模型子代理:
python
示例:生成一个编程代理
sessions_spawn(
task=审查这段 Python 代码中的错误,
model=ollama/qwen2.5-coder:7b,
label=代码审查
)
模型路径格式:ollama/<模型名称>
并行代理(智囊团模式)
生成多个本地代理进行协作任务:
python
agents = [
{label: 架构师, model: ollama/gemma3:12b, task: 设计系统架构},
{label: 程序员, model: ollama/qwen2.5-coder:7b, task: 实现核心逻辑},
{label: 审查员, model: ollama/llama3.1:8b, task: 审查错误和改进点},
]
for a in agents:
sessions_spawn(task=a[task], model=a[model], label=a[label])
直接 API
对于自定义集成,直接使用 Ollama API:
bash
对话
curl $OLLAMA_HOST/api/chat -d {
model: qwen3:4b,
messages: [{role: user, content: 你好}],
stream: false
}
生成
curl $OLLAMA_HOST/api/generate -d {
model: qwen3:4b,
prompt: 为什么天空是蓝色的?,
stream: false
}
列出模型
curl $OLLAMA_HOST/api/tags
拉取模型
curl $OLLAMA_HOST/api/pull -d {name: phi3:mini}
故障排除
连接被拒绝?
- - 检查 Ollama 是否正在运行:ollama serve
- 确认 OLLAMA_HOST 设置正确
- 对于远程服务器,确保防火墙允许 11434 端口
模型无法加载?
- - 检查显存:较大的模型可能需要 CPU 卸载
- 先尝试较小的模型
响应缓慢?
- - 模型可能正在 CPU 上运行
- 使用较小的量化版本(例如,使用 :7b 而不是 :30b)
OpenClaw 子代理回退到默认模型?
- - 确保 OpenClaw 配置中存在 ollama:default 认证配置文件
- 检查模型路径格式:ollama/模型名称:标签