Skip to content

fix(cohere): allow parallel tool messages in message validation - #1022

Merged
njbrake merged 1 commit into
mainfrom
fix/cohere-agent-loop-tool-messages
Apr 13, 2026
Merged

fix(cohere): allow parallel tool messages in message validation#1022
njbrake merged 1 commit into
mainfrom
fix/cohere-agent-loop-tool-messages

Conversation

@njbrake

@njbrake njbrake commented Apr 13, 2026

Copy link
Copy Markdown
Member

Summary

  • The _patch_messages() validation in the Cohere provider only checked if the immediately preceding message was an assistant, but with parallel tool calls multiple tool result messages follow a single assistant message. The second tool message's predecessor is another tool message, not the assistant, causing a ValueError.
  • Fixed by walking backwards past sibling tool messages to find the originating assistant message.
  • Added unit tests for parallel tool message sequences (both valid and invalid).

Fixes failing integration tests:

  • test_agent_loop_parallel_tool_calls[cohere]
  • test_agent_loop_sequential_tool_calls[cohere]

Regression introduced in #1013.

Test plan

  • Existing unit tests pass (18/18)
  • Pre-commit checks pass
  • Integration tests pass for cohere provider

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

The _patch_messages validation only checked if the immediately preceding
message was an assistant, causing failures when multiple tool result
messages follow a single assistant message with parallel tool calls.
Walk backwards past sibling tool messages to find the originating
assistant message instead.

Fixes agent loop integration tests for cohere provider.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@njbrake
njbrake temporarily deployed to integration-tests April 13, 2026 10:23 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ PR Template Missing

This PR appears to be missing the required checklist from the PR template.

Please edit your PR description to include the checklist section. The checklist helps maintainers review your contribution.

This PR will be automatically closed in 24 hours if the template is not restored.

If you're using an AI coding tool, please ensure it preserves the PR template.

@github-actions github-actions Bot added the missing-template PR is missing required template checklist label Apr 13, 2026
@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/any_llm/providers/cohere/utils.py 55.69% <100.00%> (+1.74%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@njbrake
njbrake merged commit d72ca02 into main Apr 13, 2026
11 of 12 checks passed
@njbrake
njbrake deleted the fix/cohere-agent-loop-tool-messages branch April 13, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-template PR is missing required template checklist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant