microsoft / autogen

A programming framework for agentic AI. Discord: https://aka.ms/autogen-dc. Roadmap: https://aka.ms/autogen-roadmap
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
27.96k stars 4.08k forks source link

Fixed alternating message role bug in Anthropic client #2992

Closed marklysze closed 1 week ago

marklysze commented 1 week ago

There was a bug that appeared in some workflows where a message role was not 'assistant' when it contained a 'tool_use' block. This isn't accepted by Anthropic and throws an exception.

This code has more robust alternating role management in the messages.

NOTE: There's still another outstanding issue when running two tools consecutively in the messages. This requires message merging and will be done in a separate PR.

Checks

codecov-commenter commented 1 week ago

Codecov Report

Attention: Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.

Project coverage is 15.47%. Comparing base (89c2f20) to head (e68d181). Report is 1 commits behind head on main.

Files Patch % Lines
autogen/oai/anthropic.py 0.00% 34 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2992 +/- ## =========================================== - Coverage 32.49% 15.47% -17.03% =========================================== Files 93 93 Lines 10097 10103 +6 Branches 2167 2170 +3 =========================================== - Hits 3281 1563 -1718 - Misses 6532 8485 +1953 + Partials 284 55 -229 ``` | [Flag](https://app.codecov.io/gh/microsoft/autogen/pull/2992/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/microsoft/autogen/pull/2992/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft) | `15.47% <0.00%> (-17.03%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=microsoft#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.