# 架構

> PentAGI 執行的服務、彼此間的通訊方式，以及哪些為選用項目。

PentAGI 由一組 Docker 服務組成。核心堆疊足以執行 [flows](https://pentagi.com/zh-tw/docs/glossary/#flow)；[knowledge graph](https://pentagi.com/zh-tw/docs/glossary/#knowledge-graph) 與可觀測性堆疊則為選用附加元件。

## [系統脈絡](https://pentagi.com/zh-tw/docs/concepts/architecture/#system-context)

```mermaid
flowchart LR
  accTitle: System context of PentAGI with its users, targets, LLM providers, search engines, monitoring and the update server
  user["Security engineer"] -->|HTTPS| pentagi["PentAGI"]
  user -->|monitors| langfuse["Langfuse"]
  user -->|monitors| grafana["Grafana"]
  pentagi -->|tests| target["Target systems"]
  pentagi -->|queries| llm["LLM providers"]
  pentagi -->|searches| search["Search engines"]
  pentagi -->|reports| langfuse
  pentagi -->|reports| grafana
  pentagi -->|checks for updates| update["update.pentagi.com"]
```

PentAGI 也會在啟動後兩分鐘內，以及之後每三小時檢查 `update.pentagi.com` 是否有較新的建置版本，並在請求中傳送安裝摘要；[更新檢查](https://pentagi.com/zh-tw/docs/configuration/security/#update-check) 列出了其中包含的內容以及如何關閉此功能。

## [服務](https://pentagi.com/zh-tw/docs/concepts/architecture/#services)

| 群組              | 服務                                                                                                                               | Compose 檔案                         |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| 核心              | `pentagi`（具備 REST 與 GraphQL 的 Go 後端、React UI）、`pgvector`（搭載 pgvector 的 PostgreSQL）、`pgexporter`（PostgreSQL 指標）、`scraper`（隔離式瀏覽器） | `docker-compose.yml`               |
| Knowledge graph | `graphiti`、`neo4j`                                                                                                               | `docker-compose-graphiti.yml`      |
| LLM 可觀測性        | `langfuse-web`、`langfuse-worker`、`clickhouse`、`redis`、`minio`、`postgres`                                                         | `docker-compose-langfuse.yml`      |
| 系統可觀測性          | `grafana`、`otel`、`victoriametrics`、`jaeger`、`clickstore`、`loki`、`node-exporter`、`cadvisor`                                       | `docker-compose-observability.yml` |

[Tools](https://pentagi.com/zh-tw/docs/glossary/#tool) 絕不會在 `pentagi` 容器本身內部執行：每個 flow 都會取得自己的 [sandbox](https://pentagi.com/zh-tw/docs/glossary/#sandbox) 容器，這些容器是根據 flow 的目標所挑選的映像檔（例如 Kali Linux）所建構。

## [容器](https://pentagi.com/zh-tw/docs/concepts/architecture/#containers)

```mermaid
graph TB
  accTitle: Containers of the core stack and the optional knowledge graph
  subgraph Core
    UI[Web UI] -->|HTTP/WS| API[Backend API]
    API --> DB[(PostgreSQL + pgvector)]
    API --> Agents[Agents]
    Agents --> Sandbox[Sandboxed tools]
    Agents --> Scraper[Isolated browser]
  end
  subgraph Knowledge graph
    Graphiti --> Neo4j[(Neo4j)]
  end
  Agents --> Graphiti
  API -->|telemetry| OTEL[OpenTelemetry]
  API -->|LLM traces| Langfuse
```

* **後端 API** — 以 Go 撰寫，提供 REST 與 GraphQL 介面，並支援 Bearer Token 存取以利自動化。
* **Vector store** — 搭載 pgvector 的 PostgreSQL，用於保存所有命令、輸出與嵌入資料。
* **Agents** — 負責規劃與執行工作的多代理系統；請參閱 [Agents](https://pentagi.com/zh-tw/docs/concepts/agents/)。
* **Sandbox** — 與主機隔離的 tool 容器；在生產環境中，它們可以部署於獨立的 [worker node](https://pentagi.com/zh-tw/docs/deployment/worker-node/) 上。