Add handling of missing tool calls/tool call responses#172
Open
akavi wants to merge 1 commit intoakavi/websocket-providersfrom
Open
Add handling of missing tool calls/tool call responses#172akavi wants to merge 1 commit intoakavi/websocket-providersfrom
akavi wants to merge 1 commit intoakavi/websocket-providersfrom
Conversation
285e6ef to
e75eba1
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
e75eba1 to
fa9635f
Compare
sauhardjain
reviewed
Mar 10, 2026
sauhardjain
approved these changes
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Bug report from Balto
LlmProviderto correctly handle unpaired tool_call/tool_call_responsea) LlmAgent is about maintaining the state of the agent, LlmProvider is about wrapping the Llm conversation API in a consistent interface
Based off of #159 since that does a bunch of rework of the
LlmProvidercode, and I'd rather not deal with the rebase mess.Type of change
Testing
Unit tests
Checklist
make formatNote
Medium Risk
Changes the pre-flight normalization for every LLM chat call (message filtering, terminal validation, and tool-call pairing), which could alter conversation history and tool execution in edge cases despite being defensive.
Overview
Centralizes message validation in
LlmProviderby adding_normalize_messagesand applying it inLlmProvider.chat, returning an empty stream when the conversation is empty/invalid.Normalization now filters empty user/assistant messages, removes unpaired
tool_callsand orphaned tool responses, and enforces terminal-message rules (can’t end on assistant; last user message must be non-empty), replacing the earlier skip logic previously done inLlmAgent.LlmAgentno longer pre-validates message sequences before calling the provider, and_build_messagesnow preserves emptyUserTextSent/AgentTextSentcontents (as"") for the provider to handle.Written by Cursor Bugbot for commit fa9635f. This will update automatically on new commits. Configure here.