diff --git a/Makefile b/Makefile index 76e57e94..049be8f8 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ check-event-features: cargo test --package aws_lambda_events --no-default-features --features apigw cargo test --package aws_lambda_events --no-default-features --features appsync cargo test --package aws_lambda_events --no-default-features --features autoscaling + cargo test --package aws_lambda_events --no-default-features --features bedrock_agent_runtime cargo test --package aws_lambda_events --no-default-features --features chime_bot cargo test --package aws_lambda_events --no-default-features --features clientvpn cargo test --package aws_lambda_events --no-default-features --features cloudwatch_events diff --git a/lambda-events/Cargo.toml b/lambda-events/Cargo.toml index ca5fa1a8..b35809a2 100644 --- a/lambda-events/Cargo.toml +++ b/lambda-events/Cargo.toml @@ -43,6 +43,7 @@ default = [ "apigw", "appsync", "autoscaling", + "bedrock_agent_runtime", "chime_bot", "clientvpn", "cloudformation", @@ -85,6 +86,7 @@ alb = ["bytes", "http", "http-body", "http-serde", "query_map"] apigw = ["bytes", "http", "http-body", "http-serde", "query_map"] appsync = [] autoscaling = ["chrono"] +bedrock_agent_runtime = [] chime_bot = ["chrono"] clientvpn = [] cloudformation = [] diff --git a/lambda-events/src/event/bedrock_agent_runtime/mod.rs b/lambda-events/src/event/bedrock_agent_runtime/mod.rs new file mode 100644 index 00000000..65ab4a9d --- /dev/null +++ b/lambda-events/src/event/bedrock_agent_runtime/mod.rs @@ -0,0 +1,94 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +/// The Event sent to Lambda from Agents for Amazon Bedrock. +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct AgentEvent { + ///The version of the message that identifies the format of the event data going into the Lambda function and the expected format of the response from a Lambda function. Amazon Bedrock only supports version 1.0. + pub message_version: String, + ///Contains information about the name, ID, alias, and version of the agent that the action group belongs to. + pub agent: Agent, + ///The user input for the conversation turn. + pub input_text: String, + /// The unique identifier of the agent session. + pub session_id: String, + /// The name of the action group. + pub action_group: String, + /// The path to the API operation, as defined in the OpenAPI schema. + pub api_path: String, + /// The method of the API operation, as defined in the OpenAPI schema. + pub http_method: String, + /// Contains a list of objects. Each object contains the name, type, and value of a parameter in the API operation, as defined in the OpenAPI schema. + pub parameters: Vec, + /// Contains the request body and its properties, as defined in the OpenAPI schema. + pub request_body: RequestBody, + /// Contains session attributes and their values. + pub session_attributes: HashMap, + /// Contains prompt attributes and their values. + pub prompt_session_attributes: HashMap, +} + +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct RequestBody { + /// Contains the request body and its properties + pub content: HashMap, +} + +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Content { + /// The content of the request body + pub properties: Vec, +} + +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Property { + /// The name of the parameter + pub name: String, + /// The type of the parameter + pub r#type: String, + /// The value of the parameter + pub value: String, +} + +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Parameter { + /// The name of the parameter + pub name: String, + /// The type of the parameter + pub r#type: String, + /// The value of the parameter + pub value: String, +} + +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct Agent { + /// The name of the agent. + pub name: String, + /// The unique identifier of the agent. + pub id: String, + /// The alias of the agent. + pub alias: String, + /// The version of the agent. + pub version: String, +} + +#[cfg(test)] +mod tests { + use serde_json; + + #[test] + #[cfg(feature = "bedrock-agent-runtime")] + fn example_bedrock_agent__runtime_event() { + let data = include!("../../fixtures/example-bedrock-agent-runtime-event.json"); + let parsed: AgentEvent = serde_json::from_str(&data).unwrap(); + let output: String = serde_json::to_string(&parsed).unwrap(); + let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap(); + assert_eq!(parsed, reparsed); + } +} diff --git a/lambda-events/src/event/mod.rs b/lambda-events/src/event/mod.rs index 5ee57911..28a0c82b 100644 --- a/lambda-events/src/event/mod.rs +++ b/lambda-events/src/event/mod.rs @@ -17,6 +17,10 @@ pub mod appsync; #[cfg(feature = "autoscaling")] pub mod autoscaling; +/// AWS Lambda event definitions for agent for amazon bedrock +#[cfg(feature = "bedrock_agent_runtime")] +pub mod bedrock_agent_runtime; + /// AWS Lambda event definitions for chime_bot. #[cfg(feature = "chime_bot")] pub mod chime_bot; diff --git a/lambda-events/src/fixtures/example-bedrock-agent-runtime-event.json b/lambda-events/src/fixtures/example-bedrock-agent-runtime-event.json new file mode 100644 index 00000000..b5244515 --- /dev/null +++ b/lambda-events/src/fixtures/example-bedrock-agent-runtime-event.json @@ -0,0 +1,40 @@ +{ + "messageVersion": "1.0", + "agent": { + "name": "AgentName", + "id": "AgentID", + "alias": "AgentAlias", + "version": "AgentVersion" + }, + "inputText": "InputText", + "sessionId": "SessionID", + "actionGroup": "ActionGroup", + "apiPath": "/api/path", + "httpMethod": "POST", + "parameters": [ + { + "name": "param1", + "type": "string", + "value": "value1" + } + ], + "requestBody": { + "content": { + "application/json": { + "properties": [ + { + "name": "prop1", + "type": "string", + "value": "value1" + } + ] + } + } + }, + "sessionAttributes": { + "attr1": "value1" + }, + "promptSessionAttributes": { + "promptAttr1": "value1" + } +} \ No newline at end of file