()
| 18 | ) |
| 19 | |
| 20 | func 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", |
nothing calls this directly
no test coverage detected