(ctx context.Context, agentID string, st store.Store, provFactory provider.Factory)
| 95 | } |
| 96 | |
| 97 | func demonstrateSummary(ctx context.Context, agentID string, st store.Store, provFactory provider.Factory) { |
| 98 | // 加载消息 |
| 99 | messages, err := st.LoadMessages(ctx, agentID) |
| 100 | if err != nil { |
| 101 | log.Printf("Failed to load messages: %v", err) |
| 102 | return |
| 103 | } |
| 104 | |
| 105 | // 创建 Provider |
| 106 | prov, err := provFactory.Create(&types.ModelConfig{ |
| 107 | Provider: "anthropic", |
| 108 | Model: "claude-3-5-sonnet-20241022", |
| 109 | }) |
| 110 | if err != nil { |
| 111 | log.Printf("Failed to create provider: %v", err) |
| 112 | return |
| 113 | } |
| 114 | defer func() { |
| 115 | if err := prov.Close(); err != nil { |
| 116 | log.Printf("Failed to close provider: %v", err) |
| 117 | } |
| 118 | }() |
| 119 | |
| 120 | // 创建摘要器 |
| 121 | summarizer := session.NewSummarizer(session.SummarizerConfig{ |
| 122 | Provider: prov, |
| 123 | MaxMessagesPerCall: 50, |
| 124 | MinMessagesToSummarize: 3, |
| 125 | }) |
| 126 | |
| 127 | // 生成摘要 |
| 128 | summary, err := summarizer.SummarizeSession(ctx, messages) |
| 129 | if err != nil { |
| 130 | log.Printf("Failed to generate summary: %v", err) |
| 131 | return |
| 132 | } |
| 133 | |
| 134 | fmt.Printf("Summary (%d messages):\n", summary.MessageCount) |
| 135 | fmt.Printf("%s\n", truncate(summary.Text, 200)) |
| 136 | |
| 137 | if len(summary.KeyTopics) > 0 { |
| 138 | fmt.Printf("Key Topics: %v\n", summary.KeyTopics) |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | func demonstrateSearch(ctx context.Context, agentID string, st store.Store) { |
| 143 | // 创建搜索器 |
no test coverage detected