Skip to content

Conversation

@afarntrog
Copy link
Contributor

@afarntrog afarntrog commented Dec 1, 2025

Description

This pull request improves the robustness of session message history handling in the repository_session_manager by enhancing the logic for fixing broken tool use/result pairs and adding comprehensive tests for these scenarios. The changes ensure that message histories do not contain orphaned tool results, which could otherwise lead to invalid conversation states. Additionally, new tests are introduced to verify the correctness of the helper functions and the updated fixing logic.

Session message history fixes:

  • Enhanced the _fix_broken_tool_use method in repository_session_manager.py to remove orphaned toolResult messages at the start of the conversation and clarified the docstring to explain the handling of both orphaned toolUse and toolResult messages.
  • Fixed a typo in a comment within _fix_broken_tool_use for clarity.

Testing improvements:

  • Added new tests in test_repository_session_manager.py to verify that orphaned toolResult messages at the start are removed and that normal conversations are unaffected by the fixing logic.
  • Introduced a new test module test_tool_helpers.py with tests for the generate_missing_tool_result_content function, ensuring correct generation of missing tool results for various scenarios.

Related Issues

#1272

Documentation PR

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Dec 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@afarntrog afarntrog changed the title Add dummy toolUse message when its missing due to pagination in session management Remove toolResult message when toolUse is missing due to pagination in session management Dec 4, 2025
@afarntrog afarntrog enabled auto-merge (squash) December 4, 2025 22:01
@afarntrog afarntrog requested a review from bergjaak December 4, 2025 22:01
@afarntrog afarntrog merged commit 5ea97f9 into strands-agents:main Dec 4, 2025
14 checks passed
dbschmigelski pushed a commit to dbschmigelski/sdk-python that referenced this pull request Dec 9, 2025
…manager (strands-agents#1274)

* Remove toolUse message when its missing due to pagination in session manager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants