BedrockAgentRuntimeClient

Contains APIs related to model invocation and querying of knowledge bases.

Installation

NPM
npm install @aws-sdk/client-bedrock-agent-runtime
Yarn
yarn add @aws-sdk/client-bedrock-agent-runtime
pnpm
pnpm add @aws-sdk/client-bedrock-agent-runtime

BedrockAgentRuntimeClient Operations

Command
Summary
DeleteAgentMemoryCommand

Deletes memory from the specified memory identifier.

GenerateQueryCommand

Generates an SQL query from a natural language query. For more information, see Generate a query for structured data  in the Amazon Bedrock User Guide.

GetAgentMemoryCommand

Gets the sessions stored in the memory of the agent.

InvokeAgentCommand

Sends a prompt for the agent to process and respond to. Note the following fields for the request:

  • 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 .

  • To stream agent responses, make sure that only orchestration prompt is enabled. Agent streaming is not supported for the following steps:

    • Pre-processing

    • Post-processing

    • Agent with 1 Knowledge base and User Input not enabled

  • End a conversation by setting endSession to true.

  • In the sessionState object, you can include attributes for the session or prompt or, if you configured an action group to return control, results from invocation of the action group.

The response contains both chunk and trace attributes.

The final response is returned in the bytes field of the chunk object. The InvokeAgent returns one chunk for the entire interaction.

  • 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.

  • If the action predicted was configured to return control, the response returns parameters for the action, elicited from the user, in the returnControl field.

  • Errors are also surfaced in the response.

InvokeFlowCommand

Invokes an alias of a flow to run the inputs that you specify and return the output of each node as a stream. If there's an error, the error is returned. For more information, see Test a flow in Amazon Bedrock  in the Amazon Bedrock User Guide .

The CLI doesn't support streaming operations in Amazon Bedrock, including InvokeFlow.

InvokeInlineAgentCommand

Invokes an inline Amazon Bedrock agent using the configurations you provide with the request.

  • Specify the following fields for security purposes.

    • (Optional) customerEncryptionKeyArn – The Amazon Resource Name (ARN) of a KMS key to encrypt the creation of the agent.

    • (Optional) idleSessionTTLinSeconds – Specify the number of seconds for which the agent should maintain session information. After this time expires, the subsequent InvokeInlineAgent request begins a new session.

  • To override the default prompt behavior for agent orchestration and to use advanced prompts, include a promptOverrideConfiguration object. For more information, see Advanced prompts .

  • The agent instructions will not be honored if your agent has only one knowledge base, uses default prompts, has no action group, and user input is disabled.

OptimizePromptCommand

Optimizes a prompt for the task that you specify. For more information, see Optimize a prompt  in the Amazon Bedrock User Guide .

RerankCommand

Reranks the relevance of sources based on queries. For more information, see Improve the relevance of query responses with a reranker model .

RetrieveAndGenerateCommand

Queries a knowledge base and generates responses based on the retrieved results and using the specified foundation model or inference profile . The response only cites sources that are relevant to the query.

RetrieveAndGenerateStreamCommand

Queries a knowledge base and generates responses based on the retrieved results, with output in streaming format.

The CLI doesn't support streaming operations in Amazon Bedrock, including InvokeModelWithResponseStream.

This operation requires permission for the bedrock:RetrieveAndGenerate action.

RetrieveCommand

Queries a knowledge base and retrieves information from it.

BedrockAgentRuntimeClient Configuration

Parameter
Type
Description
defaultsMode
Optional
DefaultsMode | Provider<DefaultsMode>
The @smithy/smithy-client#DefaultsMode that will be used to determine how certain default configuration options are resolved in the SDK.
disableHostPrefix
Optional
boolean
Disable dynamically changing the endpoint of the client based on the hostPrefix trait of an operation.
eventStreamSerdeProvider
Optional
EventStreamSerdeProvider
The function that provides necessary utilities for generating and parsing event stream
extensions
Optional
RuntimeExtension[]
Optional extensions
logger
Optional
Logger
Optional logger for logging debug/info/warn/error.
maxAttempts
Optional
number | Provider<number>
Value for how many times a request will be made at most in case of retry.
profile
Optional
string
Setting a client profile is similar to setting a value for the AWS_PROFILE environment variable. Setting a profile on a client in code only affects the single client instance, unlike AWS_PROFILE.When set, and only for environments where an AWS configuration file exists, fields configurable by this file will be retrieved from the specified profile within that file. Conflicting code configuration and environment variables will still have higher priority.For client credential resolution that involves checking the AWS configuration file, the client's profile (this value) will be used unless a different profile is set in the credential provider options.
region
Optional
string | Provider<string>
The AWS region to which this client will send requests
requestHandler
Optional
__HttpHandlerUserInput
The HTTP handler to use or its constructor options. Fetch in browser and Https in Nodejs.
retryMode
Optional
string | Provider<string>
Specifies which retry algorithm to use.
useDualstackEndpoint
Optional
boolean | Provider<boolean>
Enables IPv6/IPv4 dualstack endpoint.
useFipsEndpoint
Optional
boolean | Provider<boolean>
Enables FIPS compatible endpoints.
Additional config fields are described in the full configuration type: BedrockAgentRuntimeClientConfig