aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Bedrock Agent Runtime - InvokeAgentCommand documentation missing for Multi-agent collaboration

Open PavaniKa opened this issue 11 months ago • 10 comments

Describe the issue

The InvokeAgentCommand documentation & Example Syntax is missing the required configuration/parameters for Multi-agent collaboration scenario. With ReturnControl feature, the Agent (without collaboration) is working as expected, but the Agent in Supervisor mode is throwing below error:

ValidationException: Validation failed: Unexpected actionGroup: action-group-XXXX or function : get_XXXX_data encountered for invocationId: f8b89c79-19b7-4b1d-ab08-bdfc3bde284d

So I looked at the InvokeAgentResponse in the Example Syntax, added the agentCollaboratorName parameter. Now it just calls the same ReturnControl function in a loop.

Links

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-agent-runtime/command/InvokeAgentCommand/

PavaniKa avatar Jan 22 '25 21:01 PavaniKa

Hi @PavaniKa - thanks for reaching out.

According to the error, it seems like the action-group being used for multi-agent is invalid. Can you share the steps you followed along with your code snippet for further guidance?

You can also follow this service docs for working with multi-agent collaboration: https://docs.aws.amazon.com/bedrock/latest/userguide/create-multi-agent-collaboration.html

Best, John

aBurmeseDev avatar Jan 23 '25 04:01 aBurmeseDev

Sure. Here is the scenario. I have two agents Agent1, Agent2. Both have Action Groups with invocation set as Return control. Both are working as expected (with the code below) from my node.js app.

I created a new SuperAgent, enabled Multi-Agent Collaboration in it & configured Agent1, Agent2 as collaborators. When invoked, control is returned as expected and corresponding function is called. Below Error is thrown when the final response is sent back:

ValidationException: Validation failed: Unexpected actionGroup: action-group-XXXX or function : get_XXXX_data encountered for invocationId: f8b89c79-19b7-4b1d-ab08-bdfc3bde284d

Please note, these are valid actionGroup, function combination in one of the collaborator agent(s).

Here is the code block. Only difference between SuperAgent and normal agent invocations is the BEDROCK_AGENT_ID, BEDROCK_AGENT_ALIAS_ID values.

const BEDROCK_AGENT_ID = process.env.BEDROCK_AGENT_ID;
const BEDROCK_AGENT_ALIAS_ID = process.env.BEDROCK_AGENT_ALIAS_ID;

async function __invokeBedrockAgent(agentPayload, returnControlData, apiResponse) {
    const bedrockClient = agentPayload.client;

    const invocationId = returnControlData.invocationId;
    const functionInvocationInput = returnControlData.invocationInputs[0].functionInvocationInput;

    const actionGroup = functionInvocationInput.actionGroup;
    const functionName = functionInvocationInput.function;

    const responseBody = {
        TEXT: {
            body: JSON.stringify(apiResponse), //JSON response from API
        }
    };

    const inputPayload = {
        agentId: BEDROCK_AGENT_ID, //required
        agentAliasId: BEDROCK_AGENT_ALIAS_ID, //required
        sessionId: agentPayload.sessionId, //required
        endSession: false, //this will make sure the Agent remembers the state
        inputText: agentPayload.inputText, // this will be ignored if there is a session state
        sessionState: {
            invocationId: invocationId, //required
            returnControlInvocationResults: [
                {
                    functionResult: {
                        actionGroup: actionGroup,
                        function: functionName,
                        responseBody: responseBody,
                        responseState: 'REPROMPT', //this can be 'REPROMPT' or 'COMPLETED' or 'FAILED'
                    },
                },
            ],
        }
    };

    try {
        console.log(">>> Bedrock Agent Input Payload: ", inputPayload);
        const command = new InvokeAgentCommand(inputPayload);

        let completion = "";
        //send the command
        console.log(">>> Sending Command to Bedrock Agent...");
        const response = await bedrockClient.send(command);

        if (response.completion === undefined) {
            throw new Error("Completion is undefined");
        }

        //process the response
        const readable = response.completion;

        for await (const event of readable) {
            console.log(">>> Processing Event...");
            completion = await processEvent(event, agentPayload);
        }

        return completion;
    } catch (err) {
        console.error(err, err.stack);
        throw new Error(err.stack);
    }
};

PavaniKa avatar Jan 23 '25 12:01 PavaniKa

Thanks for sharing your use case. I reached out to service team, on your behalf, to review it and provide guidance (ref: P192976310). I'll update here when I hear back.

aBurmeseDev avatar Jan 24 '25 02:01 aBurmeseDev

Here's response from service and request for verification:

with MulitAgent collaboration using ROC, can customer check if they are providing the correct agentId in the ReturnControlInvocationResult payloads? Each ROC InvocationInput payload has a agentId that is required for bedrockAgents to route request to the correct agent in multi-agent set-up.

Reference boto3 payload

aBurmeseDev avatar Feb 18 '25 19:02 aBurmeseDev

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] avatar Mar 01 '25 00:03 github-actions[bot]

Thanks for the update.

Doesn't that defeat the purpose of a 'Supervisor' Agent If we are controlling the route by including agentId of a Collaborator Agent in the InvocationInput payload?

PavaniKa avatar Mar 03 '25 12:03 PavaniKa

@aBurmeseDev Considering the above case , can i get the respective outputs from agent 1 and agent 2 individually from the super agent If we use BEDROCK_AGENT_ID, BEDROCK_AGENT_ALIAS_ID values of superagent

aruns05 avatar Mar 24 '25 07:03 aruns05

Hey all - I'll have to relay your concerns back to service team and wait for their response. I'll keep it posted.

aBurmeseDev avatar Mar 24 '25 23:03 aBurmeseDev

Thanks @aBurmeseDev will wait for you as the above question is critical for me. Please let this thread stay open until then

aruns05 avatar Mar 25 '25 08:03 aruns05

I had the same issue, adding the agentId to the functionInvocationInput fixed the problem @PavaniKa https://docs.aws.amazon.com/bedrock/latest/userguide/agents-returncontrol.html

medelling24 avatar Apr 04 '25 06:04 medelling24

Although I haven't heard back from service team, I was able to confirm the finding above. Let me know if you have any other questions @PavaniKa

aBurmeseDev avatar Jun 26 '25 07:06 aBurmeseDev

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

github-actions[bot] avatar Jul 15 '25 00:07 github-actions[bot]