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 InvokeAgentCommand: agent does not invoke the action/lambda function #6506

Closed
3 of 4 tasks
fabiobeoni opened this issue Sep 23, 2024 · 3 comments
Closed
3 of 4 tasks
Assignees
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@fabiobeoni
Copy link

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

@fabiobeoni fabiobeoni added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 23, 2024
@zshzbh zshzbh self-assigned this Sep 23, 2024
@fabiobeoni
Copy link
Author

fabiobeoni commented Sep 24, 2024

I have also tried to let BedRock to create a default lambda function for the action described in the screenshot. BedRock created a python based lambda, I made it to just return a json array to be read by the model to create an answer with it.

In this case, I still have BedRock invoking the lambda only when testing the agent from AWS Console UI (I see lambda invocation logs from the agent). While instead I invoke the agent from code InvokeAgentCommand the agent skips invoking the lambda (I don't see any invocation logs)

@fabiobeoni
Copy link
Author

My fault guys.. there is no bug. I am sorry for not having figured out before.

Basically when you run your agent testing from AWS Console UI, by default you test the DRAFT version of the agent. While when you invoke the agent from code (lambda/webapp) using the AWS SDK you run the agent version specified in the agent alias. That's why I was having different results (agent working in AWS Console UI, not working on my app).

I solved by forcing an agent "prepare" (just after the creation), then an alias update targeting a new version.

After creating the new version and having the agent alias targeting it, the invocation of the agent from lambda does work as in the AWS Console UI.

Copy link

github-actions bot commented Oct 9, 2024

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 github-actions bot locked as resolved and limited conversation to collaborators Oct 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants