From bc8997185262078a5b7038122d63b4f72e74e57c Mon Sep 17 00:00:00 2001 From: awstools Date: Fri, 8 Nov 2024 19:22:22 +0000 Subject: [PATCH] feat(client-bedrock-agent-runtime): This release adds trace functionality to Bedrock Prompt Flows --- .../src/commands/InvokeAgentCommand.ts | 12 +- .../src/commands/InvokeFlowCommand.ts | 38 ++ .../src/models/models_0.ts | 464 +++++++++++++++--- .../src/protocols/Aws_restJson1.ts | 160 ++++++ .../aws-models/bedrock-agent-runtime.json | 307 +++++++++++- 5 files changed, 904 insertions(+), 77 deletions(-) diff --git a/clients/client-bedrock-agent-runtime/src/commands/InvokeAgentCommand.ts b/clients/client-bedrock-agent-runtime/src/commands/InvokeAgentCommand.ts index 3cefd2441324..69c5c6046328 100644 --- a/clients/client-bedrock-agent-runtime/src/commands/InvokeAgentCommand.ts +++ b/clients/client-bedrock-agent-runtime/src/commands/InvokeAgentCommand.ts @@ -374,6 +374,8 @@ export interface InvokeAgentCommandOutput extends InvokeAgentResponse, __Metadat * // traceId: "STRING_VALUE", * // text: "STRING_VALUE", * // type: "PRE_PROCESSING" || "ORCHESTRATION" || "KNOWLEDGE_BASE_RESPONSE_GENERATION" || "POST_PROCESSING", + * // overrideLambda: "STRING_VALUE", + * // promptCreationMode: "DEFAULT" || "OVERRIDDEN", * // inferenceConfiguration: { // InferenceConfiguration * // temperature: Number("float"), * // topP: Number("float"), @@ -383,8 +385,6 @@ export interface InvokeAgentCommandOutput extends InvokeAgentResponse, __Metadat * // "STRING_VALUE", * // ], * // }, - * // overrideLambda: "STRING_VALUE", - * // promptCreationMode: "DEFAULT" || "OVERRIDDEN", * // parserMode: "DEFAULT" || "OVERRIDDEN", * // }, * // modelInvocationOutput: { // PreProcessingModelInvocationOutput @@ -505,6 +505,8 @@ export interface InvokeAgentCommandOutput extends InvokeAgentResponse, __Metadat * // traceId: "STRING_VALUE", * // text: "STRING_VALUE", * // type: "PRE_PROCESSING" || "ORCHESTRATION" || "KNOWLEDGE_BASE_RESPONSE_GENERATION" || "POST_PROCESSING", + * // overrideLambda: "STRING_VALUE", + * // promptCreationMode: "DEFAULT" || "OVERRIDDEN", * // inferenceConfiguration: { * // temperature: Number("float"), * // topP: Number("float"), @@ -514,8 +516,6 @@ export interface InvokeAgentCommandOutput extends InvokeAgentResponse, __Metadat * // "STRING_VALUE", * // ], * // }, - * // overrideLambda: "STRING_VALUE", - * // promptCreationMode: "DEFAULT" || "OVERRIDDEN", * // parserMode: "DEFAULT" || "OVERRIDDEN", * // }, * // modelInvocationOutput: { // OrchestrationModelInvocationOutput @@ -536,6 +536,8 @@ export interface InvokeAgentCommandOutput extends InvokeAgentResponse, __Metadat * // traceId: "STRING_VALUE", * // text: "STRING_VALUE", * // type: "PRE_PROCESSING" || "ORCHESTRATION" || "KNOWLEDGE_BASE_RESPONSE_GENERATION" || "POST_PROCESSING", + * // overrideLambda: "STRING_VALUE", + * // promptCreationMode: "DEFAULT" || "OVERRIDDEN", * // inferenceConfiguration: { * // temperature: Number("float"), * // topP: Number("float"), @@ -545,8 +547,6 @@ export interface InvokeAgentCommandOutput extends InvokeAgentResponse, __Metadat * // "STRING_VALUE", * // ], * // }, - * // overrideLambda: "STRING_VALUE", - * // promptCreationMode: "DEFAULT" || "OVERRIDDEN", * // parserMode: "DEFAULT" || "OVERRIDDEN", * // }, * // modelInvocationOutput: { // PostProcessingModelInvocationOutput diff --git a/clients/client-bedrock-agent-runtime/src/commands/InvokeFlowCommand.ts b/clients/client-bedrock-agent-runtime/src/commands/InvokeFlowCommand.ts index dd90f00078ac..ba8fabc47871 100644 --- a/clients/client-bedrock-agent-runtime/src/commands/InvokeFlowCommand.ts +++ b/clients/client-bedrock-agent-runtime/src/commands/InvokeFlowCommand.ts @@ -59,6 +59,7 @@ export interface InvokeFlowCommandOutput extends InvokeFlowResponse, __MetadataB * }, * }, * ], + * enableTrace: true || false, * }; * const command = new InvokeFlowCommand(input); * const response = await client.send(command); @@ -74,6 +75,43 @@ export interface InvokeFlowCommandOutput extends InvokeFlowResponse, __MetadataB * // flowCompletionEvent: { // FlowCompletionEvent * // completionReason: "SUCCESS", // required * // }, + * // flowTraceEvent: { // FlowTraceEvent + * // trace: { // FlowTrace Union: only one key present + * // nodeInputTrace: { // FlowTraceNodeInputEvent + * // nodeName: "STRING_VALUE", // required + * // timestamp: new Date("TIMESTAMP"), // required + * // fields: [ // FlowTraceNodeInputFields // required + * // { // FlowTraceNodeInputField + * // nodeInputName: "STRING_VALUE", // required + * // content: { // FlowTraceNodeInputContent Union: only one key present + * // document: "DOCUMENT_VALUE", + * // }, + * // }, + * // ], + * // }, + * // nodeOutputTrace: { // FlowTraceNodeOutputEvent + * // nodeName: "STRING_VALUE", // required + * // timestamp: new Date("TIMESTAMP"), // required + * // fields: [ // FlowTraceNodeOutputFields // required + * // { // FlowTraceNodeOutputField + * // nodeOutputName: "STRING_VALUE", // required + * // content: { // FlowTraceNodeOutputContent Union: only one key present + * // document: "DOCUMENT_VALUE", + * // }, + * // }, + * // ], + * // }, + * // conditionNodeResultTrace: { // FlowTraceConditionNodeResultEvent + * // nodeName: "STRING_VALUE", // required + * // timestamp: new Date("TIMESTAMP"), // required + * // satisfiedConditions: [ // FlowTraceConditions // required + * // { // FlowTraceCondition + * // conditionName: "STRING_VALUE", // required + * // }, + * // ], + * // }, + * // }, + * // }, * // internalServerException: { // InternalServerException * // message: "STRING_VALUE", * // }, diff --git a/clients/client-bedrock-agent-runtime/src/models/models_0.ts b/clients/client-bedrock-agent-runtime/src/models/models_0.ts index f0ad2a5e0951..9f7fc9a1cffd 100644 --- a/clients/client-bedrock-agent-runtime/src/models/models_0.ts +++ b/clients/client-bedrock-agent-runtime/src/models/models_0.ts @@ -252,14 +252,6 @@ export class InternalServerException extends __BaseException { /** *

