View a markdown version of this page

AgenticRetrieveStream - Amazon Bedrock

AgenticRetrieveStream

Retrieves information from one or more knowledge bases using an agentic approach. Agentic retrieval uses a foundation model to intelligently decompose complex queries into sub-queries and iteratively retrieve relevant information from your knowledge bases. This approach improves retrieval accuracy for complex, multi-step questions that a single retrieval pass might not fully address.

The operation returns results through a stream that includes retrieval results, trace events for visibility into the process, and a generated response synthesized from the results by default, which can be turned off.

Request Syntax

POST /agenticRetrieveStream HTTP/1.1 Content-type: application/json { "agenticRetrieveConfiguration": { "foundationModelConfiguration": { "bedrockFoundationModelConfiguration": { "modelConfiguration": { "modelArn": "string" } }, "type": "string" }, "foundationModelType": "string", "maxAgentIteration": number, "rerankingConfiguration": { "bedrockRerankingConfiguration": { "modelConfiguration": { "modelArn": "string" } }, "type": "string" }, "rerankingModelType": "string" }, "generateResponse": boolean, "messages": [ { "content": { "text": "string" }, "role": "string" } ], "nextToken": "string", "policyConfiguration": { "bedrockGuardrailConfiguration": { "guardrailId": "string", "guardrailVersion": "string" } }, "retrievers": [ { "configuration": { ... }, "description": "string" } ], "userContext": { "userId": "string" } }

URI Request Parameters

The request does not use any URI parameters.

Request Body

The request accepts the following data in JSON format.

agenticRetrieveConfiguration

Configuration settings for the agentic retrieval operation.

Type: AgenticRetrieveConfiguration object

Required: Yes

generateResponse

Whether to generate a response based on the retrieved results.

Type: Boolean

Required: No

messages

The list of messages for the agentic retrieval conversation.

Type: Array of AgenticRetrieveMessage objects

Array Members: Minimum number of 1 item.

Required: Yes

nextToken

Opaque continuation token for paginated results.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 2048.

Pattern: \S*

Required: No

policyConfiguration

Policy configuration for guardrails and content filtering.

Type: AgenticRetrievePolicyConfiguration object

Required: No

retrievers

The list of retrievers to use for agentic retrieval.

Type: Array of AgenticRetriever objects

Array Members: Minimum number of 1 item.

Required: Yes

userContext

Contains information about the user making the request. This is used for access control filtering to ensure that retrieval results only include documents the user is authorized to access.

Type: UserContext object

Required: No

Response Syntax

HTTP/1.1 200 Content-type: application/json { "accessDeniedException": { }, "badGatewayException": { }, "conflictException": { }, "dependencyFailedException": { }, "internalServerException": { }, "resourceNotFoundException": { }, "responseEvent": { "text": "string" }, "result": { "generatedResponse": { "answer": "string", "citations": [ { "endIndex": number, "references": [ { "resultIndex": number } ], "startIndex": number } ] }, "nextToken": "string", "results": [ { "content": { "byteContent": blob, "mimeType": "string", "text": "string" }, "metadata": { "string" : JSON value }, "sourceRetriever": { "identifier": "string" } } ] }, "serviceQuotaExceededException": { }, "throttlingException": { }, "traceEvent": { "attributes": { "actions": [ { "fullDocumentExpansion": { "documentId": "string", "sourceRetriever": { "identifier": "string" } }, "retrieve": { "inputQuery": { "text": "string" }, "sourceRetrievers": [ { "identifier": "string" } ] } } ], "failures": [ { "message": "string" } ], "message": "string", "retrievalMetadata": [ { "identifier": "string", "retrievalType": "string" } ], "retrievalResponse": [ { "content": { "byteContent": blob, "mimeType": "string", "text": "string" }, "metadata": { "string" : JSON value }, "sourceRetriever": { "identifier": "string" } } ], "status": "string", "step": "string", "warnings": [ { ... } ] }, "id": "string", "timestamp": number }, "validationException": { } }

Response Elements

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

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

accessDeniedException

Access to the resource was denied.

Type: Exception

HTTP Status Code: 403

badGatewayException

A bad gateway error occurred.

Type: Exception

HTTP Status Code: 502

conflictException

A conflict occurred with the current state of the resource.

Type: Exception

HTTP Status Code: 409

dependencyFailedException

A dependency failed during the operation.

Type: Exception

HTTP Status Code: 424

internalServerException

An internal server error occurred.

Type: Exception

HTTP Status Code: 500

resourceNotFoundException

The specified resource was not found.

Type: Exception

HTTP Status Code: 404

responseEvent

A chunk of the generated answer. Emitted only when generateResponse is true.

Type: AgenticRetrieveResponseEvent object

result

A retrieval result event containing the retrieved items.

Type: AgenticRetrieveResultEvent object

serviceQuotaExceededException

The service quota has been exceeded.

Type: Exception

HTTP Status Code: 400

throttlingException

The request was throttled.

Type: Exception

HTTP Status Code: 429

traceEvent

A trace event providing visibility into the retrieval process.

Type: AgenticRetrieveTraceEvent object

validationException

The request validation failed.

Type: Exception

HTTP Status Code: 400

Errors

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

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.

resourceName

The name of the dependency that caused the issue, such as Amazon Bedrock, Lambda, or AWS STS.

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.

resourceName

The name of the dependency that caused the issue, such as Amazon Bedrock, Lambda, or AWS STS.

HTTP Status Code: 424

InternalServerException

An internal server error occurred. Retry your request.

reason

The reason for the exception. If the reason is BEDROCK_MODEL_INVOCATION_SERVICE_UNAVAILABLE, the model invocation service is unavailable. 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

Send a basic query using a managed model

The following example uses the managed foundation model type to query a knowledge base with agentic retrieval. When you set foundationModelType to MANAGED, the service selects the optimal model for you.

Sample Request

POST /agenticRetrieveStream HTTP/1.1 Content-type: application/json { "messages": [ { "content": { "text": "What are the main benefits of using Amazon Bedrock?" }, "role": "user" } ], "retrievers": [ { "description": "Knowledge base about Amazon Bedrock documentation", "configuration": { "knowledgeBase": { "knowledgeBaseId": "KB12345678" } } } ], "agenticRetrieveConfiguration": { "foundationModelType": "MANAGED", "rerankingModelType": "MANAGED" } }

See Also

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