MCPcopy Create free account
hub / github.com/astercloud/aster / main

Function main

examples/router/main.go:21–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19)
20
21func main() {
22 ctx := context.Background()
23
24 // 简单的JSON存储 + 本地沙箱
25 memStore, err := store.NewJSONStore("./.aster-router")
26 if err != nil {
27 log.Fatalf("Failed to create store: %v", err)
28 }
29 sbFactory := sandbox.NewFactory()
30
31 // Provider 工厂
32 providerFactory := provider.NewMultiProviderFactory()
33
34 // 模板注册:同一个模板 ID,但可以通过 RoutingProfile 决定实际模型
35 tplRegistry := agent.NewTemplateRegistry()
36 tplRegistry.Register(&types.AgentTemplateDefinition{
37 ID: "router-demo",
38 SystemPrompt: "You are a helpful assistant.",
39 Model: "claude-3-5-sonnet-20241022",
40 Tools: []string{},
41 })
42
43 // 构造静态路由器:
44 // - quality-first: 使用 anthropic 的较强模型(示例)
45 // - cost-first: 使用 deepseek 的模型(示例)
46 defaultModel := &types.ModelConfig{
47 Provider: "anthropic",
48 Model: "claude-3-5-sonnet-20241022",
49 }
50
51 routes := []router.StaticRouteEntry{
52 {
53 Task: "chat",
54 Priority: router.PriorityQuality,
55 Model: &types.ModelConfig{
56 Provider: "anthropic",
57 Model: "claude-3-5-sonnet-20241022",
58 },
59 },
60 {
61 Task: "chat",
62 Priority: router.PriorityCost,
63 Model: &types.ModelConfig{
64 Provider: "deepseek",
65 Model: "deepseek-chat",
66 },
67 },
68 }
69
70 rt := router.NewStaticRouter(defaultModel, routes)
71
72 deps := &agent.Dependencies{
73 Store: memStore,
74 SandboxFactory: sbFactory,
75 ToolRegistry: toolsRegistry(),
76 ProviderFactory: providerFactory,
77 Router: rt,
78 TemplateRegistry: tplRegistry,

Callers

nothing calls this directly

Calls 14

RegisterMethod · 0.95
NewJSONStoreFunction · 0.92
NewFactoryFunction · 0.92
NewMultiProviderFactoryFunction · 0.92
NewTemplateRegistryFunction · 0.92
NewStaticRouterFunction · 0.92
CreateFunction · 0.92
toolsRegistryFunction · 0.85
cancelFunction · 0.85
PrintfMethod · 0.80
CloseMethod · 0.65
runDemoFunction · 0.50

Tested by

no test coverage detected