()
| 18 | ) |
| 19 | |
| 20 | func main() { |
| 21 | ctx := context.Background() |
| 22 | |
| 23 | // 创建依赖 |
| 24 | jsonStore, err := store.NewJSONStore(".aster-session-enhanced") |
| 25 | if err != nil { |
| 26 | log.Fatalf("Failed to create store: %v", err) |
| 27 | } |
| 28 | |
| 29 | toolRegistry := tools.NewRegistry() |
| 30 | builtin.RegisterAll(toolRegistry) |
| 31 | |
| 32 | deps := &agent.Dependencies{ |
| 33 | Store: jsonStore, |
| 34 | SandboxFactory: sandbox.NewFactory(), |
| 35 | ToolRegistry: toolRegistry, |
| 36 | ProviderFactory: provider.NewMultiProviderFactory(), |
| 37 | TemplateRegistry: createTemplateRegistry(), |
| 38 | } |
| 39 | |
| 40 | // 创建 Agent |
| 41 | config := &types.AgentConfig{ |
| 42 | TemplateID: "chat-agent", |
| 43 | ModelConfig: &types.ModelConfig{ |
| 44 | Provider: "anthropic", |
| 45 | Model: "claude-3-5-sonnet-20241022", |
| 46 | }, |
| 47 | } |
| 48 | |
| 49 | ag, err := agent.Create(ctx, config, deps) |
| 50 | if err != nil { |
| 51 | log.Fatalf("Failed to create agent: %v", err) |
| 52 | } |
| 53 | defer func() { |
| 54 | if err := ag.Close(); err != nil { |
| 55 | log.Printf("Failed to close agent: %v", err) |
| 56 | } |
| 57 | }() |
| 58 | |
| 59 | // 模拟对话 |
| 60 | fmt.Println("=== Simulating Conversation ===") |
| 61 | fmt.Println() |
| 62 | |
| 63 | conversations := []string{ |
| 64 | "What is the capital of France?", |
| 65 | "Tell me about the Eiffel Tower", |
| 66 | "What are some famous French dishes?", |
| 67 | "How do I make croissants?", |
| 68 | "What's the history of Paris?", |
| 69 | } |
| 70 | |
| 71 | for i, msg := range conversations { |
| 72 | fmt.Printf("User: %s\n", msg) |
| 73 | result, err := ag.Chat(ctx, msg) |
| 74 | if err != nil { |
| 75 | log.Printf("Error: %v", err) |
| 76 | continue |
| 77 | } |
nothing calls this directly
no test coverage detected