Problem/Motivation

If a single Converse message contains multiple tool use requests, the following user message must contain a tool use response for each use call in the previous request. The responses cannot be broken up over multiple messages, which is what is currently happening and results in an exception.

Steps to reproduce

Invoke an agent that will call multiple tools as part of the same assistant message.
Get an exception stating that tool with an ID was expected to have a response in the next user message.

Proposed resolution

If tools are requested to be used together in one message, the next message must have content that fulfills both tool requests.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lpeabody created an issue. See original summary.

lpeabody’s picture

Priority: Normal » Major

Bumping to major since it can result in an exception that is not easy to trace.

lpeabody’s picture

Assigned: lpeabody » Unassigned
Status: Active » Needs review

I added an initial stab at grouping required tool responses into the next message. I don't think this is a great implementation FWIW. Not sure of a better way to go about it for now (I just needed to get it working).

mediabounds’s picture

StatusFileSize
new1.64 KB

I encountered the same issue (particularly when working with the Amazon Nova Pro model); I came up with a smaller patch that just assumes that if there are multiple tool messages in a row in the input that they should all be sent to amazon in one message.

This definitely feels like a hack and is simply working around the assumption made in the base AI module that a `ChatMessage` can only have one set of tool results.

mediabounds’s picture

StatusFileSize
new1.59 KB

Re-rolling my patch against the 1.1.x branch.

mediabounds’s picture

StatusFileSize
new1.65 KB

Fixing an issue in my previous patch where it could attempt to combine a tool response with an assistant response.

driskell’s picture

I get this too. Thanks for looking into a patch!

@mediabounds I think it’s safe to say if there’s multiple tool use together they can be merged. I can’t think of any case where a tool use response would appear consecutively if the previous assistant request(s) didn’t ask for multiple.

marcus_johansson’s picture

Status: Needs review » Reviewed & tested by the community

Sorry for not picking this up sooner, the MR looks good and it has been tested by a colleague of mine. Getting merged. Thank you everyone

marcus_johansson’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.