设计原则: 模块化、可扩展、框架无关 最后更新: 2024年11月17日
aster 采用四层架构设计,将后端核心、Server 层、HTTP 层和客户端 SDK 完全解耦:
pkg/ 核心 SDK:
cmd/ HTTP 层:
依赖方向: Client → Server/HTTP → Core
职责分离: 展示层 → 服务层 → 接口层 → 业务层
四层职责:
15 个功能域:
每个模块独立,可按需使用。
三通道设计:
import (
"github.com/astercloud/aster/pkg/agent"
"github.com/astercloud/aster/pkg/store"
// 不会引入任何 HTTP 框架!
)
func main() {
store, _ := store.NewJSONStore(".data")
deps := &agent.Dependencies{Store: store}
config := &types.AgentConfig{TemplateID: "assistant"}
ag, _ := agent.Create(context.Background(), config, deps)
result, _ := ag.Chat(context.Background(), "Hello!")
println(result.Text)
}
# 使用内置的 Gin 实现
./aster serve --addr :8080
# 或自己实现 HTTP 层(用任何框架)
import { AgentsdkClient } from "@aster/client-js";
const client = new AgentsdkClient({
baseURL: "http://localhost:8080",
apiKey: "your-api-key",
});
// 使用任意资源
const response = await client.agents.chat({
input: "Hello, world!",
});
// 流式响应
for await (const event of client.agents.stream({ input: "..." })) {
console.log(event);
}
// 事件订阅
const sub = await client.agents.subscribe(["progress", "control"]);
for await (const event of sub) {
console.log(event);
}
| 特性 | aster | LangChain | CrewAI |
|---|---|---|---|
| 语言 | Go + TypeScript | Python | Python |
| 架构 | 三层解耦 | 单体 | 单体 |
| 框架依赖 | 零依赖 (核心) | 强依赖 | 强依赖 |
| 性能 | 极高 (Go) | 中等 | 中等 |
| 事件驱动 | ✅ 三通道 | ❌ | ❌ |
| Middleware | ✅ 洋葱模型 | ✅ | ❌ |
| 类型安全 | ✅ 完整 | ❌ | ❌ |
| 可扩展性 | ✅ 极强 | ✅ | ⚠️ |
版本: v2.0 最后更新: 2024年11月17日