Handling LDP Agent incorrectly giving Message#1299
Merged
jamesbraza merged 3 commits intomainfrom Feb 22, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a critical bug where GPT 5.2 occasionally returns a plain Message object instead of the expected ToolRequestMessage, causing crashes when the code tries to access the tool_calls attribute. The fix implements defensive programming by handling both message types gracefully in the record_action method and the environment's step method.
Changes:
- Modified
record_actionmethod signature to accept bothMessageandToolRequestMessagetypes - Added runtime type checking in
record_actionto only append tool history when aToolRequestMessageis received - Added type guard in environment's
stepmethod to return a helpful error message when receiving a plainMessage
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/paperqa/agents/tools.py | Updated record_action signature to handle both Message and ToolRequestMessage, with conditional tool history tracking |
| src/paperqa/agents/env.py | Added type guard in step method to gracefully handle plain Message objects and return error response |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
39b2f20 to
1a1790a
Compare
whitead
approved these changes
Feb 21, 2026
915ecf6 to
fb232e5
Compare
b81a2a6 to
f3bda5f
Compare
f3bda5f to
188ff65
Compare
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.
We are seeing crashes due to GPT 5.2 occasionally giving a
Messageover aToolRequestMessage. Arguably we should fix this in LDP, but for now we can react here too: