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

Function main

examples/agent/main.go:20–145  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18)
19
20func main() {
21 // 检查API Key
22 apiKey := os.Getenv("ANTHROPIC_API_KEY")
23 if apiKey == "" {
24 log.Fatal("ANTHROPIC_API_KEY environment variable is required")
25 }
26
27 // 创建上下文
28 ctx := context.Background()
29
30 // 1. 创建工具注册表并注册内置工具
31 toolRegistry := tools.NewRegistry()
32 builtin.RegisterAll(toolRegistry)
33
34 // 2. 创建Sandbox工厂
35 sandboxFactory := sandbox.NewFactory()
36
37 // 3. 创建Provider工厂
38 providerFactory := &provider.AnthropicFactory{}
39
40 // 4. 创建Store
41 storePath := ".aster"
42 jsonStore, err := store.NewJSONStore(storePath)
43 if err != nil {
44 log.Fatalf("Failed to create store: %v", err)
45 }
46
47 // 5. 创建模板注册表
48 templateRegistry := agent.NewTemplateRegistry()
49
50 // 注册一个简单的助手模板
51 templateRegistry.Register(&types.AgentTemplateDefinition{
52 ID: "simple-assistant",
53 Model: "claude-sonnet-4-5",
54 SystemPrompt: "You are a helpful assistant that can read and write files. When users ask you to read or write files, use the available tools.",
55 Tools: []any{"Read", "Write", "Bash"},
56 })
57
58 // 6. 创建依赖
59 deps := &agent.Dependencies{
60 Store: jsonStore,
61 SandboxFactory: sandboxFactory,
62 ToolRegistry: toolRegistry,
63 ProviderFactory: providerFactory,
64 TemplateRegistry: templateRegistry,
65 }
66
67 // 7. 创建Agent配置
68 config := &types.AgentConfig{
69 TemplateID: "simple-assistant",
70 ModelConfig: &types.ModelConfig{
71 Provider: "anthropic",
72 Model: "claude-sonnet-4-5",
73 APIKey: apiKey,
74 },
75 Sandbox: &types.SandboxConfig{
76 Kind: types.SandboxKindLocal,
77 WorkDir: "./workspace",

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
NewRegistryFunction · 0.92
RegisterAllFunction · 0.92
NewFactoryFunction · 0.92
NewJSONStoreFunction · 0.92
NewTemplateRegistryFunction · 0.92
CreateFunction · 0.92
PrintfMethod · 0.80
handleProgressEventFunction · 0.70
handleMonitorEventFunction · 0.70
CloseMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected