Skip to main content

strands/agent/
invoke_args.rs

1//! Agent invocation input (`InvokeArgs`).
2
3use crate::types::{ContentBlock, InterruptResponse, InterruptResponseContent, Message};
4
5/// The input of an agent invocation (`InvokeArgs`).
6///
7/// Build it with `.into()` from a string, content blocks, messages or interrupt responses.
8///
9/// ```
10/// use strands::{InterruptResponse, InvokeArgs};
11///
12/// assert!(matches!(InvokeArgs::from("Hello"), InvokeArgs::Text(_)));
13/// let resume: InvokeArgs = vec![InterruptResponse::new("tool:t-1:confirm", "yes")].into();
14/// assert!(matches!(resume, InvokeArgs::InterruptResponses(_)));
15/// ```
16#[derive(Debug, Clone, PartialEq)]
17#[non_exhaustive]
18pub enum InvokeArgs {
19    /// User text, sent as one user message with a text block.
20    Text(String),
21    /// Content blocks, sent as one user message.
22    ContentBlocks(Vec<ContentBlock>),
23    /// Messages appended to the conversation as given.
24    Messages(Vec<Message>),
25    /// Responses that resume an interrupted agent.
26    InterruptResponses(Vec<InterruptResponseContent>),
27}
28
29impl From<&str> for InvokeArgs {
30    fn from(text: &str) -> Self {
31        Self::Text(text.to_owned())
32    }
33}
34
35impl From<&String> for InvokeArgs {
36    fn from(text: &String) -> Self {
37        Self::Text(text.clone())
38    }
39}
40
41impl From<String> for InvokeArgs {
42    fn from(text: String) -> Self {
43        Self::Text(text)
44    }
45}
46
47impl From<Vec<ContentBlock>> for InvokeArgs {
48    fn from(blocks: Vec<ContentBlock>) -> Self {
49        Self::ContentBlocks(blocks)
50    }
51}
52
53impl From<Vec<Message>> for InvokeArgs {
54    fn from(messages: Vec<Message>) -> Self {
55        Self::Messages(messages)
56    }
57}
58
59impl From<Message> for InvokeArgs {
60    fn from(message: Message) -> Self {
61        Self::Messages(vec![message])
62    }
63}
64
65impl From<Vec<InterruptResponseContent>> for InvokeArgs {
66    fn from(responses: Vec<InterruptResponseContent>) -> Self {
67        Self::InterruptResponses(responses)
68    }
69}
70
71impl From<Vec<InterruptResponse>> for InvokeArgs {
72    fn from(responses: Vec<InterruptResponse>) -> Self {
73        Self::InterruptResponses(responses.into_iter().map(InterruptResponseContent::from).collect())
74    }
75}