Hi Everyone ,
I am trying to invoke bedrock agent via below code from a Lambda function
def call_agent(input_data):
print("Invoking Agent")
client = boto3.client('bedrock-agent-runtime')
agent_arn = '<AGENT_ARN>'
# Call the Bedrock agent
agent_response = client.invoke_agent(
agentAliasId = '<AGENT_ALIAS>',
agentId = '<AGENT_ID>',
enableTrace = True,
inputText = input_data,
endSession = False,
sessionId = str(uuid.uuid4())
)
print("RAW Response :", agent_response)
if 'completion' not in agent_response:
raise ValueError("Missing 'completion' in agent response")
for event in agent_response['completion']:
if 'chunk' in event:
data = event['chunk']['bytes']
decoded_bytes = data.decode('utf8')
print('bytes: ', decoded_bytes)
message = message + decoded_byte
else:
raise ValueError("Missing 'chunk' in agent response")
return message
I am getting Missing 'chunk' in agent response
with any input . Can anyone help with why I am getting null
chunks ?
Below, I have shared the response of invokeAgent API
RAW Response : {'ResponseMetadata': {'RequestId': '2e0d0d4a-1b08-4531-8c55-8864bf387538', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Tue, 20 Aug 2024 06:16:42 GMT', 'content-type': 'application/json', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'x-amzn-requestid': '2e0d0d4a-1b08-4531-8c55-8864bf387538', 'x-amz-bedrock-agent-session-id': '399068f7-a518-40c7-97a3-db21c9b8ebb9', 'x-amzn-bedrock-agent-content-type': 'application/json'}, 'RetryAttempts': 0}, 'contentType': 'application/json', 'sessionId': '399068f7-a518-40c7-97a3-db21c9b8ebb9', 'completion': <botocore.eventstream.EventStream object at 0x7f5d93a74f80>}