aws_sdk_bedrockagentruntime/operation/invoke_agent/builders.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub use crate::operation::invoke_agent::_invoke_agent_output::InvokeAgentOutputBuilder;
3
4pub use crate::operation::invoke_agent::_invoke_agent_input::InvokeAgentInputBuilder;
5
6impl crate::operation::invoke_agent::builders::InvokeAgentInputBuilder {
7 /// Sends a request with this input using the given client.
8 pub async fn send_with(
9 self,
10 client: &crate::Client,
11 ) -> ::std::result::Result<
12 crate::operation::invoke_agent::InvokeAgentOutput,
13 ::aws_smithy_runtime_api::client::result::SdkError<
14 crate::operation::invoke_agent::InvokeAgentError,
15 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
16 >,
17 > {
18 let mut fluent_builder = client.invoke_agent();
19 fluent_builder.inner = self;
20 fluent_builder.send().await
21 }
22}
23/// Fluent builder constructing a request to `InvokeAgent`.
24///
25/// <note>
26/// </note>
27/// <p>Sends a prompt for the agent to process and respond to. Note the following fields for the request:</p>
28/// <ul>
29/// <li>
30/// <p>To continue the same conversation with an agent, use the same <code>sessionId</code> value in the request.</p></li>
31/// <li>
32/// <p>To activate trace enablement, turn <code>enableTrace</code> to <code>true</code>. Trace enablement helps you follow the agent's reasoning process that led it to the information it processed, the actions it took, and the final result it yielded. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/agents-test.html#trace-events">Trace enablement</a>.</p></li>
33/// <li>
34/// <p>End a conversation by setting <code>endSession</code> to <code>true</code>.</p></li>
35/// <li>
36/// <p>In the <code>sessionState</code> object, you can include attributes for the session or prompt or, if you configured an action group to return control, results from invocation of the action group.</p></li>
37/// </ul>
38/// <p>The response contains both <b>chunk</b> and <b>trace</b> attributes.</p>
39/// <p>The final response is returned in the <code>bytes</code> field of the <code>chunk</code> object. The <code>InvokeAgent</code> returns one chunk for the entire interaction.</p>
40/// <ul>
41/// <li>
42/// <p>The <code>attribution</code> object contains citations for parts of the response.</p></li>
43/// <li>
44/// <p>If you set <code>enableTrace</code> to <code>true</code> in the request, you can trace the agent's steps and reasoning process that led it to the response.</p></li>
45/// <li>
46/// <p>If the action predicted was configured to return control, the response returns parameters for the action, elicited from the user, in the <code>returnControl</code> field.</p></li>
47/// <li>
48/// <p>Errors are also surfaced in the response.</p></li>
49/// </ul>
50#[derive(::std::clone::Clone, ::std::fmt::Debug)]
51pub struct InvokeAgentFluentBuilder {
52 handle: ::std::sync::Arc<crate::client::Handle>,
53 inner: crate::operation::invoke_agent::builders::InvokeAgentInputBuilder,
54 config_override: ::std::option::Option<crate::config::Builder>,
55}
56impl
57 crate::client::customize::internal::CustomizableSend<
58 crate::operation::invoke_agent::InvokeAgentOutput,
59 crate::operation::invoke_agent::InvokeAgentError,
60 > for InvokeAgentFluentBuilder
61{
62 fn send(
63 self,
64 config_override: crate::config::Builder,
65 ) -> crate::client::customize::internal::BoxFuture<
66 crate::client::customize::internal::SendResult<
67 crate::operation::invoke_agent::InvokeAgentOutput,
68 crate::operation::invoke_agent::InvokeAgentError,
69 >,
70 > {
71 ::std::boxed::Box::pin(async move { self.config_override(config_override).send().await })
72 }
73}
74impl InvokeAgentFluentBuilder {
75 /// Creates a new `InvokeAgentFluentBuilder`.
76 pub(crate) fn new(handle: ::std::sync::Arc<crate::client::Handle>) -> Self {
77 Self {
78 handle,
79 inner: ::std::default::Default::default(),
80 config_override: ::std::option::Option::None,
81 }
82 }
83 /// Access the InvokeAgent as a reference.
84 pub fn as_input(&self) -> &crate::operation::invoke_agent::builders::InvokeAgentInputBuilder {
85 &self.inner
86 }
87 /// Sends the request and returns the response.
88 ///
89 /// If an error occurs, an `SdkError` will be returned with additional details that
90 /// can be matched against.
91 ///
92 /// By default, any retryable failures will be retried twice. Retry behavior
93 /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
94 /// set when configuring the client.
95 pub async fn send(
96 self,
97 ) -> ::std::result::Result<
98 crate::operation::invoke_agent::InvokeAgentOutput,
99 ::aws_smithy_runtime_api::client::result::SdkError<
100 crate::operation::invoke_agent::InvokeAgentError,
101 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
102 >,
103 > {
104 let input = self
105 .inner
106 .build()
107 .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)?;
108 let runtime_plugins = crate::operation::invoke_agent::InvokeAgent::operation_runtime_plugins(
109 self.handle.runtime_plugins.clone(),
110 &self.handle.conf,
111 self.config_override,
112 );
113 let mut output = crate::operation::invoke_agent::InvokeAgent::orchestrate(&runtime_plugins, input).await?;
114
115 // Converts any error encountered beyond this point into an `SdkError` response error
116 // with an `HttpResponse`. However, since we have already exited the `orchestrate`
117 // function, the original `HttpResponse` is no longer available and cannot be restored.
118 // This means that header information from the original response has been lost.
119 //
120 // Note that the response body would have been consumed by the deserializer
121 // regardless, even if the initial message was hypothetically processed during
122 // the orchestrator's deserialization phase but later resulted in an error.
123 fn response_error(
124 err: impl ::std::convert::Into<::aws_smithy_runtime_api::box_error::BoxError>,
125 ) -> ::aws_smithy_runtime_api::client::result::SdkError<
126 crate::operation::invoke_agent::InvokeAgentError,
127 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
128 > {
129 ::aws_smithy_runtime_api::client::result::SdkError::response_error(
130 err,
131 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse::new(
132 ::aws_smithy_runtime_api::http::StatusCode::try_from(200).expect("valid successful code"),
133 ::aws_smithy_types::body::SdkBody::empty(),
134 ),
135 )
136 }
137
138 let message = output.completion.try_recv_initial_response().await.map_err(response_error)?;
139
140 match message {
141 ::std::option::Option::Some(_message) => ::std::result::Result::Ok(output),
142 ::std::option::Option::None => ::std::result::Result::Ok(output),
143 }
144 }
145
146 /// Consumes this builder, creating a customizable operation that can be modified before being sent.
147 pub fn customize(
148 self,
149 ) -> crate::client::customize::CustomizableOperation<
150 crate::operation::invoke_agent::InvokeAgentOutput,
151 crate::operation::invoke_agent::InvokeAgentError,
152 Self,
153 > {
154 crate::client::customize::CustomizableOperation::new(self)
155 }
156 pub(crate) fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
157 self.set_config_override(::std::option::Option::Some(config_override.into()));
158 self
159 }
160
161 pub(crate) fn set_config_override(&mut self, config_override: ::std::option::Option<crate::config::Builder>) -> &mut Self {
162 self.config_override = config_override;
163 self
164 }
165 /// <p>Contains parameters that specify various attributes of the session. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html">Control session context</a>.</p><note>
166 /// <p>If you include <code>returnControlInvocationResults</code> in the <code>sessionState</code> field, the <code>inputText</code> field will be ignored.</p>
167 /// </note>
168 pub fn session_state(mut self, input: crate::types::SessionState) -> Self {
169 self.inner = self.inner.session_state(input);
170 self
171 }
172 /// <p>Contains parameters that specify various attributes of the session. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html">Control session context</a>.</p><note>
173 /// <p>If you include <code>returnControlInvocationResults</code> in the <code>sessionState</code> field, the <code>inputText</code> field will be ignored.</p>
174 /// </note>
175 pub fn set_session_state(mut self, input: ::std::option::Option<crate::types::SessionState>) -> Self {
176 self.inner = self.inner.set_session_state(input);
177 self
178 }
179 /// <p>Contains parameters that specify various attributes of the session. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/agents-session-state.html">Control session context</a>.</p><note>
180 /// <p>If you include <code>returnControlInvocationResults</code> in the <code>sessionState</code> field, the <code>inputText</code> field will be ignored.</p>
181 /// </note>
182 pub fn get_session_state(&self) -> &::std::option::Option<crate::types::SessionState> {
183 self.inner.get_session_state()
184 }
185 /// <p>The unique identifier of the agent to use.</p>
186 pub fn agent_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
187 self.inner = self.inner.agent_id(input.into());
188 self
189 }
190 /// <p>The unique identifier of the agent to use.</p>
191 pub fn set_agent_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
192 self.inner = self.inner.set_agent_id(input);
193 self
194 }
195 /// <p>The unique identifier of the agent to use.</p>
196 pub fn get_agent_id(&self) -> &::std::option::Option<::std::string::String> {
197 self.inner.get_agent_id()
198 }
199 /// <p>The alias of the agent to use.</p>
200 pub fn agent_alias_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
201 self.inner = self.inner.agent_alias_id(input.into());
202 self
203 }
204 /// <p>The alias of the agent to use.</p>
205 pub fn set_agent_alias_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
206 self.inner = self.inner.set_agent_alias_id(input);
207 self
208 }
209 /// <p>The alias of the agent to use.</p>
210 pub fn get_agent_alias_id(&self) -> &::std::option::Option<::std::string::String> {
211 self.inner.get_agent_alias_id()
212 }
213 /// <p>The unique identifier of the session. Use the same value across requests to continue the same conversation.</p>
214 pub fn session_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
215 self.inner = self.inner.session_id(input.into());
216 self
217 }
218 /// <p>The unique identifier of the session. Use the same value across requests to continue the same conversation.</p>
219 pub fn set_session_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
220 self.inner = self.inner.set_session_id(input);
221 self
222 }
223 /// <p>The unique identifier of the session. Use the same value across requests to continue the same conversation.</p>
224 pub fn get_session_id(&self) -> &::std::option::Option<::std::string::String> {
225 self.inner.get_session_id()
226 }
227 /// <p>Specifies whether to end the session with the agent or not.</p>
228 pub fn end_session(mut self, input: bool) -> Self {
229 self.inner = self.inner.end_session(input);
230 self
231 }
232 /// <p>Specifies whether to end the session with the agent or not.</p>
233 pub fn set_end_session(mut self, input: ::std::option::Option<bool>) -> Self {
234 self.inner = self.inner.set_end_session(input);
235 self
236 }
237 /// <p>Specifies whether to end the session with the agent or not.</p>
238 pub fn get_end_session(&self) -> &::std::option::Option<bool> {
239 self.inner.get_end_session()
240 }
241 /// <p>Specifies whether to turn on the trace or not to track the agent's reasoning process. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/agents-test.html#trace-events">Trace enablement</a>.</p>
242 pub fn enable_trace(mut self, input: bool) -> Self {
243 self.inner = self.inner.enable_trace(input);
244 self
245 }
246 /// <p>Specifies whether to turn on the trace or not to track the agent's reasoning process. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/agents-test.html#trace-events">Trace enablement</a>.</p>
247 pub fn set_enable_trace(mut self, input: ::std::option::Option<bool>) -> Self {
248 self.inner = self.inner.set_enable_trace(input);
249 self
250 }
251 /// <p>Specifies whether to turn on the trace or not to track the agent's reasoning process. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/agents-test.html#trace-events">Trace enablement</a>.</p>
252 pub fn get_enable_trace(&self) -> &::std::option::Option<bool> {
253 self.inner.get_enable_trace()
254 }
255 /// <p>The prompt text to send the agent.</p><note>
256 /// <p>If you include <code>returnControlInvocationResults</code> in the <code>sessionState</code> field, the <code>inputText</code> field will be ignored.</p>
257 /// </note>
258 pub fn input_text(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
259 self.inner = self.inner.input_text(input.into());
260 self
261 }
262 /// <p>The prompt text to send the agent.</p><note>
263 /// <p>If you include <code>returnControlInvocationResults</code> in the <code>sessionState</code> field, the <code>inputText</code> field will be ignored.</p>
264 /// </note>
265 pub fn set_input_text(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
266 self.inner = self.inner.set_input_text(input);
267 self
268 }
269 /// <p>The prompt text to send the agent.</p><note>
270 /// <p>If you include <code>returnControlInvocationResults</code> in the <code>sessionState</code> field, the <code>inputText</code> field will be ignored.</p>
271 /// </note>
272 pub fn get_input_text(&self) -> &::std::option::Option<::std::string::String> {
273 self.inner.get_input_text()
274 }
275 /// <p>The unique identifier of the agent memory.</p>
276 pub fn memory_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
277 self.inner = self.inner.memory_id(input.into());
278 self
279 }
280 /// <p>The unique identifier of the agent memory.</p>
281 pub fn set_memory_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
282 self.inner = self.inner.set_memory_id(input);
283 self
284 }
285 /// <p>The unique identifier of the agent memory.</p>
286 pub fn get_memory_id(&self) -> &::std::option::Option<::std::string::String> {
287 self.inner.get_memory_id()
288 }
289 /// <p>Model performance settings for the request.</p>
290 pub fn bedrock_model_configurations(mut self, input: crate::types::BedrockModelConfigurations) -> Self {
291 self.inner = self.inner.bedrock_model_configurations(input);
292 self
293 }
294 /// <p>Model performance settings for the request.</p>
295 pub fn set_bedrock_model_configurations(mut self, input: ::std::option::Option<crate::types::BedrockModelConfigurations>) -> Self {
296 self.inner = self.inner.set_bedrock_model_configurations(input);
297 self
298 }
299 /// <p>Model performance settings for the request.</p>
300 pub fn get_bedrock_model_configurations(&self) -> &::std::option::Option<crate::types::BedrockModelConfigurations> {
301 self.inner.get_bedrock_model_configurations()
302 }
303 /// <p>Specifies the configurations for streaming.</p><note>
304 /// <p>To use agent streaming, you need permissions to perform the <code>bedrock:InvokeModelWithResponseStream</code> action.</p>
305 /// </note>
306 pub fn streaming_configurations(mut self, input: crate::types::StreamingConfigurations) -> Self {
307 self.inner = self.inner.streaming_configurations(input);
308 self
309 }
310 /// <p>Specifies the configurations for streaming.</p><note>
311 /// <p>To use agent streaming, you need permissions to perform the <code>bedrock:InvokeModelWithResponseStream</code> action.</p>
312 /// </note>
313 pub fn set_streaming_configurations(mut self, input: ::std::option::Option<crate::types::StreamingConfigurations>) -> Self {
314 self.inner = self.inner.set_streaming_configurations(input);
315 self
316 }
317 /// <p>Specifies the configurations for streaming.</p><note>
318 /// <p>To use agent streaming, you need permissions to perform the <code>bedrock:InvokeModelWithResponseStream</code> action.</p>
319 /// </note>
320 pub fn get_streaming_configurations(&self) -> &::std::option::Option<crate::types::StreamingConfigurations> {
321 self.inner.get_streaming_configurations()
322 }
323 /// <p>Specifies parameters that control how the service populates the agent prompt for an <code>InvokeAgent</code> request. You can control which aspects of previous invocations in the same agent session the service uses to populate the agent prompt. This gives you more granular control over the contextual history that is used to process the current request.</p>
324 pub fn prompt_creation_configurations(mut self, input: crate::types::PromptCreationConfigurations) -> Self {
325 self.inner = self.inner.prompt_creation_configurations(input);
326 self
327 }
328 /// <p>Specifies parameters that control how the service populates the agent prompt for an <code>InvokeAgent</code> request. You can control which aspects of previous invocations in the same agent session the service uses to populate the agent prompt. This gives you more granular control over the contextual history that is used to process the current request.</p>
329 pub fn set_prompt_creation_configurations(mut self, input: ::std::option::Option<crate::types::PromptCreationConfigurations>) -> Self {
330 self.inner = self.inner.set_prompt_creation_configurations(input);
331 self
332 }
333 /// <p>Specifies parameters that control how the service populates the agent prompt for an <code>InvokeAgent</code> request. You can control which aspects of previous invocations in the same agent session the service uses to populate the agent prompt. This gives you more granular control over the contextual history that is used to process the current request.</p>
334 pub fn get_prompt_creation_configurations(&self) -> &::std::option::Option<crate::types::PromptCreationConfigurations> {
335 self.inner.get_prompt_creation_configurations()
336 }
337 /// <p>The ARN of the resource making the request.</p>
338 pub fn source_arn(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
339 self.inner = self.inner.source_arn(input.into());
340 self
341 }
342 /// <p>The ARN of the resource making the request.</p>
343 pub fn set_source_arn(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
344 self.inner = self.inner.set_source_arn(input);
345 self
346 }
347 /// <p>The ARN of the resource making the request.</p>
348 pub fn get_source_arn(&self) -> &::std::option::Option<::std::string::String> {
349 self.inner.get_source_arn()
350 }
351}