Skip to content

fix(python): ignore empty tool messages#1455

Open
pragnyanramtha wants to merge 2 commits into
i-am-bee:mainfrom
pragnyanramtha:codex/ignore-empty-tool-messages
Open

fix(python): ignore empty tool messages#1455
pragnyanramtha wants to merge 2 commits into
i-am-bee:mainfrom
pragnyanramtha:codex/ignore-empty-tool-messages

Conversation

@pragnyanramtha
Copy link
Copy Markdown

@pragnyanramtha pragnyanramtha commented May 17, 2026

Summary

  • avoid indexing the first tool result while scanning memory for the last tool call/response pair
  • use the last tool call from a multi-tool assistant message when selecting the matching tool response
  • ignore empty or unrelated tool messages instead of raising IndexError
  • add regression coverage for matching tool responses, empty tool messages, and multi-tool assistant messages

Validation

  • uv run --with pytest --with syrupy pytest tests/memory/test_utils.py -q -> 3 passed; emitted local warnings for an unknown asyncio config option and PyCharm diff patching
  • uv run --with ruff ruff check beeai_framework/memory/utils.py tests/memory/test_utils.py
  • uv run --with ruff ruff format --check beeai_framework/memory/utils.py tests/memory/test_utils.py
  • git diff --check

Notes

The commits include DCO signoffs as required by the Python contributing guide.

Signed-off-by: pragnyanramtha <pragnyanramtha@gmail.com>
@pragnyanramtha pragnyanramtha requested a review from a team as a code owner May 17, 2026 04:39
Copilot AI review requested due to automatic review settings May 17, 2026 04:39
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 17, 2026
@github-actions github-actions Bot added the python Python related functionality label May 17, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the extract_last_tool_call_pair utility to more robustly identify matching tool responses by checking all results within a ToolMessage using any(). It also introduces unit tests to verify matching logic and the handling of empty tool messages. Review feedback suggests using the last tool call ID from the AssistantMessage to ensure the most recent interaction is captured and recommends optimizing the search loop by iterating over msg.content directly to reduce overhead.

Comment thread python/beeai_framework/memory/utils.py Outdated
Comment thread python/beeai_framework/memory/utils.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Signed-off-by: pragnyanramtha <pragnyanramtha@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Python related functionality size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants