Null/Empty Chunks while invoking an agent

0

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>}
1 Answer
0

Hi,

To better understand your issue, you may want to trace the request to the LLM to see which chunks of content from the RAG database were given to the LLM.

See my article to see how to trace those LLM calls: https://repost.aws/articles/AR-LV1HoR_S0m-qy89wXwHmw/the-leverage-of-llm-system-prompt-by-knowledge-bases-for-bedrock-in-rag-workflows

Best,

Didier

profile pictureAWS
EXPERT
answered 23 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions