From c19da2936a22bac23e09662b5a0748b089282317 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Thu, 20 Mar 2025 16:46:49 +0530 Subject: [PATCH 1/3] fix: final cut summary Signed-off-by: royalpinto007 --- backend/director/core/reasoning.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/director/core/reasoning.py b/backend/director/core/reasoning.py index 79eae6d2..dbd03eca 100644 --- a/backend/director/core/reasoning.py +++ b/backend/director/core/reasoning.py @@ -291,6 +291,10 @@ def step(self): self.summary_content.text = llm_response.content self.summary_content.status = MsgStatus.success else: + self.summary_content.text = ( + self.summary_content.text + llm_response.content + if self.summary_content.text else llm_response.content + ) self.session.reasoning_context.append( ContextMessage( content=SUMMARIZATION_PROMPT.format( @@ -306,7 +310,11 @@ def step(self): ] ) self.session.reasoning_context.pop() - self.summary_content.text = summary_response.content + if summary_response.content not in self.summary_content.text: + self.summary_content.text += ( + f"\n{summary_response.content}" + if self.summary_content.text else summary_response.content + ) if self.failed_agents: self.summary_content.status = MsgStatus.error else: From a357a9b6ffc996837034c72f38d780f9ccac1853 Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Fri, 21 Mar 2025 15:49:56 +0530 Subject: [PATCH 2/3] fix: append assistant messages Signed-off-by: royalpinto007 --- backend/director/core/reasoning.py | 38 ++++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/backend/director/core/reasoning.py b/backend/director/core/reasoning.py index dbd03eca..56e2fdf9 100644 --- a/backend/director/core/reasoning.py +++ b/backend/director/core/reasoning.py @@ -69,13 +69,14 @@ 1. Provide an overview of the tasks completed by each agent, listing the actions taken and their outcomes. 2. Exclude individual agent responses from the summary unless explicitly specified to include them. 3. Ensure the summary is user-friendly, succinct and avoids technical jargon unless requested by the user. -4. If there were any errors, incomplete tasks, or user confirmations required: +4. Include the assistant's responses where relevant to provide context. +5. If there were any errors, incomplete tasks, or user confirmations required: - Clearly mention the issue in the summary. - Politely inform the user: "If you encountered any issues or have further questions, please don't hesitate to reach out to our team on [Discord](https://discord.com/invite/py9P639jGz). We're here to help!" -5. If the user seems dissatisfied or expresses unhappiness: +6. If the user seems dissatisfied or expresses unhappiness: - Acknowledge their concerns in a respectful and empathetic tone. - Include the same invitation to reach out on Discord for further assistance. -6. End the summary by inviting the user to ask further questions or clarify additional needs. +7. End the summary by inviting the user to ask further questions or clarify additional needs. """ @@ -291,15 +292,26 @@ def step(self): self.summary_content.text = llm_response.content self.summary_content.status = MsgStatus.success else: - self.summary_content.text = ( - self.summary_content.text + llm_response.content - if self.summary_content.text else llm_response.content - ) + assistant_messages = [] + for message in self.session.reasoning_context: + if message.role == RoleTypes.assistant and message.content: + if isinstance(message.content, list): + extracted_texts = [ + item["text"] if isinstance(item, dict) and "text" in item else str(item) + for item in message.content + ] + assistant_messages.append(" ".join(extracted_texts)) + else: + assistant_messages.append(str(message.content)) + + summary_prompt = SUMMARIZATION_PROMPT.format(query=self.input_message.content) + + if assistant_messages: + summary_prompt += " Assistant Responses: " + " ".join(assistant_messages) + self.session.reasoning_context.append( ContextMessage( - content=SUMMARIZATION_PROMPT.format( - query=self.input_message.content - ), + content=summary_prompt, role=RoleTypes.system, ) ) @@ -310,11 +322,7 @@ def step(self): ] ) self.session.reasoning_context.pop() - if summary_response.content not in self.summary_content.text: - self.summary_content.text += ( - f"\n{summary_response.content}" - if self.summary_content.text else summary_response.content - ) + self.summary_content.text = summary_response.content if self.failed_agents: self.summary_content.status = MsgStatus.error else: From 77ecd6d1d2e8f866ec40fd62b2c1be1f2918791a Mon Sep 17 00:00:00 2001 From: royalpinto007 Date: Fri, 21 Mar 2025 19:04:37 +0530 Subject: [PATCH 3/3] fix: unnecessary assistant response header Signed-off-by: royalpinto007 --- backend/director/core/reasoning.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/director/core/reasoning.py b/backend/director/core/reasoning.py index 56e2fdf9..45344c19 100644 --- a/backend/director/core/reasoning.py +++ b/backend/director/core/reasoning.py @@ -297,17 +297,21 @@ def step(self): if message.role == RoleTypes.assistant and message.content: if isinstance(message.content, list): extracted_texts = [ - item["text"] if isinstance(item, dict) and "text" in item else str(item) + item["text"] + if isinstance(item, dict) and "text" in item + else str(item) for item in message.content ] assistant_messages.append(" ".join(extracted_texts)) else: assistant_messages.append(str(message.content)) - summary_prompt = SUMMARIZATION_PROMPT.format(query=self.input_message.content) + summary_prompt = SUMMARIZATION_PROMPT.format( + query=self.input_message.content + ) if assistant_messages: - summary_prompt += " Assistant Responses: " + " ".join(assistant_messages) + summary_prompt += " ".join(assistant_messages) self.session.reasoning_context.append( ContextMessage(