Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The tool calls were not used correctly, since the loop was not considering the tool calls generated between steps. This PR moves the multistep loop so that all tool calls are used.
AI Description
The PR makes changes to the chat functionality, specifically to the handling of tool calls and the chat stream.
src/backend/chat/custom/custom.py
chat
function has been modified to remove theshould_break
variable and associated logic. Now, the loop iterates until there are no new tool calls.call_chat
function has been updated to include a loop that invokes the chat stream and checks for new tool calls. If there are no new tool calls, the loop exits.has_new_tool_calls
function has been added to check if the last element in thechat_history
list has tool calls.update_chat_history_with_tool_results
function has been introduced to update the chat history with tool results.call_tools
function has been modified to check for the presence of"tool_calls"
in the last element of thechat_history
list instead of checking fortool_results
.src/backend/schemas/chat.py
ChatMessage
class now includes adefault=None
value for themessage
field.to_dict
method of theChatMessage
class has been updated to include"tool_results"
and"tool_calls"
in the returned dictionary.StreamEnd
class now includes achat_history
field with a default value ofNone
.finish_reason
field of theStreamEnd
class has been updated to include an extra set of parentheses.error
field has been added to theStreamEnd
class with a default value ofNone
.src/backend/services/chat.py
to_dict
function has been imported frombackend.chat.collate
.handle_stream_end
function now includes the chat history in thestream_end_data
dictionary by converting the event to a dictionary and accessing the"response"
and"chat_history"
fields.