fix attempt double message add

This commit is contained in:
marko-kraemer 2025-03-31 20:30:32 -07:00
parent 486f11ba77
commit 110df43921
2 changed files with 18 additions and 18 deletions

View File

@ -133,19 +133,11 @@ class LLMResponseProcessor:
if self.tool_calls_accumulated: if self.tool_calls_accumulated:
message["tool_calls"] = self.tool_calls_accumulated message["tool_calls"] = self.tool_calls_accumulated
if not hasattr(self, '_message_added'): await self.results_adder.update_response(
await self.results_adder.add_initial_response( self.thread_id,
self.thread_id, self.content_buffer,
self.content_buffer, self.tool_calls_accumulated
self.tool_calls_accumulated )
)
self._message_added = True
else:
await self.results_adder.update_response(
self.thread_id,
self.content_buffer,
self.tool_calls_accumulated
)
# Handle stream completion # Handle stream completion
if chunk.choices[0].finish_reason: if chunk.choices[0].finish_reason:

View File

@ -55,15 +55,23 @@ class XMLResultsAdder(ResultsAdderBase):
- Creates initial message if none exists - Creates initial message if none exists
- Preserves XML structure in updates - Preserves XML structure in updates
""" """
if not self.message_added:
await self.add_initial_response(thread_id, content, tool_calls)
return
message = { message = {
"role": "assistant", "role": "assistant",
"content": content "content": content
} }
await self.update_message(thread_id, message)
# Check if an assistant message already exists in the thread
existing_messages = await self.get_messages(thread_id)
assistant_msg = next((msg for msg in reversed(existing_messages)
if msg['role'] == 'assistant'), None)
if assistant_msg:
# Update existing message
await self.update_message(thread_id, message)
else:
# Add new message
await self.add_message(thread_id, message)
self.message_added = True
async def add_tool_result(self, thread_id: str, result: Dict[str, Any]): async def add_tool_result(self, thread_id: str, result: Dict[str, Any]):
"""Add XML tool result with proper referencing. """Add XML tool result with proper referencing.