()
| 35 | } |
| 36 | |
| 37 | func main() { |
| 38 | ctx := context.Background() |
| 39 | |
| 40 | // 创建依赖 |
| 41 | jsonStore, err := store.NewJSONStore(".aster-structured-output") |
| 42 | if err != nil { |
| 43 | log.Fatalf("Failed to create store: %v", err) |
| 44 | } |
| 45 | |
| 46 | toolRegistry := tools.NewRegistry() |
| 47 | builtin.RegisterAll(toolRegistry) |
| 48 | |
| 49 | deps := &agent.Dependencies{ |
| 50 | Store: jsonStore, |
| 51 | SandboxFactory: sandbox.NewFactory(), |
| 52 | ToolRegistry: toolRegistry, |
| 53 | ProviderFactory: provider.NewMultiProviderFactory(), |
| 54 | TemplateRegistry: createTemplateRegistry(), |
| 55 | } |
| 56 | |
| 57 | // 创建 Agent 配置(启用 Structured Output Middleware) |
| 58 | config := &types.AgentConfig{ |
| 59 | TemplateID: "structured-agent", |
| 60 | ModelConfig: &types.ModelConfig{ |
| 61 | Provider: "anthropic", |
| 62 | Model: "claude-3-5-sonnet-20241022", |
| 63 | }, |
| 64 | Middlewares: []string{"structured_output"}, |
| 65 | MiddlewareConfig: map[string]map[string]any{ |
| 66 | "structured_output": { |
| 67 | "enabled": true, |
| 68 | "required_fields": []string{"tasks", "total"}, |
| 69 | "allow_text_backup": false, |
| 70 | }, |
| 71 | }, |
| 72 | } |
| 73 | |
| 74 | // 创建 Agent |
| 75 | ag, err := agent.Create(ctx, config, deps) |
| 76 | if err != nil { |
| 77 | log.Fatalf("Failed to create agent: %v", err) |
| 78 | } |
| 79 | defer func() { |
| 80 | if err := ag.Close(); err != nil { |
| 81 | log.Printf("Failed to close agent: %v", err) |
| 82 | } |
| 83 | }() |
| 84 | |
| 85 | // 示例 1: 生成任务列表 |
| 86 | fmt.Println("=== Example 1: Generate Task List ===") |
| 87 | prompt := `Create a task list for building a web application. |
| 88 | Return the result in JSON format with the following structure: |
| 89 | { |
| 90 | "tasks": [ |
| 91 | { |
| 92 | "id": "task-1", |
| 93 | "title": "Task title", |
| 94 | "description": "Task description", |
nothing calls this directly
no test coverage detected