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

Function main

examples/structured-output/main.go:37–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35}
36
37func 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.
88Return 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",

Callers

nothing calls this directly

Calls 15

ParseIntoMethod · 0.95
NewJSONStoreFunction · 0.92
NewRegistryFunction · 0.92
RegisterAllFunction · 0.92
NewFactoryFunction · 0.92
NewMultiProviderFactoryFunction · 0.92
CreateFunction · 0.92
NewTypedParserFunction · 0.92
MustGenerateSchemaFunction · 0.92
ParseTypedFunction · 0.92
PrintfMethod · 0.80
createTemplateRegistryFunction · 0.70

Tested by

no test coverage detected