Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PavaniKa opened this issue Jan 22, 2025 · 3 comments
Assignees
Labels
documentation This is a problem with documentation. p3 This is a minor priority issue service-api This issue is due to a problem in a service API, not the SDK implementation.

Comments

@PavaniKa
Copy link

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 PavaniKa added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Jan 22, 2025
@aBurmeseDev aBurmeseDev self-assigned this Jan 23, 2025
@aBurmeseDev
Copy link
Member

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 aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jan 23, 2025
@PavaniKa
Copy link
Author

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);
    }
};

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jan 24, 2025
@aBurmeseDev
Copy link
Member

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 aBurmeseDev added the service-api This issue is due to a problem in a service API, not the SDK implementation. label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation. p3 This is a minor priority issue service-api This issue is due to a problem in a service API, not the SDK implementation.
Projects
None yet
Development

No branches or pull requests

2 participants