-
Notifications
You must be signed in to change notification settings - Fork 597
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
InvokeAgentCommand doesn't return chunk #6519
Comments
Hey @davidgamify , Sorry to hear that you have this issue. I confirm that I can reproduce this issue. By looking at the InvokeAgentCommand Output definition, the type for the completion field is an asyncIterator object. Async iterators are similar to iterators but in this case the iteration is done over asynchronous values. You can also check the type of this field in the IDE. In python boto3 pkg, the So, one way we could process the data retrieved is by using a for await loop, just like what you provided. please let me know if you have any other questions! :) Thanks! |
Posting my reproduction code for import {
BedrockAgentRuntimeClient,
InvokeAgentCommand,
} from "@aws-sdk/client-bedrock-agent-runtime";
/**
* @typedef {Object} ResponseBody
* @property {string} completion
*/
/**
* Invokes a Bedrock agent to run an inference using the input
* provided in the request body.
*
* @param {string} prompt - The prompt that you want the Agent to complete.
* @param {string} sessionId - An arbitrary identifier for the session.
*/
export const invokeBedrockAgent = async (prompt, sessionId) => {
const client = new BedrockAgentRuntimeClient({ region: "us-east-1" });
const agentId = "XXXX";
const agentAliasId = "XXXX";
const command = new InvokeAgentCommand({
agentId,
agentAliasId,
sessionId: "123",
inputText: "prompt",
});
try {
let completion = "";
const response = await client.send(command);
console.log("res",response)
console.log("response",response.completion)
if (response.completion === undefined) {
throw new Error("Completion is undefined");
}
console.log(response.completion);
for await (let chunkEvent of response.completion) {
const chunk = chunkEvent.chunk;
console.log(chunk);
const decodedResponse = new TextDecoder("utf-8").decode(chunk.bytes);
completion += decodedResponse;
}
return { sessionId: sessionId, completion };
} catch (err) {
console.error(err);
}
};
// Call function if run directly
import { fileURLToPath } from "url";
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const result = await invokeBedrockAgent("I need help.", "123");
console.log(result);
} Result :
|
Thanks @zshzbh - I am completely blocked by this issue. Hopefully, someone can come up with a resolution soon. I see it's a p2, so hopefully, it'll get attention soon. |
Hey @davidgamify , Could you please help me understand why this is a blocker for you as you can get |
@zshzbh - Because I don't get the chunk in the for await loop. I never get the chunk. Here's the output I get:
|
Hey @davidgamify , I just realized that you are using react native. In this case, you have to install polyfills (ref) - If you are consuming modular AWS SDK for JavaScript on react-native environments, you will need to add and import following polyfills in your react-native application: react-native-get-random-values import "react-native-get-random-values";
import "react-native-url-polyfill/auto";
import "web-streams-polyfill/dist/polyfill";
import { DynamoDB } from "@aws-sdk/client-dynamodb"; Specifically Metro bundler used by react-native, enable Package Exports Support: https://metrobundler.dev/docs/package-exports/ Could you please confirm you have installed the required polyfills? If not, could you please install those and rebuild the app and try again? Thanks! |
I do have the polyfills and the get-random-values. I couldn't enable Package Exports Support as, when I did, axios wouldn't work. I'm trying to figure out the axios issue now. |
I couldn't figure out the Axios issue. Unfortunately, I can't seem to get Axios to work when I enable Package Exports Support. |
Is there anyway that you can use other artifacts instead of axios? If the issue persists, could you please send us the code with Axios so I can try to reproduce and troubleshoot on my end. Thanks~! |
Checkboxes for prior research
Describe the bug
When I call the InvokeAgentCommand send function, I receive a response, but the response doesn't include the chunk. When I use the same parameters in python3 (boto3), I get chunk in the result.
Regression Issue
SDK version number
"@aws-sdk/client-bedrock-agent-runtime": "^3.658.0"
Which JavaScript Runtime is this issue in?
React Native
Details of the browser/Node.js/ReactNative version
v22.7.0
Reproduction Steps
Observed Behavior
!!!response in log =
Expected Behavior
I would expect response to look like:
Possible Solution
No response
Additional Information/Context
No response
The text was updated successfully, but these errors were encountered: