Skip to content

Commit a357a9b

Browse files
committed
fix: append assistant messages
Signed-off-by: royalpinto007 <[email protected]>
1 parent c19da29 commit a357a9b

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

backend/director/core/reasoning.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@
6969
1. Provide an overview of the tasks completed by each agent, listing the actions taken and their outcomes.
7070
2. Exclude individual agent responses from the summary unless explicitly specified to include them.
7171
3. Ensure the summary is user-friendly, succinct and avoids technical jargon unless requested by the user.
72-
4. If there were any errors, incomplete tasks, or user confirmations required:
72+
4. Include the assistant's responses where relevant to provide context.
73+
5. If there were any errors, incomplete tasks, or user confirmations required:
7374
- Clearly mention the issue in the summary.
7475
- 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!"
75-
5. If the user seems dissatisfied or expresses unhappiness:
76+
6. If the user seems dissatisfied or expresses unhappiness:
7677
- Acknowledge their concerns in a respectful and empathetic tone.
7778
- Include the same invitation to reach out on Discord for further assistance.
78-
6. End the summary by inviting the user to ask further questions or clarify additional needs.
79+
7. End the summary by inviting the user to ask further questions or clarify additional needs.
7980
8081
"""
8182

@@ -291,15 +292,26 @@ def step(self):
291292
self.summary_content.text = llm_response.content
292293
self.summary_content.status = MsgStatus.success
293294
else:
294-
self.summary_content.text = (
295-
self.summary_content.text + llm_response.content
296-
if self.summary_content.text else llm_response.content
297-
)
295+
assistant_messages = []
296+
for message in self.session.reasoning_context:
297+
if message.role == RoleTypes.assistant and message.content:
298+
if isinstance(message.content, list):
299+
extracted_texts = [
300+
item["text"] if isinstance(item, dict) and "text" in item else str(item)
301+
for item in message.content
302+
]
303+
assistant_messages.append(" ".join(extracted_texts))
304+
else:
305+
assistant_messages.append(str(message.content))
306+
307+
summary_prompt = SUMMARIZATION_PROMPT.format(query=self.input_message.content)
308+
309+
if assistant_messages:
310+
summary_prompt += " Assistant Responses: " + " ".join(assistant_messages)
311+
298312
self.session.reasoning_context.append(
299313
ContextMessage(
300-
content=SUMMARIZATION_PROMPT.format(
301-
query=self.input_message.content
302-
),
314+
content=summary_prompt,
303315
role=RoleTypes.system,
304316
)
305317
)
@@ -310,11 +322,7 @@ def step(self):
310322
]
311323
)
312324
self.session.reasoning_context.pop()
313-
if summary_response.content not in self.summary_content.text:
314-
self.summary_content.text += (
315-
f"\n{summary_response.content}"
316-
if self.summary_content.text else summary_response.content
317-
)
325+
self.summary_content.text = summary_response.content
318326
if self.failed_agents:
319327
self.summary_content.status = MsgStatus.error
320328
else:

0 commit comments

Comments
 (0)