跳转到内容

架构概览

Greentic 采用分层架构,并对关注点进行清晰分离:

┌─────────────────────────────────────────────────────────┐
│ Messaging Channels │
│ (Slack, Teams, Telegram, WhatsApp, WebChat) │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ Gateway (HTTP/NATS) │
│ Public Endpoint Router │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ greentic-runner │
│ (Production Runtime Host) │
│ ┌─────────────────────────────────────────────────┐ │
│ │ Flow Executor │ │
│ │ (Wasmtime Component Model) │ │
│ └─────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ Session Manager │ │
│ │ (Memory / Redis) │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ WASM Components │
│ (Flows, Providers, MCP Tools, Custom Components) │
└─────────────────────────────────────────────────────────┘

greentic-runner

主要的生产运行时,负责托管和执行 flows、管理 sessions,并协调所有平台服务。

greentic-flow

用于 .ygtc 文件的 flow schema 定义、中间表示(IR)、加载器与校验器。

greentic-pack

Pack 构建 CLI,用于创建已签名的 .gtpack 归档,其中包含 flows、components 和 assets。

greentic-component

用于构建 WASM components 的组件编写 CLI 与运行时工具集。

层级技术用途
WASM RuntimeWasmtime v41Component model 执行
Async RuntimeTokio v1异步 I/O、任务调度
HTTP ServerAxum v0.8REST API、webhooks
Message BusNATS事件分发、发布/订阅
Session StoreMemory/RedisFlow 状态持久化
SecretsAWS/Azure/GCP/Vault凭证管理
1. External Message (e.g., Slack)
2. Webhook Handler (Provider Ingress)
3. NATS: greentic.messaging.ingress.{env}.{tenant}.{team}.{channel}
4. Flow Router (tenant/team resolution)
5. Flow Executor (WASM component execution)
6. Session State Update
7. Reply/Action Nodes
8. NATS: greentic.messaging.egress.{env}.{tenant}.{team}.{channel}
9. Provider Egress → External Service
1. Bundle Configuration (greentic.demo.yaml)
2. Pack Resolver (local/OCI registry)
3. Signature Verification (ed25519-dalek)
4. CBOR Metadata Parsing
5. WASM Component Instantiation
6. WIT Interface Binding
7. Runtime Registration

Greentic 在每一层都实现了租户隔离:

Tenant
└── Environment (prod, staging, dev)
└── Team
└── Channel (messaging provider instance)
└── Session (user conversation state)

TenantCtx 结构体会贯穿所有操作:

pub struct TenantCtx {
pub tenant_id: String,
pub env_id: String,
pub team_id: Option<String>,
}

Greentic 使用 WebAssembly Interface Types (WIT) 规范来定义组件接口:

greentic-interfaces/wit/component.wit
package greentic:component;
interface types {
record message {
id: string,
content: string,
sender: string,
timestamp: u64,
}
record outcome {
success: bool,
data: option<string>,
error: option<string>,
}
}
world component {
import types;
export execute: func(input: types.message) -> types.outcome;
}
greentic-types ─────────────────────────── (foundation)
greentic-telemetry
greentic-interfaces ← greentic-types
greentic-config ← greentic-types
greentic-session ← greentic-types
greentic-state ← greentic-types + greentic-interfaces
greentic-flow ← greentic-interfaces + greentic-types
greentic-pack ← greentic-flow + greentic-types
greentic-component ← greentic-interfaces + greentic-types
greentic-mcp ← greentic-interfaces + greentic-types
greentic-runner ← ALL of the above

Greentic 使用 OpenTelemetry 实现分布式追踪与指标采集:

  • Tracing: 使用 OTLP exporter 进行分布式 trace 关联
  • Metrics: Flow 执行时间、消息吞吐量、错误率
  • Logging: 携带 trace context 的结构化日志
  • Flows - 了解 flow 定义
  • Packs - 理解 pack 结构
  • Components - 构建自定义 WASM components