Skip to content

Amazon Bedrock Agent - Get All Messages for a given SessionId

0

Is there a way I can get all the messages send by the User and answered by the LLM Agent using some API call or Bedrock functionality? Something like: {"user":"hello","agent":"hello, how are you today?","user":...}

If not, what do you do to achieve that?

I'm building an AI english tutor for my application and I want to save the previous conversations on a S3 Bucket for further reuse in my model context and RAG base, but the only way I thought of doing it was saving every message for every interaction in a python list and then sending it as json to a storage, with the sessionId as the filename.

I was used to call OpenAI Assistant functions which had a 'retrieve messages' endpoint where you just put the interaction id and got all the messages from it.

Any help would be appreciated.

asked 2 years ago465 views
1 Answer
1

From what I know, Bedrock doesn't provide direct API to retrieve messages for a given sessionId.

A possibility would be to try and go for manual storage. In your application, store every message exchanged between the user and the LLM agent in an S3 bucket using python. Serialize the messages you collect into JSON format and save them to the S3 with the SessionId as the filename.

import json
import boto3

s3_client = boto3.client('s3')

def save_conversation_to_s3(session_id, conversation):
    # Convert conversation to JSON
    json_data = json.dumps(conversation)
    
    # Save to S3
    s3_client.put_object(
        Bucket='your-bucket-name',
        Key=f'{session_id}.json',
        Body=json_data,
        ContentType='application/json'
    )

Maybe if enough people post about this, Bedrock will offer a built-in method to retrieve messages for a session directly.

answered 2 years 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.