By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How to find sessionId for a Bedrock Agent?

0

For an API connection I need the sessionID. I found the AgentID & AliasID, but where do you find the sessionID in AWS Bedrock?

Thanks in advance!

1 Answer
0

Hello.

In case of "RetrieveAndGenerate" API, "sessionId" is included in the response.
The first time you execute the "RetrieveAndGenerate" API, make the request without including the "sessionId" From the second time onward, include the "sessionId" received in the response as a parameter in your request, allowing you to continue the session for subsequent responses.
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_RetrieveAndGenerate.html#API_agent-runtime_RetrieveAndGenerate_ResponseSyntax

For "invoke_agent", please reuse any string.
In other words, as long as the ID is unique, there is no problem.
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-agent-runtime/client/invoke_agent.html

In the case of "invoke_agent", I think the code from the blog below will be helpful.
In the blog code below, "session_id" is created on line 86 of the code.
https://community.aws/content/2g8NsQl8CvJhxQ0635HKkg6hMga/agents-for-amazon-bedrock-handling-return-of-control-in-code

session_id = ''.join(random.choices(string.ascii_uppercase + string.digits, k=SESSION_ID_LENGTH))
profile picture
EXPERT
answered a month ago
profile pictureAWS
EXPERT
reviewed a month 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