InvokeAgent - Amazon Bedrock

InvokeAgent

Sends a prompt for the agent to process and respond to.

Note

The AWS CLI doesn't support InvokeAgent.

  • To continue the same conversation with an agent, use the same sessionId value in the request.

  • To activate trace enablement, turn enableTrace to true. Trace enablement helps you follow the agent's reasoning process that led it to the information it processed, the actions it took, and the final result it yielded. For more information, see Trace enablement.

  • End a conversation by setting endSession to true.

  • Include attributes for the session or prompt in the sessionState object.

The response is returned in the bytes field of the chunk object.

  • The attribution object contains citations for parts of the response.

  • If you set enableTrace to true in the request, you can trace the agent's steps and reasoning process that led it to the response.

  • Errors are also surfaced in the response.

Request Syntax

POST /agents/agentId/agentAliases/agentAliasId/sessions/sessionId/text HTTP/1.1 Content-type: application/json { "enableTrace": boolean, "endSession": boolean, "inputText": "string", "sessionState": { "promptSessionAttributes": { "string" : "string" }, "sessionAttributes": { "string" : "string" } } }

URI Request Parameters

The request uses the following URI parameters.

agentAliasId

The alias of the agent to use.

Length Constraints: Minimum length of 0. Maximum length of 10.

Pattern: ^[0-9a-zA-Z]+$

Required: Yes

agentId

The unique identifier of the agent to use.

Length Constraints: Minimum length of 0. Maximum length of 10.

Pattern: ^[0-9a-zA-Z]+$

Required: Yes

sessionId

The unique identifier of the session. Use the same value across requests to continue the same conversation.

Length Constraints: Minimum length of 2. Maximum length of 100.

Pattern: ^[0-9a-zA-Z._:-]+$

Required: Yes

Request Body

The request accepts the following data in JSON format.

enableTrace

Specifies whether to turn on the trace or not to track the agent's reasoning process. For more information, see Trace enablement.

Type: Boolean

Required: No

endSession

Specifies whether to end the session with the agent or not.

Type: Boolean

Required: No

inputText

The prompt text to send the agent.

Type: String

Length Constraints: Minimum length of 0. Maximum length of 25000000.

Required: Yes

sessionState

Contains parameters that specify various attributes of the session. For more information, see Control session context.

Type: SessionState object

Required: No

Response Syntax

HTTP/1.1 200 x-amzn-bedrock-agent-content-type: contentType x-amz-bedrock-agent-session-id: sessionId Content-type: application/json { "accessDeniedException": { }, "badGatewayException": { }, "chunk": { "attribution": { "citations": [ { "generatedResponsePart": { "textResponsePart": { "span": { "end": number, "start": number }, "text": "string" } }, "retrievedReferences": [ { "content": { "text": "string" }, "location": { "s3Location": { "uri": "string" }, "type": "string" }, "metadata": { "string" : JSON value } } ] } ] }, "bytes": blob }, "conflictException": { }, "dependencyFailedException": { }, "internalServerException": { }, "resourceNotFoundException": { }, "serviceQuotaExceededException": { }, "throttlingException": { }, "trace": { "agentAliasId": "string", "agentId": "string", "sessionId": "string", "trace": { ... } }, "validationException": { } }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The response returns the following HTTP headers.

contentType

The MIME type of the input data in the request. The default value is application/json.

sessionId

The unique identifier of the session with the agent.

Length Constraints: Minimum length of 2. Maximum length of 100.

Pattern: ^[0-9a-zA-Z._:-]+$

The following data is returned in JSON format by the service.

accessDeniedException

The request is denied because of missing access permissions. Check your permissions and retry your request.

Type: Exception

HTTP Status Code: 403
badGatewayException

There was an issue with a dependency due to a server issue. Retry your request.

Type: Exception

HTTP Status Code: 502
chunk

Contains a part of an agent response and citations for it.

Type: PayloadPart object

conflictException

There was a conflict performing an operation. Resolve the conflict and retry your request.

Type: Exception

HTTP Status Code: 409
dependencyFailedException

There was an issue with a dependency. Check the resource configurations and retry the request.

Type: Exception

HTTP Status Code: 424
internalServerException

An internal server error occurred. Retry your request.

Type: Exception

HTTP Status Code: 500
resourceNotFoundException

The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.

Type: Exception

HTTP Status Code: 404
serviceQuotaExceededException

The number of requests exceeds the service quota. Resubmit your request later.

Type: Exception

HTTP Status Code: 400
throttlingException

The number of requests exceeds the limit. Resubmit your request later.

Type: Exception

HTTP Status Code: 429
trace

Contains information about the agent and session, alongside the agent's reasoning process and results from calling API actions and querying knowledge bases and metadata about the trace. You can use the trace to understand how the agent arrived at the response it provided the customer. For more information, see Trace events.

Type: TracePart object

validationException

Input validation failed. Check your request parameters and retry the request.

Type: Exception

HTTP Status Code: 400

Errors

For information about the errors that are common to all actions, see Common Errors.

AccessDeniedException

The request is denied because of missing access permissions. Check your permissions and retry your request.

HTTP Status Code: 403

BadGatewayException

There was an issue with a dependency due to a server issue. Retry your request.

HTTP Status Code: 502

ConflictException

There was a conflict performing an operation. Resolve the conflict and retry your request.

HTTP Status Code: 409

DependencyFailedException

There was an issue with a dependency. Check the resource configurations and retry the request.

HTTP Status Code: 424

InternalServerException

An internal server error occurred. Retry your request.

HTTP Status Code: 500

ResourceNotFoundException

The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.

HTTP Status Code: 404

ServiceQuotaExceededException

The number of requests exceeds the service quota. Resubmit your request later.

HTTP Status Code: 400

ThrottlingException

The number of requests exceeds the limit. Resubmit your request later.

HTTP Status Code: 429

ValidationException

Input validation failed. Check your request parameters and retry the request.

HTTP Status Code: 400

Examples

Example request

This example illustrates one usage of InvokeAgent.

POST https://bedrock-agent-runtime.us-east-1.amazonaws.com/agents/ABCDEFGHIJ/agentAliases/TSTALIASID/sessions/abb/text { "inputText": "can you show me the policy engine violation under his name from 10/10/2023 to 11/10/2023 ? My alias is adam@", "enableTrace": true, "endSession": false, "sessionState": { "sessionAttributes": { "key1": "val1", "key2": "val2" }, "promptSessionAttributes": { "key3": "val3", "key4": "val4" } } }

Example response

This example illustrates one usage of InvokeAgent.

HTTP/1.1 200 x-amzn-bedrock-agent-content-type: application/json x-amz-bedrock-agent-session-id: abb Content-type: application/json {payload}

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: