aws_lambda_events/event/bedrock_agent_runtime/
mod.rs

1use serde::{Deserialize, Serialize};
2use 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")]
7pub 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    #[serde(default, skip_serializing_if = "Option::is_none")]
24    pub parameters: Option<Vec<Parameter>>,
25    /// Contains the request body and its properties, as defined in the OpenAPI schema.
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    pub request_body: Option<RequestBody>,
28    /// Contains session attributes and their values.
29    pub session_attributes: HashMap<String, String>,
30    /// Contains prompt attributes and their values.
31    pub prompt_session_attributes: HashMap<String, String>,
32}
33
34#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
35#[serde(rename_all = "camelCase")]
36pub struct RequestBody {
37    /// Contains the request body and its properties
38    pub content: HashMap<String, Content>,
39}
40
41#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
42#[serde(rename_all = "camelCase")]
43pub struct Content {
44    /// The content of the request body
45    pub properties: Vec<Property>,
46}
47
48#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
49#[serde(rename_all = "camelCase")]
50pub struct Property {
51    /// The name of the parameter
52    pub name: String,
53    /// The type of the parameter
54    pub r#type: String,
55    /// The value of the parameter
56    pub value: String,
57}
58
59#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
60#[serde(rename_all = "camelCase")]
61pub struct Parameter {
62    /// The name of the parameter
63    pub name: String,
64    /// The type of the parameter
65    pub r#type: String,
66    /// The value of the parameter
67    pub value: String,
68}
69
70#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
71#[serde(rename_all = "camelCase")]
72pub struct Agent {
73    /// The name of the agent.
74    pub name: String,
75    /// The unique identifier of the agent.
76    pub id: String,
77    /// The alias of the agent.
78    pub alias: String,
79    /// The version of the agent.
80    pub version: String,
81}
82
83#[cfg(test)]
84mod tests {
85
86    use crate::event::bedrock_agent_runtime::AgentEvent;
87
88    #[test]
89    #[cfg(feature = "bedrock_agent_runtime")]
90    fn example_bedrock_agent_runtime_event() {
91        let data = include_bytes!("../../fixtures/example-bedrock-agent-runtime-event.json");
92        let parsed: AgentEvent = serde_json::from_slice(data).unwrap();
93        let output: String = serde_json::to_string(&parsed).unwrap();
94        let reparsed: AgentEvent = serde_json::from_slice(output.as_bytes()).unwrap();
95        assert_eq!(parsed, reparsed);
96    }
97    #[test]
98    #[cfg(feature = "bedrock_agent_runtime")]
99    fn example_bedrock_agent_runtime_event_without_parameters() {
100        let data = include_bytes!("../../fixtures/example-bedrock-agent-runtime-event-without-parameters.json");
101        let parsed: AgentEvent = serde_json::from_slice(data).unwrap();
102        let output: String = serde_json::to_string(&parsed).unwrap();
103        let reparsed: AgentEvent = serde_json::from_slice(output.as_bytes()).unwrap();
104        assert_eq!(parsed, reparsed);
105    }
106    #[test]
107    #[cfg(feature = "bedrock_agent_runtime")]
108    fn example_bedrock_agent_runtime_event_without_request_body() {
109        let data = include_bytes!("../../fixtures/example-bedrock-agent-runtime-event-without-request-body.json");
110        let parsed: AgentEvent = serde_json::from_slice(data).unwrap();
111        let output: String = serde_json::to_string(&parsed).unwrap();
112        let reparsed: AgentEvent = serde_json::from_slice(output.as_bytes()).unwrap();
113        assert_eq!(parsed, reparsed);
114    }
115}