From 1ba519633e3d1d8b614ee2dd9c2f228801eb5e45 Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Fri, 23 Jan 2026 14:42:27 +0100 Subject: [PATCH 1/6] feat: add unsummarized memories Signed-off-by: Jana Peper --- lib/Controller/ChattyLLMController.php | 8 +++---- lib/Service/SessionSummaryService.php | 31 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/Controller/ChattyLLMController.php b/lib/Controller/ChattyLLMController.php index bde83575..91457684 100644 --- a/lib/Controller/ChattyLLMController.php +++ b/lib/Controller/ChattyLLMController.php @@ -1037,7 +1037,7 @@ private function scheduleLLMChatTask( 'history' => $history, ]; if (isset($this->taskProcessingManager->getAvailableTaskTypes()[TextToTextChat::ID]['optionalInputShape']['memories'])) { - $input['memories'] = $this->sessionSummaryService->getUserSessionSummaries($this->userId); + $input['memories'] = $this->sessionSummaryService->getMemories($this->userId); } $task = new Task(TextToTextChat::ID, $input, Application::APP_ID . ':chatty-llm', $this->userId, $customId); $this->taskProcessingManager->scheduleTask($task); @@ -1067,7 +1067,7 @@ private function scheduleAgencyTask(string $content, int $confirmation, string $ ]; /** @psalm-suppress UndefinedClass */ if (isset($this->taskProcessingManager->getAvailableTaskTypes()[\OCP\TaskProcessing\TaskTypes\ContextAgentInteraction::ID]['optionalInputShape']['memories'])) { - $taskInput['memories'] = $this->sessionSummaryService->getUserSessionSummaries($this->userId); + $taskInput['memories'] = $this->sessionSummaryService->getMemories($this->userId); } /** @psalm-suppress UndefinedClass */ $task = new Task( @@ -1093,7 +1093,7 @@ private function scheduleAudioChatTask( ]; /** @psalm-suppress UndefinedClass */ if (isset($this->taskProcessingManager->getAvailableTaskTypes()[\OCP\TaskProcessing\TaskTypes\AudioToAudioChat::ID]['optionalInputShape']['memories'])) { - $input['memories'] = $this->sessionSummaryService->getUserSessionSummaries($this->userId); + $input['memories'] = $this->sessionSummaryService->getMemories($this->userId); } /** @psalm-suppress UndefinedClass */ $task = new Task( @@ -1119,7 +1119,7 @@ private function scheduleAgencyAudioTask( ]; /** @psalm-suppress UndefinedClass */ if (isset($this->taskProcessingManager->getAvailableTaskTypes()[\OCP\TaskProcessing\TaskTypes\ContextAgentAudioInteraction::ID]['optionalInputShape']['memories'])) { - $taskInput['memories'] = $this->sessionSummaryService->getUserSessionSummaries($this->userId); + $taskInput['memories'] = $this->sessionSummaryService->getMemories($this->userId); } /** @psalm-suppress UndefinedClass */ $task = new Task( diff --git a/lib/Service/SessionSummaryService.php b/lib/Service/SessionSummaryService.php index fd3b3f85..359f7ca7 100644 --- a/lib/Service/SessionSummaryService.php +++ b/lib/Service/SessionSummaryService.php @@ -9,11 +9,13 @@ namespace OCA\Assistant\Service; +use OCA\Assistant\AppInfo\Application; use OCA\Assistant\BackgroundJob\GenerateNewChatSummaries; use OCA\Assistant\BackgroundJob\RegenerateOutdatedChatSummariesJob; use OCA\Assistant\Db\ChattyLLM\MessageMapper; use OCA\Assistant\Db\ChattyLLM\Session; use OCA\Assistant\Db\ChattyLLM\SessionMapper; +use OCP\IAppConfig; use OCP\BackgroundJob\IJobList; use OCP\DB\Exception; use OCP\TaskProcessing\Task; @@ -34,6 +36,7 @@ public function __construct( private MessageMapper $messageMapper, private TaskProcessingService $taskProcessingService, private LoggerInterface $logger, + private IAppConfig $appConfig, private IJobList $jobList, ) { } @@ -105,4 +108,32 @@ public function getUserSessionSummaries(?string $userId): array { } } + /** + * returns all remembered chats as summaries where available and whole chats where not + * @return array + */ + public function getMemories(?string $userId): array { + $memories = []; + try { + $sessions = $this->sessionMapper->getRememberedUserSessions($userId, self::MAX_INJECTED_SUMMARIES); + foreach ($sessions as $session) { + if ($session->getSummary() !== null) { + $memories[] = $session->getSummary(); + + } + else { + $lastNMessages = intval($this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10')); + $chatHistory = $this->messageMapper->getMessages($session->getId(),0, $lastNMessages); + $memories[] = "This is the raw chat history of a chat between the user and Assistant: " . json_encode($chatHistory); + } + } + return $memories; + } catch (Exception $e) { + $this->logger->error('Failed to get remembered user sessions', ['exception' => $e]); + return []; + } + } + + + } From 198bc13f20e7ca2661c8c2ffb660fe850dac8f03 Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Fri, 23 Jan 2026 14:43:36 +0100 Subject: [PATCH 2/6] fix: update outdated summaries every 10 min Signed-off-by: Jana Peper --- lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php b/lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php index bc886b79..df1a8505 100644 --- a/lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php +++ b/lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php @@ -20,7 +20,7 @@ public function __construct( private SessionSummaryService $sessionSummaryService, ) { parent::__construct($timeFactory); - $this->setInterval(60 * 60 * 24); // 24h + $this->setInterval(60 * 10); // 10min } public function run($argument) { $userId = $argument['userId']; From 70d0a4344fc8ad6738dce23a471dcafb33200d07 Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Fri, 23 Jan 2026 15:08:05 +0100 Subject: [PATCH 3/6] feat: add chatlogs of outdated summaries and adjust summary prompt Signed-off-by: Jana Peper --- lib/Service/SessionSummaryService.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Service/SessionSummaryService.php b/lib/Service/SessionSummaryService.php index 359f7ca7..57b8816b 100644 --- a/lib/Service/SessionSummaryService.php +++ b/lib/Service/SessionSummaryService.php @@ -49,7 +49,7 @@ private function generateSummaries(array $sessions): void { array_shift($messages); } - $prompt = "Summarize insights about the user's circumstances, preferences and choices from the following conversation. Be as concise as possible. Do not add an introductory sentence or any other remarks.\n\n"; + $prompt = "Summarize insights about the user's circumstances, preferences and choices from the following conversation. Be as concise as possible. Especially mention any facts or numbers stated by the user. Do not add an introductory sentence or any other remarks.\n\n"; foreach ($messages as $message) { $prompt .= $message->getRole() . ': ' . $message->getContent() . "\n\n"; @@ -118,14 +118,20 @@ public function getMemories(?string $userId): array { $sessions = $this->sessionMapper->getRememberedUserSessions($userId, self::MAX_INJECTED_SUMMARIES); foreach ($sessions as $session) { if ($session->getSummary() !== null) { - $memories[] = $session->getSummary(); + $memory = $session->getSummary(); + if (!$session->getIsSummaryUpToDate()) { + $lastNMessages = intval($this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10')); + $chatHistory = $this->messageMapper->getMessages($session->getId(),0, $lastNMessages); + $memory .= "The summary is outdated. These are the last messages in the raw chat history: " . json_encode($chatHistory); + } } else { $lastNMessages = intval($this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10')); $chatHistory = $this->messageMapper->getMessages($session->getId(),0, $lastNMessages); - $memories[] = "This is the raw chat history of a chat between the user and Assistant: " . json_encode($chatHistory); + $memory = "This is the raw chat history of a chat between the user and Assistant: " . json_encode($chatHistory); } + $memories[] = $memory; } return $memories; } catch (Exception $e) { From 947b792253b9ef6bf133d78769a820cfd7213263 Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Fri, 23 Jan 2026 15:11:05 +0100 Subject: [PATCH 4/6] fix: cs fix Signed-off-by: Jana Peper --- lib/Service/SessionSummaryService.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Service/SessionSummaryService.php b/lib/Service/SessionSummaryService.php index 57b8816b..01bdff64 100644 --- a/lib/Service/SessionSummaryService.php +++ b/lib/Service/SessionSummaryService.php @@ -15,9 +15,9 @@ use OCA\Assistant\Db\ChattyLLM\MessageMapper; use OCA\Assistant\Db\ChattyLLM\Session; use OCA\Assistant\Db\ChattyLLM\SessionMapper; -use OCP\IAppConfig; use OCP\BackgroundJob\IJobList; use OCP\DB\Exception; +use OCP\IAppConfig; use OCP\TaskProcessing\Task; use OCP\TaskProcessing\TaskTypes\TextToText; use Psr\Log\LoggerInterface; @@ -121,15 +121,14 @@ public function getMemories(?string $userId): array { $memory = $session->getSummary(); if (!$session->getIsSummaryUpToDate()) { $lastNMessages = intval($this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10')); - $chatHistory = $this->messageMapper->getMessages($session->getId(),0, $lastNMessages); - $memory .= "The summary is outdated. These are the last messages in the raw chat history: " . json_encode($chatHistory); + $chatHistory = $this->messageMapper->getMessages($session->getId(), 0, $lastNMessages); + $memory .= 'The summary is outdated. These are the last messages in the raw chat history: ' . json_encode($chatHistory); } - } - else { + } else { $lastNMessages = intval($this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10')); - $chatHistory = $this->messageMapper->getMessages($session->getId(),0, $lastNMessages); - $memory = "This is the raw chat history of a chat between the user and Assistant: " . json_encode($chatHistory); + $chatHistory = $this->messageMapper->getMessages($session->getId(), 0, $lastNMessages); + $memory = 'This is the raw chat history of a chat between the user and Assistant: ' . json_encode($chatHistory); } $memories[] = $memory; } From 829e13f8956229d5e235b1d83f3138a1e7c18f9a Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Fri, 23 Jan 2026 15:31:52 +0100 Subject: [PATCH 5/6] fix(ui): hide settings part when no chat remembered Signed-off-by: Jana Peper --- src/components/PersonalSettings.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/PersonalSettings.vue b/src/components/PersonalSettings.vue index 5fd50c1d..be46d9ee 100644 --- a/src/components/PersonalSettings.vue +++ b/src/components/PersonalSettings.vue @@ -58,7 +58,7 @@ {{ taskNames.join(', ') }} -
+

{{ t('assistant', 'Remembered conversations') }}

{{ t('assistant', 'The following conversations are remembered by the Assistant Chat and will be taken into account for every new conversation:') }}

From 2412a3d5018a00e558aafc6a72d0ca94f6439994 Mon Sep 17 00:00:00 2001 From: janepie <49834966+janepie@users.noreply.github.com> Date: Mon, 26 Jan 2026 16:12:08 +0100 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Marcel Klehr Signed-off-by: janepie <49834966+janepie@users.noreply.github.com> Signed-off-by: Jana Peper --- lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php | 2 +- lib/Service/SessionSummaryService.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php b/lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php index df1a8505..a6aa392e 100644 --- a/lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php +++ b/lib/BackgroundJob/RegenerateOutdatedChatSummariesJob.php @@ -20,7 +20,7 @@ public function __construct( private SessionSummaryService $sessionSummaryService, ) { parent::__construct($timeFactory); - $this->setInterval(60 * 10); // 10min + $this->setInterval(60 * 60); // 1h } public function run($argument) { $userId = $argument['userId']; diff --git a/lib/Service/SessionSummaryService.php b/lib/Service/SessionSummaryService.php index 01bdff64..9631caba 100644 --- a/lib/Service/SessionSummaryService.php +++ b/lib/Service/SessionSummaryService.php @@ -110,7 +110,7 @@ public function getUserSessionSummaries(?string $userId): array { /** * returns all remembered chats as summaries where available and whole chats where not - * @return array + * @return list */ public function getMemories(?string $userId): array { $memories = []; @@ -118,7 +118,7 @@ public function getMemories(?string $userId): array { $sessions = $this->sessionMapper->getRememberedUserSessions($userId, self::MAX_INJECTED_SUMMARIES); foreach ($sessions as $session) { if ($session->getSummary() !== null) { - $memory = $session->getSummary(); + $memory = $session->getSummary() ?? ''; if (!$session->getIsSummaryUpToDate()) { $lastNMessages = intval($this->appConfig->getValueString(Application::APP_ID, 'chat_last_n_messages', '10')); $chatHistory = $this->messageMapper->getMessages($session->getId(), 0, $lastNMessages);