()
| 19 | ) |
| 20 | |
| 21 | func main() { |
| 22 | // 检查 API Key |
| 23 | apiKey := os.Getenv("ANTHROPIC_API_KEY") |
| 24 | if apiKey == "" { |
| 25 | log.Fatal("ANTHROPIC_API_KEY environment variable is required") |
| 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 | jsonStore, err := store.NewJSONStore(".aster-memory-agent") |
| 42 | if err != nil { |
| 43 | log.Fatalf("create store failed: %v", err) |
| 44 | } |
| 45 | |
| 46 | // 5. 模板注册表 |
| 47 | templateRegistry := agent.NewTemplateRegistry() |
| 48 | templateRegistry.Register(&types.AgentTemplateDefinition{ |
| 49 | ID: "memory-assistant", |
| 50 | // SystemPrompt 仅描述职责, 具体的长期记忆说明由 AgentMemoryMiddleware 注入 |
| 51 | SystemPrompt: "You are an assistant with file access and long-term memory. " + |
| 52 | "Always prefer reading from and writing to memory files when users ask to remember or recall information.", |
| 53 | Model: "claude-sonnet-4-5", |
| 54 | // 这里只配置基础工具; memory_* 工具由中间件自动注入 |
| 55 | Tools: []any{"Read", "Write", "Bash"}, |
| 56 | }) |
| 57 | |
| 58 | deps := &agent.Dependencies{ |
| 59 | Store: jsonStore, |
| 60 | SandboxFactory: sandboxFactory, |
| 61 | ToolRegistry: toolRegistry, |
| 62 | ProviderFactory: providerFactory, |
| 63 | TemplateRegistry: templateRegistry, |
| 64 | } |
| 65 | |
| 66 | // 6. 为 Sandbox 工作目录准备本地路径 |
| 67 | workDir := "./workspace" |
| 68 | if err := os.MkdirAll(workDir, 0o755); err != nil { |
| 69 | log.Fatalf("create workspace dir failed: %v", err) |
| 70 | } |
| 71 | |
| 72 | // 7. 创建 Agent 配置, 启用 filesystem + agent_memory 中间件 |
| 73 | config := &types.AgentConfig{ |
| 74 | TemplateID: "memory-assistant", |
| 75 | ModelConfig: &types.ModelConfig{ |
| 76 | Provider: "anthropic", |
| 77 | Model: "claude-sonnet-4-5", |
| 78 | APIKey: apiKey, |
nothing calls this directly
no test coverage detected