Skip to content

Bedrock InvokeAgentCommand: agent does not invoke the action/lambda function #6506

@fabiobeoni

Description

@fabiobeoni

Checkboxes for prior research

Describe the bug

Hi guys,

I have a lambda function chat_ask_bot_fnc that runs InvokeAgentCommand (as for the example code from docs https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javascriptv3/example_code/bedrock-agent-runtime/actions/invoke-agent.js):

....

const command = new InvokeAgentCommand({
    agentId,
    agentAliasId,
    sessionId,
    inputText: prompt,
  });

const response = await client.send(command);

...

The agent is configured to invoke the action-group/lambda query-pm-values-fnc (to get data from dynamo):

Screenshot from 2024-09-23 17-38-10

I see the agent response in logs from lambda chat_ask_bot_fnc returned by await client.send(command):

>> Agent response:
{
  '$metadata': {
    httpStatusCode: 200,
    requestId: '761e6612-8325-41fc-9a98-1bb584121d32',
    extendedRequestId: undefined,
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  contentType: 'application/json',
  sessionId: '12345',
  completion: SmithyMessageDecoderStream {
    options: {
      messageStream: [MessageDecoderStream],
      deserializer: [AsyncFunction (anonymous)]
    }
  }
}

... and the agent response.completion "I attempted to retrieve the latest pollution data but was unable to due to an error with the function call format"

So looks like the agent called the query-pm-values-fnc as required, but I don't have any invocation log stream for that function. So to me the Agent actually did not invoke the action/lambda.

Also, when I test the agent from AWS Console the test goes well. The agent invokes the query-pm-values-fnc and returns the answer with the values from the query.

My understanding of the issue is that there is somethings wrong with the InvokeAgentCommand execution, since the agent thinks he has invoked the action/lambda, while it did not.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

nodejs 20

Reproduction Steps

Included above...

Observed Behavior

Agent response.completion "I attempted to retrieve the latest pollution data but was unable to due to an error with the function call format".

Registered action/lambda is actually not called.

Expected Behavior

Agent response.completion contains data from the result of the invoked lambda.

Lambda should be invoked.

Possible Solution

No response

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions