|
| 1 | +use serde::{Deserialize, Serialize}; |
| 2 | +use std::collections::HashMap; |
| 3 | + |
| 4 | +/// The Event sent to Lambda from Agents for Amazon Bedrock. |
| 5 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 6 | +#[serde(rename_all = "camelCase")] |
| 7 | +pub struct AgentEvent { |
| 8 | + ///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. |
| 9 | + pub message_version: String, |
| 10 | + ///Contains information about the name, ID, alias, and version of the agent that the action group belongs to. |
| 11 | + pub agent: Agent, |
| 12 | + ///The user input for the conversation turn. |
| 13 | + pub input_text: String, |
| 14 | + /// The unique identifier of the agent session. |
| 15 | + pub session_id: String, |
| 16 | + /// The name of the action group. |
| 17 | + pub action_group: String, |
| 18 | + /// The path to the API operation, as defined in the OpenAPI schema. |
| 19 | + pub api_path: String, |
| 20 | + /// The method of the API operation, as defined in the OpenAPI schema. |
| 21 | + pub http_method: String, |
| 22 | + /// 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. |
| 23 | + pub parameters: Vec<Parameter>, |
| 24 | + /// Contains the request body and its properties, as defined in the OpenAPI schema. |
| 25 | + pub request_body: RequestBody, |
| 26 | + /// Contains session attributes and their values. |
| 27 | + pub session_attributes: HashMap<String, String>, |
| 28 | + /// Contains prompt attributes and their values. |
| 29 | + pub prompt_session_attributes: HashMap<String, String>, |
| 30 | +} |
| 31 | + |
| 32 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 33 | +#[serde(rename_all = "camelCase")] |
| 34 | +pub struct RequestBody { |
| 35 | + /// Contains the request body and its properties |
| 36 | + pub content: HashMap<String, Content>, |
| 37 | +} |
| 38 | + |
| 39 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 40 | +#[serde(rename_all = "camelCase")] |
| 41 | +pub struct Content { |
| 42 | + /// The content of the request body |
| 43 | + pub properties: Vec<Property>, |
| 44 | +} |
| 45 | + |
| 46 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 47 | +#[serde(rename_all = "camelCase")] |
| 48 | +pub struct Property { |
| 49 | + /// The name of the parameter |
| 50 | + pub name: String, |
| 51 | + /// The type of the parameter |
| 52 | + pub r#type: String, |
| 53 | + /// The value of the parameter |
| 54 | + pub value: String, |
| 55 | +} |
| 56 | + |
| 57 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 58 | +#[serde(rename_all = "camelCase")] |
| 59 | +pub struct Parameter { |
| 60 | + /// The name of the parameter |
| 61 | + pub name: String, |
| 62 | + /// The type of the parameter |
| 63 | + pub r#type: String, |
| 64 | + /// The value of the parameter |
| 65 | + pub value: String, |
| 66 | +} |
| 67 | + |
| 68 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 69 | +#[serde(rename_all = "camelCase")] |
| 70 | +pub struct Agent { |
| 71 | + /// The name of the agent. |
| 72 | + pub name: String, |
| 73 | + /// The unique identifier of the agent. |
| 74 | + pub id: String, |
| 75 | + /// The alias of the agent. |
| 76 | + pub alias: String, |
| 77 | + /// The version of the agent. |
| 78 | + pub version: String, |
| 79 | +} |
| 80 | + |
| 81 | +#[cfg(test)] |
| 82 | +mod tests { |
| 83 | + use serde_json; |
| 84 | + |
| 85 | + #[test] |
| 86 | + #[cfg(feature = "bedrock-agent-runtime")] |
| 87 | + fn example_bedrock_agent__runtime_event() { |
| 88 | + let data = include!("../../fixtures/example-bedrock-agent-runtime-event.json"); |
| 89 | + let parsed: AgentEvent = serde_json::from_str(&data).unwrap(); |
| 90 | + let output: String = serde_json::to_string(&parsed).unwrap(); |
| 91 | + let reparsed: AgentEvent = serde_json::from_slice(&output.as_bytes()).unwrap(); |
| 92 | + assert_eq!(parsed, reparsed); |
| 93 | + } |
| 94 | +} |
0 commit comments