> 为什么大多数代理应用不仅仅需要一个模型,它们还需要 路由规划、护栏、审批、审计和服务合同AgentFabric 提供织物。
亮点
- 代理层编排器+推理引擎(大型语言模型/小型语言模型)、内存,以及使用OPA(Open Policy Agent,开放策略代理,无具体日期)进行策略检查。
- 服务层用于订单、支付、库存、通知的REST微服务。
- 平台层Kubernetes(Kubernetes 作者,未注明日期),服务网格例如 Istio(Istio 作者,未注明日期),NATS 队列(Synadia 通讯,未注明日期),存储,以及使用 OpenTelemetry 实现可观测性(OpenTelemetry 作者,未注明日期)。
- 治理外部化决策(PDP)、如个人身份信息(PII)编辑、审计追踪等义务(Open Policy Agent,未注明日期;OpenTelemetry 作者,未注明日期)。
- MCP(Minimum Change Principle,最小变化原则)可选模型上下文协议服务器,用于向智能体暴露工具/资源(OpenAI,未注明日期)。
快速入门(Docker Compose)```bash
From the repo root
docker compose up -d --build
Or bring up OPA first:
docker compose up -d opa
**健康检查**
- OPA (PowerShell): `curl.exe "http://localhost:8181/health?plugins&bundles"`
- OPA(CMD): `curl http://localhost:8181/health?plugins^&bundles`
______________________________________________________________________
## 架构(系统概览)```mermaid
flowchart LR
subgraph A["Agent Layer — Plan · Act · Learn"]
U["User / Client"]
ORCH["Orchestrator Agent"]
LLM["Reasoning Engine (LLM / SLM)"]
MEM["Memory"]
POL["Policy Client"]
end
subgraph S["Services"]
ODR["Orders API"]
PAY["Payments API"]
INV["Inventory API"]
NOTI["Notifications API"]
ETL["Data Service ETL"]
end
subgraph P["Platform"]
MESH["Service Mesh Istio"]
Q["Queue NATS"]
OBS["Observability OTel"]
K8S["Kubernetes"]
STO["Storage"]
OPA["OPA PDP"]
end
%% Agent edges
U --> ORCH
ORCH --> LLM
ORCH --> MEM
ORCH --> POL
POL --> OPA
%% Service mesh fanout
ORCH --> MESH
MESH --> ODR
MESH --> PAY
MESH --> INV
MESH --> NOTI
%% Queue / ETL
ORCH --> Q
Q --> ETL
%% Storage
ODR --> STO
PAY --> STO
INV --> STO
ETL --> STO
%% Telemetry
ODR -.-> OBS
PAY -.-> OBS
INV -.-> OBS
NOTI -.-> OBS
ETL -.-> OBS
ORCH -.-> OBS
MESH -.-> OBS
%% Infra ties
MESH --- K8S
ODR --- K8S
PAY --- K8S
INV --- K8S
NOTI --- K8S
ETL --- K8S
ORCH --- K8S
OPA --- K8S
%% Styling
classDef agent fill:#e8f1ff,stroke:#1b66ff,color:#0b2e6e
classDef think fill:#fff2cc,stroke:#e6a100,color:#4a3b00
classDef policy fill:#fde2e2,stroke:#e63b3b,color:#5a0c0c
classDef svc fill:#eaffea,stroke:#16a34a,color:#064b23
classDef mesh fill:#e6fcff,stroke:#06b6d4,color:#034752
classDef queue fill:#f1e8ff,stroke:#7c3aed,color:#2d0d5a
classDef store fill:#fff0e6,stroke:#fb923c,color:#5a2c00
classDef obs fill:#f5f3ff,stroke:#6366f1,color:#1f1b6b
classDef k8s fill:#eef2ff,stroke:#3b82f6,color:#0b255c
class U,ORCH agent
class LLM,MEM think
class POL policy
class ODR,PAY,INV,NOTI,ETL svc
class MESH mesh
class Q queue
class OBS obs
class K8S k8s
class STO store
治理与政策(OPA/注册)```mermaid
flowchart LR
subgraph Request
RQ["Action Request: tool + args + actor + context"]
end
RQ --> PDPC["Policy Client"]
PDPC --> OPA["OPA PDP"]
OPA -->|allow or deny with obligations| PDPC
PDPC -->|enforce obligations eg redact| EXEC["Executor or Router"]
EXEC --> SVC["Domain Service"]
SVC --> AUD["Audit and OTel spans"]
classDef policy fill:#fde2e2,stroke:#e63b3b,color:#5a0c0c
classDef svc fill:#eaffea,stroke:#16a34a,color:#064b23
classDef obs fill:#f5f3ff,stroke:#6366f1,color:#1f1b6b
class PDPC,OPA policy
class SVC,AUD obs
**示例策略(`policy/policy.rego`)**```rego
package agent
default allow = false
# Simple allow for smoke tests
allow {
input.tool == "ping"
}
# Example: payments guard
deny[msg] {
input.tool == "charge_payment"
input.args.amount > 1000
msg := "amount exceeds limit; approval required"
}
requires_approval {
input.tool == "charge_payment"
input.args.amount > 1000
}
协调器查询: POST /v1/data/agent/allow 并且可以读取辅助数据(例如。, requires_approval(开放策略代理,无日期)。
编排序列```mermaid
sequenceDiagram
autonumber
participant U as User
participant A as Orchestrator
participant P as OPA PDP
participant R as Reasoning LLM or SLM
participant S as Service API
participant Q as NATS Queue
participant O as Observability
U->>A: POST /act (goal, tool, args)
A->>P: policy input (tool, args, actor, context)
alt allowed
P-->>A: allow true, obligations
A->>R: plan or transform
A->>S: call service with obligations
S-->>A: result
else approval required
P-->>A: allow false, requires approval
A-->>U: 202 Accepted (pending)
end
A->>Q: publish ETL job optional
A-->>U: response
A-)+O: OTel spans and logs
______________________________________________________________________
## 部署拓扑(K8s)```mermaid
flowchart TB
subgraph "Kubernetes Cluster"
subgraph "Namespace: agentfabric"
subgraph Control
OPA["OPA Deployment"]
OTL["OTel Collector"]
end
subgraph Apps
ORCH["Orchestrator Deployment"]
ODR["Orders"]
PAY["Payments"]
INV["Inventory"]
NOTI["Notifications"]
ETL["Data Service"]
end
Q["NATS"]
PVC["PersistentVolumeClaim data"]
end
end
ORCH --> OPA
ORCH --> OTL
ODR --> OTL
PAY --> OTL
INV --> OTL
NOTI --> OTL
ETL --> OTL
ETL --> PVC
配置
- OPA 端点:
OPA_URL=http://opa:8181/v1/data/agent/allow - OTel(OpenTelemetry):
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 - 服务URL:
ORDERS_URL,PAYMENTS_URL,INVENTORY_URL,NOTIFY_URL - 队列:
NATS_URL=nats://nats:4222
编写OPA片段yaml
opa:
image: openpolicyagent/opa:0.67.0
command: ["run","--server","--addr=:8181","/policy"]
volumes:
- ./policy:/policy:ro
ports:
- "8181:8181"
参考文献(APA格式)
作者
弗里曼·奥古斯塔斯·杰克逊 — 维护者及原始作者。\
欢迎在 https://github.com/4th/AgenticFabric 提出问题和贡献代码