Contains information about an input into the flow.

- *

This data type is used in the following API operations:

- * * @public */ export type FlowInputContent = FlowInputContent.DocumentMember | FlowInputContent.$UnknownMember; @@ -298,14 +290,6 @@ export namespace FlowInputContent { /** *

Contains information about an input into the prompt flow and where to send it.

- *

This data type is used in the following API operations:

- * * @public */ export interface FlowInput { @@ -349,6 +333,12 @@ export interface InvokeFlowRequest { * @public */ inputs: FlowInput[] | undefined; + + /** + *

Specifies whether to return the trace for the flow or not. Traces track inputs and outputs for nodes in the flow. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ + enableTrace?: boolean; } /** @@ -366,14 +356,6 @@ export type FlowCompletionReason = (typeof FlowCompletionReason)[keyof typeof Fl /** *

Contains information about why a flow completed.

- *

This data type is used in the following API operations:

- * * @public */ export interface FlowCompletionEvent { @@ -386,14 +368,6 @@ export interface FlowCompletionEvent { /** *

Contains information about the content in an output from prompt flow invocation.

- *

This data type is used in the following API operations:

- * * @public */ export type FlowOutputContent = FlowOutputContent.DocumentMember | FlowOutputContent.$UnknownMember; @@ -451,14 +425,6 @@ export type NodeType = (typeof NodeType)[keyof typeof NodeType]; /** *

Contains information about an output from prompt flow invoction.

- *

This data type is used in the following API operations:

- * * @public */ export interface FlowOutputEvent { @@ -481,6 +447,291 @@ export interface FlowOutputEvent { content: FlowOutputContent | undefined; } +/** + *

Contains information about a condition that was satisfied. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export interface FlowTraceCondition { + /** + *

The name of the condition.

+ * @public + */ + conditionName: string | undefined; +} + +/** + *

Contains information about an output from a condition node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export interface FlowTraceConditionNodeResultEvent { + /** + *

The name of the condition node.

+ * @public + */ + nodeName: string | undefined; + + /** + *

The date and time that the trace was returned.

+ * @public + */ + timestamp: Date | undefined; + + /** + *

An array of objects containing information about the conditions that were satisfied.

+ * @public + */ + satisfiedConditions: FlowTraceCondition[] | undefined; +} + +/** + *

Contains the content of the node input. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export type FlowTraceNodeInputContent = + | FlowTraceNodeInputContent.DocumentMember + | FlowTraceNodeInputContent.$UnknownMember; + +/** + * @public + */ +export namespace FlowTraceNodeInputContent { + /** + *

The content of the node input.

+ * @public + */ + export interface DocumentMember { + document: __DocumentType; + $unknown?: never; + } + + /** + * @public + */ + export interface $UnknownMember { + document?: never; + $unknown: [string, any]; + } + + export interface Visitor { + document: (value: __DocumentType) => T; + _: (name: string, value: any) => T; + } + + export const visit = (value: FlowTraceNodeInputContent, visitor: Visitor): T => { + if (value.document !== undefined) return visitor.document(value.document); + return visitor._(value.$unknown[0], value.$unknown[1]); + }; +} + +/** + *

Contains information about a field in the input into a node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export interface FlowTraceNodeInputField { + /** + *

The name of the node input.

+ * @public + */ + nodeInputName: string | undefined; + + /** + *

The content of the node input.

+ * @public + */ + content: FlowTraceNodeInputContent | undefined; +} + +/** + *

Contains information about the input into a node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export interface FlowTraceNodeInputEvent { + /** + *

The name of the node that received the input.

+ * @public + */ + nodeName: string | undefined; + + /** + *

The date and time that the trace was returned.

+ * @public + */ + timestamp: Date | undefined; + + /** + *

An array of objects containing information about each field in the input.

+ * @public + */ + fields: FlowTraceNodeInputField[] | undefined; +} + +/** + *

Contains the content of the node output. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export type FlowTraceNodeOutputContent = + | FlowTraceNodeOutputContent.DocumentMember + | FlowTraceNodeOutputContent.$UnknownMember; + +/** + * @public + */ +export namespace FlowTraceNodeOutputContent { + /** + *

The content of the node output.

+ * @public + */ + export interface DocumentMember { + document: __DocumentType; + $unknown?: never; + } + + /** + * @public + */ + export interface $UnknownMember { + document?: never; + $unknown: [string, any]; + } + + export interface Visitor { + document: (value: __DocumentType) => T; + _: (name: string, value: any) => T; + } + + export const visit = (value: FlowTraceNodeOutputContent, visitor: Visitor): T => { + if (value.document !== undefined) return visitor.document(value.document); + return visitor._(value.$unknown[0], value.$unknown[1]); + }; +} + +/** + *

Contains information about a field in the output from a node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export interface FlowTraceNodeOutputField { + /** + *

The name of the node output.

+ * @public + */ + nodeOutputName: string | undefined; + + /** + *

The content of the node output.

+ * @public + */ + content: FlowTraceNodeOutputContent | undefined; +} + +/** + *

Contains information about the output from a node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export interface FlowTraceNodeOutputEvent { + /** + *

The name of the node that yielded the output.

+ * @public + */ + nodeName: string | undefined; + + /** + *

The date and time that the trace was returned.

+ * @public + */ + timestamp: Date | undefined; + + /** + *

An array of objects containing information about each field in the output.

+ * @public + */ + fields: FlowTraceNodeOutputField[] | undefined; +} + +/** + *

Contains information about an input or output for a node in the flow. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export type FlowTrace = + | FlowTrace.ConditionNodeResultTraceMember + | FlowTrace.NodeInputTraceMember + | FlowTrace.NodeOutputTraceMember + | FlowTrace.$UnknownMember; + +/** + * @public + */ +export namespace FlowTrace { + /** + *

Contains information about the input into a node.

+ * @public + */ + export interface NodeInputTraceMember { + nodeInputTrace: FlowTraceNodeInputEvent; + nodeOutputTrace?: never; + conditionNodeResultTrace?: never; + $unknown?: never; + } + + /** + *

Contains information about the output from a node.

+ * @public + */ + export interface NodeOutputTraceMember { + nodeInputTrace?: never; + nodeOutputTrace: FlowTraceNodeOutputEvent; + conditionNodeResultTrace?: never; + $unknown?: never; + } + + /** + *

Contains information about an output from a condition node.

+ * @public + */ + export interface ConditionNodeResultTraceMember { + nodeInputTrace?: never; + nodeOutputTrace?: never; + conditionNodeResultTrace: FlowTraceConditionNodeResultEvent; + $unknown?: never; + } + + /** + * @public + */ + export interface $UnknownMember { + nodeInputTrace?: never; + nodeOutputTrace?: never; + conditionNodeResultTrace?: never; + $unknown: [string, any]; + } + + export interface Visitor { + nodeInputTrace: (value: FlowTraceNodeInputEvent) => T; + nodeOutputTrace: (value: FlowTraceNodeOutputEvent) => T; + conditionNodeResultTrace: (value: FlowTraceConditionNodeResultEvent) => T; + _: (name: string, value: any) => T; + } + + export const visit = (value: FlowTrace, visitor: Visitor): T => { + if (value.nodeInputTrace !== undefined) return visitor.nodeInputTrace(value.nodeInputTrace); + if (value.nodeOutputTrace !== undefined) return visitor.nodeOutputTrace(value.nodeOutputTrace); + if (value.conditionNodeResultTrace !== undefined) + return visitor.conditionNodeResultTrace(value.conditionNodeResultTrace); + return visitor._(value.$unknown[0], value.$unknown[1]); + }; +} + +/** + *

Contains information about a trace, which tracks an input or output for a node in the flow. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

+ * @public + */ +export interface FlowTraceEvent { + /** + *

The trace object containing information about an input or output for a node in the flow.

+ * @public + */ + trace: FlowTrace | undefined; +} + /** *

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

* @public @@ -563,14 +814,6 @@ export class ValidationException extends __BaseException { /** *

The output of the flow.

- *

This data type is used in the following API operations:

- * * @public */ export type FlowResponseStream = @@ -580,6 +823,7 @@ export type FlowResponseStream = | FlowResponseStream.DependencyFailedExceptionMember | FlowResponseStream.FlowCompletionEventMember | FlowResponseStream.FlowOutputEventMember + | FlowResponseStream.FlowTraceEventMember | FlowResponseStream.InternalServerExceptionMember | FlowResponseStream.ResourceNotFoundExceptionMember | FlowResponseStream.ServiceQuotaExceededExceptionMember @@ -598,6 +842,7 @@ export namespace FlowResponseStream { export interface FlowOutputEventMember { flowOutputEvent: FlowOutputEvent; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -617,6 +862,27 @@ export namespace FlowResponseStream { export interface FlowCompletionEventMember { flowOutputEvent?: never; flowCompletionEvent: FlowCompletionEvent; + flowTraceEvent?: never; + internalServerException?: never; + validationException?: never; + resourceNotFoundException?: never; + serviceQuotaExceededException?: never; + throttlingException?: never; + accessDeniedException?: never; + conflictException?: never; + dependencyFailedException?: never; + badGatewayException?: never; + $unknown?: never; + } + + /** + *

Contains information about a trace, which tracks an input or output for a node in the flow.

+ * @public + */ + export interface FlowTraceEventMember { + flowOutputEvent?: never; + flowCompletionEvent?: never; + flowTraceEvent: FlowTraceEvent; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -636,6 +902,7 @@ export namespace FlowResponseStream { export interface InternalServerExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException: InternalServerException; validationException?: never; resourceNotFoundException?: never; @@ -655,6 +922,7 @@ export namespace FlowResponseStream { export interface ValidationExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException: ValidationException; resourceNotFoundException?: never; @@ -674,6 +942,7 @@ export namespace FlowResponseStream { export interface ResourceNotFoundExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException: ResourceNotFoundException; @@ -693,6 +962,7 @@ export namespace FlowResponseStream { export interface ServiceQuotaExceededExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -712,6 +982,7 @@ export namespace FlowResponseStream { export interface ThrottlingExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -731,6 +1002,7 @@ export namespace FlowResponseStream { export interface AccessDeniedExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -750,6 +1022,7 @@ export namespace FlowResponseStream { export interface ConflictExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -769,6 +1042,7 @@ export namespace FlowResponseStream { export interface DependencyFailedExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -788,6 +1062,7 @@ export namespace FlowResponseStream { export interface BadGatewayExceptionMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -806,6 +1081,7 @@ export namespace FlowResponseStream { export interface $UnknownMember { flowOutputEvent?: never; flowCompletionEvent?: never; + flowTraceEvent?: never; internalServerException?: never; validationException?: never; resourceNotFoundException?: never; @@ -821,6 +1097,7 @@ export namespace FlowResponseStream { export interface Visitor { flowOutputEvent: (value: FlowOutputEvent) => T; flowCompletionEvent: (value: FlowCompletionEvent) => T; + flowTraceEvent: (value: FlowTraceEvent) => T; internalServerException: (value: InternalServerException) => T; validationException: (value: ValidationException) => T; resourceNotFoundException: (value: ResourceNotFoundException) => T; @@ -836,6 +1113,7 @@ export namespace FlowResponseStream { export const visit = (value: FlowResponseStream, visitor: Visitor): T => { if (value.flowOutputEvent !== undefined) return visitor.flowOutputEvent(value.flowOutputEvent); if (value.flowCompletionEvent !== undefined) return visitor.flowCompletionEvent(value.flowCompletionEvent); + if (value.flowTraceEvent !== undefined) return visitor.flowTraceEvent(value.flowTraceEvent); if (value.internalServerException !== undefined) return visitor.internalServerException(value.internalServerException); if (value.validationException !== undefined) return visitor.validationException(value.validationException); @@ -2519,12 +2797,6 @@ export interface ModelInvocationInput { */ type?: PromptType; - /** - *

Specifications about the inference parameters that were provided alongside the prompt. These are specified in the PromptOverrideConfiguration object that was set when the agent was created or updated. For more information, see Inference parameters for foundation models.

- * @public - */ - inferenceConfiguration?: InferenceConfiguration; - /** *

The ARN of the Lambda function to use when parsing the raw foundation model output in parts of the agent sequence.

* @public @@ -2537,6 +2809,12 @@ export interface ModelInvocationInput { */ promptCreationMode?: CreationMode; + /** + *

Specifications about the inference parameters that were provided alongside the prompt. These are specified in the PromptOverrideConfiguration object that was set when the agent was created or updated. For more information, see Inference parameters for foundation models.

+ * @public + */ + inferenceConfiguration?: InferenceConfiguration; + /** *

Specifies whether to override the default parser Lambda function when parsing the raw foundation model output in the part of the agent sequence defined by the promptType.

* @public @@ -4131,7 +4409,7 @@ export interface ExternalSourcesRetrieveAndGenerateConfiguration { */ export interface GenerationConfiguration { /** - *

Contains the template for the prompt that's sent to the model for response generation.

+ *

Contains the template for the prompt that's sent to the model for response generation. Generation prompts must include the $search_results$ variable. For more information, see Use placeholder variables in the user guide.

* @public */ promptTemplate?: PromptTemplate; @@ -4187,7 +4465,7 @@ export interface QueryTransformationConfiguration { */ export interface OrchestrationConfiguration { /** - *

Contains the template for the prompt that's sent to the model for response generation.

+ *

Contains the template for the prompt that's sent to the model. Orchestration prompts must include the $conversation_history$ and $output_format_instructions$ variables. For more information, see Use placeholder variables in the user guide.

* @public */ promptTemplate?: PromptTemplate; @@ -5172,12 +5450,86 @@ export const FlowOutputEventFilterSensitiveLog = (obj: FlowOutputEvent): any => ...(obj.content && { content: obj.content }), }); +/** + * @internal + */ +export const FlowTraceConditionFilterSensitiveLog = (obj: FlowTraceCondition): any => ({ + ...obj, +}); + +/** + * @internal + */ +export const FlowTraceConditionNodeResultEventFilterSensitiveLog = (obj: FlowTraceConditionNodeResultEvent): any => ({ + ...obj, + ...(obj.satisfiedConditions && { satisfiedConditions: SENSITIVE_STRING }), +}); + +/** + * @internal + */ +export const FlowTraceNodeInputContentFilterSensitiveLog = (obj: FlowTraceNodeInputContent): any => { + if (obj.document !== undefined) return { document: obj.document }; + if (obj.$unknown !== undefined) return { [obj.$unknown[0]]: "UNKNOWN" }; +}; + +/** + * @internal + */ +export const FlowTraceNodeInputFieldFilterSensitiveLog = (obj: FlowTraceNodeInputField): any => ({ + ...obj, + ...(obj.content && { content: SENSITIVE_STRING }), +}); + +/** + * @internal + */ +export const FlowTraceNodeInputEventFilterSensitiveLog = (obj: FlowTraceNodeInputEvent): any => ({ + ...obj, + ...(obj.fields && { fields: SENSITIVE_STRING }), +}); + +/** + * @internal + */ +export const FlowTraceNodeOutputFieldFilterSensitiveLog = (obj: FlowTraceNodeOutputField): any => ({ + ...obj, + ...(obj.content && { content: obj.content }), +}); + +/** + * @internal + */ +export const FlowTraceNodeOutputEventFilterSensitiveLog = (obj: FlowTraceNodeOutputEvent): any => ({ + ...obj, + ...(obj.fields && { fields: SENSITIVE_STRING }), +}); + +/** + * @internal + */ +export const FlowTraceFilterSensitiveLog = (obj: FlowTrace): any => { + if (obj.nodeInputTrace !== undefined) return { nodeInputTrace: SENSITIVE_STRING }; + if (obj.nodeOutputTrace !== undefined) return { nodeOutputTrace: SENSITIVE_STRING }; + if (obj.conditionNodeResultTrace !== undefined) return { conditionNodeResultTrace: SENSITIVE_STRING }; + if (obj.$unknown !== undefined) return { [obj.$unknown[0]]: "UNKNOWN" }; +}; + +/** + * @internal + */ +export const FlowTraceEventFilterSensitiveLog = (obj: FlowTraceEvent): any => ({ + ...obj, + ...(obj.trace && { trace: SENSITIVE_STRING }), +}); + /** * @internal */ export const FlowResponseStreamFilterSensitiveLog = (obj: FlowResponseStream): any => { if (obj.flowOutputEvent !== undefined) return { flowOutputEvent: SENSITIVE_STRING }; if (obj.flowCompletionEvent !== undefined) return { flowCompletionEvent: SENSITIVE_STRING }; + if (obj.flowTraceEvent !== undefined) return { flowTraceEvent: FlowTraceEventFilterSensitiveLog(obj.flowTraceEvent) }; if (obj.internalServerException !== undefined) return { internalServerException: obj.internalServerException }; if (obj.validationException !== undefined) return { validationException: obj.validationException }; if (obj.resourceNotFoundException !== undefined) return { resourceNotFoundException: obj.resourceNotFoundException }; diff --git a/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts b/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts index 44cccae7d5d8..2b9bb25e50b0 100644 --- a/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts +++ b/clients/client-bedrock-agent-runtime/src/protocols/Aws_restJson1.ts @@ -66,6 +66,15 @@ import { FlowOutputContent, FlowOutputEvent, FlowResponseStream, + FlowTrace, + FlowTraceConditionNodeResultEvent, + FlowTraceEvent, + FlowTraceNodeInputContent, + FlowTraceNodeInputEvent, + FlowTraceNodeInputField, + FlowTraceNodeOutputContent, + FlowTraceNodeOutputEvent, + FlowTraceNodeOutputField, FunctionResult, GenerationConfiguration, GuardrailConfiguration, @@ -201,6 +210,7 @@ export const se_InvokeFlowCommand = async ( let body: any; body = JSON.stringify( take(input, { + enableTrace: [], inputs: (_) => se_FlowInputs(_, context), }) ); @@ -618,6 +628,11 @@ const de_FlowResponseStream = ( flowCompletionEvent: await de_FlowCompletionEvent_event(event["flowCompletionEvent"], context), }; } + if (event["flowTraceEvent"] != null) { + return { + flowTraceEvent: await de_FlowTraceEvent_event(event["flowTraceEvent"], context), + }; + } if (event["internalServerException"] != null) { return { internalServerException: await de_InternalServerException_event(event["internalServerException"], context), @@ -809,6 +824,12 @@ const de_FlowOutputEvent_event = async (output: any, context: __SerdeContext): P Object.assign(contents, de_FlowOutputEvent(data, context)); return contents; }; +const de_FlowTraceEvent_event = async (output: any, context: __SerdeContext): Promise => { + const contents: FlowTraceEvent = {} as any; + const data: any = await parseBody(output.body, context); + Object.assign(contents, de_FlowTraceEvent(data, context)); + return contents; +}; const de_InternalServerException_event = async ( output: any, context: __SerdeContext @@ -1343,6 +1364,145 @@ const de_FlowOutputEvent = (output: any, context: __SerdeContext): FlowOutputEve }) as any; }; +/** + * deserializeAws_restJson1FlowTrace + */ +const de_FlowTrace = (output: any, context: __SerdeContext): FlowTrace => { + if (output.conditionNodeResultTrace != null) { + return { + conditionNodeResultTrace: de_FlowTraceConditionNodeResultEvent(output.conditionNodeResultTrace, context), + }; + } + if (output.nodeInputTrace != null) { + return { + nodeInputTrace: de_FlowTraceNodeInputEvent(output.nodeInputTrace, context), + }; + } + if (output.nodeOutputTrace != null) { + return { + nodeOutputTrace: de_FlowTraceNodeOutputEvent(output.nodeOutputTrace, context), + }; + } + return { $unknown: Object.entries(output)[0] }; +}; + +// de_FlowTraceCondition omitted. + +/** + * deserializeAws_restJson1FlowTraceConditionNodeResultEvent + */ +const de_FlowTraceConditionNodeResultEvent = ( + output: any, + context: __SerdeContext +): FlowTraceConditionNodeResultEvent => { + return take(output, { + nodeName: __expectString, + satisfiedConditions: _json, + timestamp: (_: any) => __expectNonNull(__parseRfc3339DateTimeWithOffset(_)), + }) as any; +}; + +// de_FlowTraceConditions omitted. + +/** + * deserializeAws_restJson1FlowTraceEvent + */ +const de_FlowTraceEvent = (output: any, context: __SerdeContext): FlowTraceEvent => { + return take(output, { + trace: (_: any) => de_FlowTrace(__expectUnion(_), context), + }) as any; +}; + +/** + * deserializeAws_restJson1FlowTraceNodeInputContent + */ +const de_FlowTraceNodeInputContent = (output: any, context: __SerdeContext): FlowTraceNodeInputContent => { + if (output.document != null) { + return { + document: de_Document(output.document, context), + }; + } + return { $unknown: Object.entries(output)[0] }; +}; + +/** + * deserializeAws_restJson1FlowTraceNodeInputEvent + */ +const de_FlowTraceNodeInputEvent = (output: any, context: __SerdeContext): FlowTraceNodeInputEvent => { + return take(output, { + fields: (_: any) => de_FlowTraceNodeInputFields(_, context), + nodeName: __expectString, + timestamp: (_: any) => __expectNonNull(__parseRfc3339DateTimeWithOffset(_)), + }) as any; +}; + +/** + * deserializeAws_restJson1FlowTraceNodeInputField + */ +const de_FlowTraceNodeInputField = (output: any, context: __SerdeContext): FlowTraceNodeInputField => { + return take(output, { + content: (_: any) => de_FlowTraceNodeInputContent(__expectUnion(_), context), + nodeInputName: __expectString, + }) as any; +}; + +/** + * deserializeAws_restJson1FlowTraceNodeInputFields + */ +const de_FlowTraceNodeInputFields = (output: any, context: __SerdeContext): FlowTraceNodeInputField[] => { + const retVal = (output || []) + .filter((e: any) => e != null) + .map((entry: any) => { + return de_FlowTraceNodeInputField(entry, context); + }); + return retVal; +}; + +/** + * deserializeAws_restJson1FlowTraceNodeOutputContent + */ +const de_FlowTraceNodeOutputContent = (output: any, context: __SerdeContext): FlowTraceNodeOutputContent => { + if (output.document != null) { + return { + document: de_Document(output.document, context), + }; + } + return { $unknown: Object.entries(output)[0] }; +}; + +/** + * deserializeAws_restJson1FlowTraceNodeOutputEvent + */ +const de_FlowTraceNodeOutputEvent = (output: any, context: __SerdeContext): FlowTraceNodeOutputEvent => { + return take(output, { + fields: (_: any) => de_FlowTraceNodeOutputFields(_, context), + nodeName: __expectString, + timestamp: (_: any) => __expectNonNull(__parseRfc3339DateTimeWithOffset(_)), + }) as any; +}; + +/** + * deserializeAws_restJson1FlowTraceNodeOutputField + */ +const de_FlowTraceNodeOutputField = (output: any, context: __SerdeContext): FlowTraceNodeOutputField => { + return take(output, { + content: (_: any) => de_FlowTraceNodeOutputContent(__expectUnion(_), context), + nodeOutputName: __expectString, + }) as any; +}; + +/** + * deserializeAws_restJson1FlowTraceNodeOutputFields + */ +const de_FlowTraceNodeOutputFields = (output: any, context: __SerdeContext): FlowTraceNodeOutputField[] => { + const retVal = (output || []) + .filter((e: any) => e != null) + .map((entry: any) => { + return de_FlowTraceNodeOutputField(entry, context); + }); + return retVal; +}; + // de_FunctionInvocationInput omitted. // de_FunctionParameter omitted. diff --git a/codegen/sdk-codegen/aws-models/bedrock-agent-runtime.json b/codegen/sdk-codegen/aws-models/bedrock-agent-runtime.json index 6048e4720b8a..9450bfcdbe49 100644 --- a/codegen/sdk-codegen/aws-models/bedrock-agent-runtime.json +++ b/codegen/sdk-codegen/aws-models/bedrock-agent-runtime.json @@ -1064,7 +1064,7 @@ "min": 1, "max": 2048 }, - "smithy.api#pattern": "^(arn:aws(-[^:]{1,10})?:bedrock:[a-z0-9-]{1,20}:([0-9]{12})?:([a-z-]{1,20}/)?)?([a-z0-9.-]{1,63}){0,2}(([:][a-z0-9-]{1,63}){0,2})?(/[a-z0-9]{1,12})?$" + "smithy.api#pattern": "^(arn:aws(-[^:]+)?:(bedrock|sagemaker):[a-z0-9-]{1,20}:([0-9]{12})?:([a-z-]+/)?)?([a-z0-9.-]{1,63}){0,2}(([:][a-z0-9-]{1,63}){0,2})?(/[a-z0-9]{1,12})?$" } }, "com.amazonaws.bedrockagentruntime#ByteContentBlob": { @@ -1718,7 +1718,7 @@ } }, "traits": { - "smithy.api#documentation": "

Contains information about why a flow completed.

\n

This data type is used in the following API operations:

\n ", + "smithy.api#documentation": "

Contains information about why a flow completed.

", "smithy.api#sensitive": {} } }, @@ -1768,7 +1768,7 @@ } }, "traits": { - "smithy.api#documentation": "

Contains information about an input into the prompt flow and where to send it.

\n

This data type is used in the following API operations:

\n " + "smithy.api#documentation": "

Contains information about an input into the prompt flow and where to send it.

" } }, "com.amazonaws.bedrockagentruntime#FlowInputContent": { @@ -1782,7 +1782,7 @@ } }, "traits": { - "smithy.api#documentation": "

Contains information about an input into the flow.

\n

This data type is used in the following API operations:

\n ", + "smithy.api#documentation": "

Contains information about an input into the flow.

", "smithy.api#sensitive": {} } }, @@ -1809,7 +1809,7 @@ } }, "traits": { - "smithy.api#documentation": "

Contains information about the content in an output from prompt flow invocation.

\n

This data type is used in the following API operations:

\n " + "smithy.api#documentation": "

Contains information about the content in an output from prompt flow invocation.

" } }, "com.amazonaws.bedrockagentruntime#FlowOutputEvent": { @@ -1838,7 +1838,7 @@ } }, "traits": { - "smithy.api#documentation": "

Contains information about an output from prompt flow invoction.

\n

This data type is used in the following API operations:

\n ", + "smithy.api#documentation": "

Contains information about an output from prompt flow invoction.

", "smithy.api#sensitive": {} } }, @@ -1865,6 +1865,12 @@ "smithy.api#documentation": "

Contains information about why the flow completed.

" } }, + "flowTraceEvent": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceEvent", + "traits": { + "smithy.api#documentation": "

Contains information about a trace, which tracks an input or output for a node in the flow.

" + } + }, "internalServerException": { "target": "com.amazonaws.bedrockagentruntime#InternalServerException", "traits": { @@ -1921,10 +1927,269 @@ } }, "traits": { - "smithy.api#documentation": "

The output of the flow.

\n

This data type is used in the following API operations:

\n ", + "smithy.api#documentation": "

The output of the flow.

", "smithy.api#streaming": {} } }, + "com.amazonaws.bedrockagentruntime#FlowTrace": { + "type": "union", + "members": { + "nodeInputTrace": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceNodeInputEvent", + "traits": { + "smithy.api#documentation": "

Contains information about the input into a node.

" + } + }, + "nodeOutputTrace": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceNodeOutputEvent", + "traits": { + "smithy.api#documentation": "

Contains information about the output from a node.

" + } + }, + "conditionNodeResultTrace": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceConditionNodeResultEvent", + "traits": { + "smithy.api#documentation": "

Contains information about an output from a condition node.

" + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about an input or output for a node in the flow. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceCondition": { + "type": "structure", + "members": { + "conditionName": { + "target": "smithy.api#String", + "traits": { + "smithy.api#documentation": "

The name of the condition.

", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about a condition that was satisfied. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceConditionNodeResultEvent": { + "type": "structure", + "members": { + "nodeName": { + "target": "com.amazonaws.bedrockagentruntime#NodeName", + "traits": { + "smithy.api#documentation": "

The name of the condition node.

", + "smithy.api#required": {} + } + }, + "timestamp": { + "target": "com.amazonaws.bedrockagentruntime#DateTimestamp", + "traits": { + "smithy.api#documentation": "

The date and time that the trace was returned.

", + "smithy.api#required": {} + } + }, + "satisfiedConditions": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceConditions", + "traits": { + "smithy.api#documentation": "

An array of objects containing information about the conditions that were satisfied.

", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about an output from a condition node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceConditions": { + "type": "list", + "member": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceCondition" + }, + "traits": { + "smithy.api#length": { + "min": 1, + "max": 5 + } + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceEvent": { + "type": "structure", + "members": { + "trace": { + "target": "com.amazonaws.bedrockagentruntime#FlowTrace", + "traits": { + "smithy.api#documentation": "

The trace object containing information about an input or output for a node in the flow.

", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about a trace, which tracks an input or output for a node in the flow. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

" + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceNodeInputContent": { + "type": "union", + "members": { + "document": { + "target": "smithy.api#Document", + "traits": { + "smithy.api#documentation": "

The content of the node input.

" + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains the content of the node input. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceNodeInputEvent": { + "type": "structure", + "members": { + "nodeName": { + "target": "com.amazonaws.bedrockagentruntime#NodeName", + "traits": { + "smithy.api#documentation": "

The name of the node that received the input.

", + "smithy.api#required": {} + } + }, + "timestamp": { + "target": "com.amazonaws.bedrockagentruntime#DateTimestamp", + "traits": { + "smithy.api#documentation": "

The date and time that the trace was returned.

", + "smithy.api#required": {} + } + }, + "fields": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceNodeInputFields", + "traits": { + "smithy.api#documentation": "

An array of objects containing information about each field in the input.

", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about the input into a node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceNodeInputField": { + "type": "structure", + "members": { + "nodeInputName": { + "target": "com.amazonaws.bedrockagentruntime#NodeInputName", + "traits": { + "smithy.api#documentation": "

The name of the node input.

", + "smithy.api#required": {} + } + }, + "content": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceNodeInputContent", + "traits": { + "smithy.api#documentation": "

The content of the node input.

", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about a field in the input into a node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceNodeInputFields": { + "type": "list", + "member": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceNodeInputField" + }, + "traits": { + "smithy.api#length": { + "min": 1, + "max": 5 + } + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceNodeOutputContent": { + "type": "union", + "members": { + "document": { + "target": "smithy.api#Document", + "traits": { + "smithy.api#documentation": "

The content of the node output.

" + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains the content of the node output. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

" + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceNodeOutputEvent": { + "type": "structure", + "members": { + "nodeName": { + "target": "com.amazonaws.bedrockagentruntime#NodeName", + "traits": { + "smithy.api#documentation": "

The name of the node that yielded the output.

", + "smithy.api#required": {} + } + }, + "timestamp": { + "target": "com.amazonaws.bedrockagentruntime#DateTimestamp", + "traits": { + "smithy.api#documentation": "

The date and time that the trace was returned.

", + "smithy.api#required": {} + } + }, + "fields": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceNodeOutputFields", + "traits": { + "smithy.api#documentation": "

An array of objects containing information about each field in the output.

", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about the output from a node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceNodeOutputField": { + "type": "structure", + "members": { + "nodeOutputName": { + "target": "com.amazonaws.bedrockagentruntime#NodeOutputName", + "traits": { + "smithy.api#documentation": "

The name of the node output.

", + "smithy.api#required": {} + } + }, + "content": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceNodeOutputContent", + "traits": { + "smithy.api#documentation": "

The content of the node output.

", + "smithy.api#required": {} + } + } + }, + "traits": { + "smithy.api#documentation": "

Contains information about a field in the output from a node. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

", + "smithy.api#sensitive": {} + } + }, + "com.amazonaws.bedrockagentruntime#FlowTraceNodeOutputFields": { + "type": "list", + "member": { + "target": "com.amazonaws.bedrockagentruntime#FlowTraceNodeOutputField" + }, + "traits": { + "smithy.api#length": { + "min": 1, + "max": 2 + } + } + }, "com.amazonaws.bedrockagentruntime#Function": { "type": "string", "traits": { @@ -2055,7 +2320,7 @@ "promptTemplate": { "target": "com.amazonaws.bedrockagentruntime#PromptTemplate", "traits": { - "smithy.api#documentation": "

Contains the template for the prompt that's sent to the model for response generation.

" + "smithy.api#documentation": "

Contains the template for the prompt that's sent to the model for response generation. Generation prompts must include the $search_results$ variable. For more information, see Use placeholder variables in the user guide.

" } }, "guardrailConfiguration": { @@ -3431,6 +3696,12 @@ "smithy.api#documentation": "

A list of objects, each containing information about an input into the flow.

", "smithy.api#required": {} } + }, + "enableTrace": { + "target": "smithy.api#Boolean", + "traits": { + "smithy.api#documentation": "

Specifies whether to return the trace for the flow or not. Traces track inputs and outputs for nodes in the flow. For more information, see Track each step in your prompt flow by viewing its trace in Amazon Bedrock.

" + } } }, "traits": { @@ -3853,12 +4124,6 @@ "smithy.api#documentation": "

The step in the agent sequence.

" } }, - "inferenceConfiguration": { - "target": "com.amazonaws.bedrockagentruntime#InferenceConfiguration", - "traits": { - "smithy.api#documentation": "

Specifications about the inference parameters that were provided alongside the prompt. These are specified in the PromptOverrideConfiguration object that was set when the agent was created or updated. For more information, see Inference parameters for foundation models.

" - } - }, "overrideLambda": { "target": "com.amazonaws.bedrockagentruntime#LambdaArn", "traits": { @@ -3871,6 +4136,12 @@ "smithy.api#documentation": "

Specifies whether the default prompt template was OVERRIDDEN. If it was, the basePromptTemplate that was set in the PromptOverrideConfiguration object when the agent was created or updated is used instead.

" } }, + "inferenceConfiguration": { + "target": "com.amazonaws.bedrockagentruntime#InferenceConfiguration", + "traits": { + "smithy.api#documentation": "

Specifications about the inference parameters that were provided alongside the prompt. These are specified in the PromptOverrideConfiguration object that was set when the agent was created or updated. For more information, see Inference parameters for foundation models.

" + } + }, "parserMode": { "target": "com.amazonaws.bedrockagentruntime#CreationMode", "traits": { @@ -3893,6 +4164,12 @@ "smithy.api#pattern": "^\\S*$" } }, + "com.amazonaws.bedrockagentruntime#NodeInputName": { + "type": "string", + "traits": { + "smithy.api#pattern": "^[a-zA-Z]([_]?[0-9a-zA-Z]){0,99}$" + } + }, "com.amazonaws.bedrockagentruntime#NodeName": { "type": "string", "traits": { @@ -4015,7 +4292,7 @@ "promptTemplate": { "target": "com.amazonaws.bedrockagentruntime#PromptTemplate", "traits": { - "smithy.api#documentation": "

Contains the template for the prompt that's sent to the model for response generation.

" + "smithy.api#documentation": "

Contains the template for the prompt that's sent to the model. Orchestration prompts must include the $conversation_history$ and $output_format_instructions$ variables. For more information, see Use placeholder variables in the user guide.

" } }, "inferenceConfig": {