# 本機模型

> 在您自己的硬體上託管模型並執行 PentAGI，讓 prompt、tool output 與 finding 都保留在您的伺服器上。

PentAGI 可以完全在您自行託管的模型上執行。[agent](https://pentagi.com/zh-tw/docs/glossary/#agent) 的提示詞、它們讀取的工具輸出以及它們報告的 [finding](https://pentagi.com/zh-tw/docs/glossary/#finding) 都會保留在您的伺服器上，而一個長 [flow](https://pentagi.com/zh-tw/docs/glossary/#flow) 的成本是 GPU 時間而非 token。支援兩種類型的模型伺服器：Ollama（設定最快速）以及 vLLM 或任何其他具有 OpenAI 相容 API 的伺服器（以獲得更高的吞吐量）。

## [Ollama](https://pentagi.com/zh-tw/docs/deployment/local-models/#ollama)

在 `.env` 中將 PentAGI 指向 Ollama 伺服器：

```bash
OLLAMA_SERVER_URL=http://ollama-server:11434
OLLAMA_SERVER_CONFIG_PATH=/opt/pentagi/conf/ollama-qwen332b-fp16-tc.provider.yml
OLLAMA_SERVER_PULL_MODELS_ENABLED=false   # true downloads missing models at startup
OLLAMA_SERVER_LOAD_MODELS_ENABLED=false   # true lists the models the server already has
```

組態檔會為每個 [agent type](https://pentagi.com/zh-tw/docs/glossary/#agent-type) 指派模型及其參數；若沒有該檔案，`OLLAMA_SERVER_MODEL` 會設定預設模型。映像檔在 `/opt/pentagi/conf/` 中隨附了現成的組態，其中包括 `ollama-qwen332b-fp16-tc.provider.yml` 和 `ollama-qwq32b-fp16-tc.provider.yml`。

Ollama 的預設上下文視窗遠小於 flow 所需的大小：agent 通常使用約 64K token，而 PentAGI 設定為 110K。Ollama 僅在建立模型時設定上下文大小，因此請從 Modelfile 建構變體：

```dockerfile
FROM qwen3:32b-fp16
PARAMETER num_ctx 110000
PARAMETER temperature 0.3
PARAMETER top_p 0.8
PARAMETER min_p 0.0
PARAMETER top_k 20
PARAMETER repeat_penalty 1.1
```

```bash
ollama create qwen3:32b-fp16-tc -f Modelfile
```

## [vLLM 和其他 OpenAI 相容伺服器](https://pentagi.com/zh-tw/docs/deployment/local-models/#vllm-and-other-openai-compatible-servers)

vLLM、LocalAI 和其他具有 OpenAI 相容 API 的伺服器可作為 [自訂 provider](https://pentagi.com/zh-tw/docs/configuration/llm-providers/#custom-and-openai-compatible-endpoints) 連接：

```bash
LLM_SERVER_URL=http://vllm-server:8000/v1
LLM_SERVER_KEY=local                      # any non-empty value when the server has no key
LLM_SERVER_MODEL=Qwen/Qwen3.6-27B-FP8
LLM_SERVER_CONFIG_PATH=/opt/pentagi/conf/vllm-qwen3.6-27b-fp8.provider.yml
```

映像檔隨附了多個基於 vLLM 的 Qwen 建置組態；`-no-think` 變體會關閉推理功能。Agent 透過 [tool call](https://pentagi.com/zh-tw/docs/glossary/#tool-call) 進行工作，因此請使用針對您的模型推薦的 tool-call 解析器和 chat [template](https://pentagi.com/zh-tw/docs/glossary/#template) 啟動伺服器：若解析器錯誤，tool call 引數將會損毀，導致 flow 在幾個步驟後停止。

## [選擇模型](https://pentagi.com/zh-tw/docs/deployment/local-models/#choosing-a-model)

* 在組態檔中，將您最強大的模型提供給 `primary_agent`、`pentester` 和 `adviser`；較輕量的模型可用於服務 `searcher`、`enricher` 和摘要任務。
* 對於參數量低於 32B 的模型，請啟用 [執行監控與 task 規劃](https://pentagi.com/zh-tw/docs/concepts/agents/#safeguards)。這大約能使結果品質加倍，但代價是 token 用量和時間增加兩到三倍。
* 規劃記憶體需求：例如，FP16 格式的 QwQ 32B 需要約 71 GB 的 GPU 記憶體。

## [保持其餘堆疊在本機](https://pentagi.com/zh-tw/docs/deployment/local-models/#keep-the-rest-of-the-stack-local)

| 部分                                                 | 設定                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Embeddings                                         | `EMBEDDING_PROVIDER=ollama` 搭配 `EMBEDDING_MODEL` 中的 embedding 模型會使用相同的 Ollama 伺服器；本機 OpenAI 相容伺服器可搭配 `EMBEDDING_PROVIDER=openai` 使用，其位址位於 `EMBEDDING_URL`，且 `EMBEDDING_KEY` 需為非空值                                                                                                                                                                                                                               |
| Web search                                         | Search 會將 agent 的查詢傳送至網際網路。預設啟用 DuckDuckGo；使用 `DUCKDUCKGO_ENABLED=false` 將其關閉，並僅保留您接受的 [engines](https://pentagi.com/zh-tw/docs/configuration/search-engines/)，例如您自己的 SearXNG                                                                                                                                                                                                                                                            |
| [Knowledge graph](https://pentagi.com/zh-tw/docs/glossary/#knowledge-graph) | 預設為關閉。啟用時，Graphiti 會呼叫 OpenAI，除非 `GRAPHITI_LLM_CLIENT_TYPE=custom` 將其導向 `LLM_SERVER_URL` 中的伺服器，並使用 `EMBEDDING_MODEL` 中指定的模型（若為空則使用 `text-embedding-3-small`）向該伺服器請求嵌入向量。若該伺服器不提供該模型，請設定 `GRAPHITI_SEPARATE_EMBEDDING=true`：Graphiti 隨後會採用 PentAGI 所使用的 `EMBEDDING_URL`、`EMBEDDING_KEY` 和 `EMBEDDING_MODEL` 值，且這些值必須指向一個與 OpenAI 相容的伺服器 — 請參閱 [Knowledge graph](https://pentagi.com/zh-tw/docs/concepts/memory/#knowledge-graph-optional) |
| Observability                                      | 隨附的 Langfuse 和 Grafana 堆疊會在您的主機上執行 — 請參閱 [Observability](https://pentagi.com/zh-tw/docs/configuration/observability/)                                                                                                                                                                                                                                                                                                                    |
| Update check                                       | `UPDATE_CHECK_INTERVAL=0` 會將其關閉；[Security](https://pentagi.com/zh-tw/docs/configuration/security/#update-check) 列出了它傳送的內容                                                                                                                                                                                                                                                                                                                |
| Images                                             | Docker 會使用其自身的設定從 Docker Hub 拉取 [sandbox](https://pentagi.com/zh-tw/docs/glossary/#sandbox) 映像檔；在封閉網路中，請將 Docker daemon 指向 registry mirror                                                                                                                                                                                                                                                                                               |