import { SessionDataWithChatUserCustomDataSpreadIn, RecordOrUndef } from './chatbot-types.js'; import '@aws-sdk/client-bedrock-agent-runtime'; import '@aws-sdk/client-bedrock-agentcore'; /** * Represents the input event structure passed to a Lambda function by an Amazon Bedrock Agent Action Group. */ interface BedrockActionGroupLambdaEvent { /** The version of the message format. Currently only "1.0" is supported by Amazon Bedrock. */ messageVersion: string; /** Information about the Bedrock agent invoking the action group. */ agent: { /** The name of the agent. */ name: string; /** The unique identifier of the agent. */ id: string; /** The alias used to invoke the agent. */ alias: string; /** The version of the agent. */ version: string; }; /** The user input message for the current conversation turn. */ inputText: string; /** The unique identifier for the session with the agent. */ sessionId: string; /** The name of the action group. */ actionGroup: string; /** * Present only when the action group is defined using function details. * The name of the function to call. * * Note an action group may only define 11 operations (functions) at the * time of this writing. */ function?: string; /** * A list of input parameters provided to the function or API call. * These are derived from the OpenAPI schema or the function definition. */ parameters: Array<{ /** The name of the parameter. */ name: string; /** The type of the parameter (e.g., string, number). */ type: string; /** The value of the parameter. */ value: any; }>; /** * Present only when the action group is defined using an OpenAPI schema. * The HTTP method (e.g., GET, POST) of the API operation. */ httpMethod?: string; /** * Present only when the action group is defined using an OpenAPI schema. * The path to the API operation. */ apiPath?: string; /** * Present only when the action group is defined using an OpenAPI schema. * The request body defined in the OpenAPI schema for the action group. */ requestBody?: Record; /** * Session attributes that persist for the duration of the session and provide context to the agent. * Each time you return these, it updates the session attributes for the current session. * * Our session attributes are a combination of SessionData and ChatUser.customData, which if present, is spread into the sessionAttributes. * * These are made available to the tools of the agent (your lambda functions). */ sessionAttributes?: SessionDataWithChatUserCustomDataSpreadIn; /** * Prompt session attributes that persist for a single turn and provide short-term context to the agent. * Each time you return these, it updates the prompt context for the current session. * * Attributes that persist over a single turn (one InvokeAgent call). You can use the * $prompt_session_attributes$ placeholder when you edit the orchestration base prompt template. * This placeholder will be populated at runtime with the attributes that you specify in the promptSessionAttributes field. * * https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html#session-state-attributes * * These are made availabe to the agent itself. */ promptSessionAttributes?: Record; } /** * Represents the response structure returned from a Lambda function to an Amazon Bedrock Agent Action Group. * * The maximum Lambda payload response size is 25 KB. * * https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html#agents-lambda-response */ interface BedrockActionGroupLambdaResponse { /** The version of the message format. Currently only "1.0" is supported by Amazon Bedrock. */ messageVersion: string; /** Contains the response information from the action group execution. */ response: ApiSchemaResponse | FunctionResponse; /** * Optional. Session attributes that persist for the duration of the session and provide context to the agent. * These attributes can be modified and returned to update the session state. */ sessionAttributes?: SessionDataWithChatUserCustomDataSpreadIn; /** * Optional. Prompt session attributes that persist for a single turn and provide short-term context to the agent. * These attributes can be modified and returned to update the prompt context. */ promptSessionAttributes?: Record; /** * Optional. Contains a list of query configurations for knowledge bases attached to the agent. */ knowledgeBasesConfiguration?: Array<{ /** The ID of the knowledge base to configure. */ knowledgeBaseId: string; /** Configuration for the knowledge base retrieval. */ retrievalConfiguration: { /** Configuration for vector search. */ vectorSearchConfiguration: { /** Number of results to return from the knowledge base. */ numberOfResults?: number; /** Optional override for the search type. */ overrideSearchType?: 'HYBRID' | 'SEMANTIC'; /** Optional filter for retrieval. */ filter?: Record; }; }; }>; } /** * Response structure for action groups defined with an OpenAPI schema. */ interface ApiSchemaResponse { /** The name of the action group. */ actionGroup: string; /** The path to the API operation, as defined in the OpenAPI schema. */ apiPath: string; /** The method of the API operation, as defined in the OpenAPI schema. */ httpMethod: string; /** The HTTP status code returned from the API operation. */ httpStatusCode: number; /** Contains the response body, as defined in the OpenAPI schema. */ responseBody: { /** The key is the content type (e.g., 'application/json') */ [contentType: string]: { /** The response body content as a JSON-formatted string. */ body: string; }; }; } /** * Response structure for action groups defined with function details. */ interface FunctionResponse { /** The name of the action group. */ actionGroup: string; /** The name of the function as defined in the function details. */ function: string; /** Contains details about the function execution response. */ functionResponse: { /** * Optional. Set to one of the following states to define the agent's behavior after processing: * - FAILURE: The agent throws a DependencyFailedException for the current session. * Applies when the function execution fails because of a dependency failure. * - REPROMPT: The agent passes a response string to the model to reprompt it. * Applies when the function execution fails because of invalid input. */ responseState?: 'FAILURE' | 'REPROMPT'; /** Contains the response from execution of the function. */ responseBody: { /** The key is the content type (currently only 'TEXT' is supported) */ [functionContentType: string]: { /** The response body content as a JSON-formatted string. */ body: string; }; }; }; } /** * Note: each description below should be just detailed enough to achieve the desired goal of the description attribute. * * Even though parameters isn't required, always set to `{}` if no parameters needed for the function. * * Explicitly include requireConfirmation even though not required and set to false */ interface BedrockActionGroupFunctionSchema { name: string; description: string; parameters?: Record; requireConfirmation?: 'ENABLED' | 'DISABLED'; } interface BedrockActionGroupFunctionSchemaParameterDetail { required?: boolean; type: 'string' | 'integer' | 'array' | 'number' | 'boolean'; description?: string; } /** Contains details about the results from looking up the knowledge base. */ /** * Represents the ReasoningContentBlock object from the AWS Bedrock Agent Runtime. /** * Represents the InvocationInput object from the AWS Bedrock Agent Runtime. * Contains information pertaining to the action group or knowledge base that is being invoked. * * Based on: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvocationInput.html */ interface InvocationInput { /** * Contains information about the action group to be invoked. */ actionGroupInvocationInput?: ActionGroupInvocationInput; /** * The collaborator's invocation input. */ agentCollaboratorInvocationInput?: AgentCollaboratorInvocationInput; /** * Contains information about the code interpreter to be invoked. */ codeInterpreterInvocationInput?: CodeInterpreterInvocationInput; /** * Specifies whether the agent is invoking an action group or a knowledge base. * Valid values: 'ACTION_GROUP' | 'KNOWLEDGE_BASE' | 'FINISH' | 'ACTION_GROUP_CODE_INTERPRETER' | 'AGENT_COLLABORATOR' */ invocationType?: 'ACTION_GROUP' | 'KNOWLEDGE_BASE' | 'FINISH' | 'ACTION_GROUP_CODE_INTERPRETER' | 'AGENT_COLLABORATOR'; /** * Contains details about the knowledge base to look up and the query to be made. */ knowledgeBaseLookupInput?: KnowledgeBaseLookupInput; /** * The unique identifier of the trace. * Length Constraints: Minimum length of 2. Maximum length of 16. */ traceId?: string; } /** * Represents the KnowledgeBaseLookupInput object from the AWS Bedrock Agent Runtime. * Contains details about the knowledge base to look up and the query to be made. * * Based on: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_KnowledgeBaseLookupInput.html */ interface KnowledgeBaseLookupInput { /** * The unique identifier of the knowledge base to look up. */ knowledgeBaseId?: string; /** * The query made to the knowledge base. */ text?: string; } /** * Represents the CodeInterpreterInvocationInput object from the AWS Bedrock Agent Runtime. * Contains information about the code interpreter being invoked. * * Based on: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_CodeInterpreterInvocationInput.html */ interface CodeInterpreterInvocationInput { /** * The code for the code interpreter to use. */ code?: string; /** * Files that are uploaded for the code interpreter to use. */ files?: string[]; } /** * Represents the AgentCollaboratorInvocationInput object from the AWS Bedrock Agent Runtime. * Contains information about the agent collaborator being invoked. * * Based on: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_AgentCollaboratorInvocationInput.html */ interface AgentCollaboratorInvocationInput { /** * The collaborator's alias ARN. * Pattern: ^arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:[0-9]{12}:agent-alias/[0-9a-zA-Z]{10}/[0-9a-zA-Z]{10}$ */ agentCollaboratorAliasArn?: string; /** * The collaborator's name. */ agentCollaboratorName?: string; /** * Text or action invocation result input for the collaborator. */ input?: AgentCollaboratorInputPayload; } /** * Represents the input payload for an agent collaborator in the AWS Bedrock Agent Runtime. * The input can be either plain text or an action invocation result. */ interface AgentCollaboratorInputPayload { /** * An action invocation result. */ returnControlResults?: ReturnControlResults; /** * Input text. */ text?: string; /** * The input type. * Valid values: 'TEXT' | 'RETURN_CONTROL' */ type?: 'TEXT' | 'RETURN_CONTROL'; } /** * Represents the result of returning control to the agent developer. */ interface ReturnControlResults { /** * The action's invocation ID. */ invocationId?: string; /** * The action invocation result. * Minimum items: 1 * Maximum items: 5 */ returnControlInvocationResults?: InvocationResultMember[]; } /** * Represents a single invocation result member. */ interface InvocationResultMember { /** * The function result. */ functionResult?: FunctionResult; /** * The API result. */ apiResult?: ApiResult; } /** * Represents the result of a function invocation. */ interface FunctionResult { /** * The name of the action group. */ actionGroup?: string; /** * The name of the function. */ function?: string; /** * The response body from the function invocation. * The keys are content types (e.g., 'TEXT'), and the values are response content. */ responseBody?: Record; } /** * Represents the result of an API invocation. */ interface ApiResult { /** * The name of the action group. */ actionGroup?: string; /** * The HTTP method used in the API invocation. */ httpMethod?: string; /** * The API path invoked. */ apiPath?: string; /** * The response body from the API invocation. * The keys are content types (e.g., 'application/json'), and the values are response content. */ responseBody?: Record; } /** * Represents the content of a response. */ interface ResponseContent { /** * The body of the response. */ body?: string; } /** * Represents the ActionGroupInvocationInput object from the AWS Bedrock Agent Runtime. * Contains information about the action group being invoked. * * Based on: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_ActionGroupInvocationInput.html */ interface ActionGroupInvocationInput { /** * The name of the action group. */ actionGroupName?: string; /** * The path to the API to call, based off the action group. */ apiPath?: string; /** * How fulfillment of the action is handled. * Valid values: 'LAMBDA' | 'RETURN_CONTROL' */ executionType?: 'LAMBDA' | 'RETURN_CONTROL'; /** * The function in the action group to call. */ function?: string; /** * The unique identifier of the invocation. * Only returned if the executionType is RETURN_CONTROL. */ invocationId?: string; /** * The parameters in the Lambda input event. */ parameters?: Parameter[]; /** * The parameters in the request body for the Lambda input event. */ requestBody?: RequestBody; /** * The API method being used, based off the action group. */ verb?: string; } /** * Represents a parameter in the Lambda input event. */ interface Parameter { /** * The name of the parameter. */ name: string; /** * The type of the parameter. */ type: string; /** * The value of the parameter. */ value: string; } /** * Represents the request body for the Lambda input event. */ interface RequestBody { /** * A map of content types to their respective parameters. */ content: Record; } /** * ModelInvocationInput * -------------------- * The prompt + model-level settings the agent sends to the foundation model * during a given step (pre-processing, orchestration, KB-response-gen, etc.). * * Docs: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_ModelInvocationInput.html */ interface ModelInvocationInput { /** ARN or name of the model (custom or FM). */ foundationModel?: string; /** Temperature, top-p, max-tokens, stop sequences, … */ inferenceConfiguration?: InferenceConfiguration; /** ARN of a Lambda that post-parses the raw FM output (optional override). */ overrideLambda?: string; /** Whether the default parser Lambda is used. */ parserMode?: 'DEFAULT' | 'OVERRIDDEN'; /** Whether the default prompt template was overridden. */ promptCreationMode?: 'DEFAULT' | 'OVERRIDDEN'; /** The actual prompt text that was sent to the model. */ text?: string; /** Unique ID that ties this record to the overall trace. */ traceId?: string; /** Which step of the agent sequence this relates to. */ type?: 'PRE_PROCESSING' | 'ORCHESTRATION' | 'KNOWLEDGE_BASE_RESPONSE_GENERATION' | 'POST_PROCESSING' | 'ROUTING_CLASSIFIER'; } /** * A light version of the InferenceConfiguration object. * Only the fields documented under ModelInvocationInput are included here; * add any others you need. * * Docs: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InferenceConfiguration.html */ interface InferenceConfiguration { maximumLength?: number; stopSequences?: string[]; temperature?: number; topK?: number; topP?: number; } export type { ActionGroupInvocationInput, AgentCollaboratorInputPayload, AgentCollaboratorInvocationInput, ApiResult, ApiSchemaResponse, BedrockActionGroupFunctionSchema, BedrockActionGroupFunctionSchemaParameterDetail, BedrockActionGroupLambdaEvent, BedrockActionGroupLambdaResponse, CodeInterpreterInvocationInput, FunctionResponse, FunctionResult, InferenceConfiguration, InvocationInput, InvocationResultMember, KnowledgeBaseLookupInput, ModelInvocationInput, Parameter, RequestBody, ResponseContent, ReturnControlResults };