diff options
| author | Grail Finder <wohilas@gmail.com> | 2025-12-28 00:06:09 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2025-12-28 00:06:09 +0300 |
| commit | cae7dea2e7c149edd055b542a2a08b53af8a0ac8 (patch) | |
| tree | 5e387c1e6197b91b945fbff01218df45cad86ca2 /bot.go | |
| parent | 29becaa8c83c8dff8af7623ca71e8021319887ab (diff) | |
| parent | 9d91685e9adde94d20313fb405c4301b4dd59a75 (diff) | |
Merge branch 'master' into doc/tutorial
Diffstat (limited to 'bot.go')
| -rw-r--r-- | bot.go | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -88,6 +88,10 @@ func cleanNullMessages(messages []models.RoleMsg) []models.RoleMsg { } func cleanToolCalls(messages []models.RoleMsg) []models.RoleMsg { + // If AutoCleanToolCallsFromCtx is false, keep tool call messages in context + if cfg != nil && !cfg.AutoCleanToolCallsFromCtx { + return consolidateConsecutiveAssistantMessages(messages) + } cleaned := make([]models.RoleMsg, 0, len(messages)) for i, msg := range messages { // recognize the message as the tool call and remove it @@ -731,7 +735,7 @@ func cleanChatBody() { for i, msg := range chatBody.Messages { logger.Debug("cleanChatBody: before clean", "index", i, "role", msg.Role, "content_len", len(msg.Content), "has_content", msg.HasContent(), "tool_call_id", msg.ToolCallID) } - // TODO: consider case where we keep tool requests + // Tool request cleaning is now configurable via AutoCleanToolCallsFromCtx (default false) // /completion msg where part meant for user and other part tool call chatBody.Messages = cleanToolCalls(chatBody.Messages) chatBody.Messages = cleanNullMessages(chatBody.Messages) @@ -1029,6 +1033,38 @@ func refreshLocalModelsIfEmpty() { localModelsMu.Unlock() } +func summarizeAndStartNewChat() { + if len(chatBody.Messages) == 0 { + _ = notifyUser("info", "No chat history to summarize") + return + } + _ = notifyUser("info", "Summarizing chat history...") + // Call the summarize_chat tool via agent + summaryBytes := callToolWithAgent("summarize_chat", map[string]string{}) + summary := string(summaryBytes) + if summary == "" { + _ = notifyUser("error", "Failed to generate summary") + return + } + // Start a new chat + startNewChat() + // Inject summary as a tool call response + toolMsg := models.RoleMsg{ + Role: cfg.ToolRole, + Content: summary, + ToolCallID: "", + } + chatBody.Messages = append(chatBody.Messages, toolMsg) + // Update UI + textView.SetText(chatToText(cfg.ShowSys)) + colorText() + // Update storage + if err := updateStorageChat(activeChatName, chatBody.Messages); err != nil { + logger.Warn("failed to update storage after injecting summary", "error", err) + } + _ = notifyUser("info", "Chat summarized and new chat started with summary as tool response") +} + func init() { var err error cfg, err = config.LoadConfig("config.toml") |
