strands_agents/types/
agent.rs

1//! Agent-related type definitions for the SDK.
2
3use super::content::{ContentBlock, Messages};
4use super::interrupt::InterruptResponseContent;
5
6/// Input type for agent invocation.
7#[derive(Debug, Clone)]
8pub enum AgentInput {
9    /// Simple text input.
10    Text(String),
11    /// Content blocks input.
12    ContentBlocks(Vec<ContentBlock>),
13    /// Interrupt response content.
14    InterruptResponses(Vec<InterruptResponseContent>),
15    /// Full messages input.
16    Messages(Messages),
17    /// No input (resume).
18    None,
19}
20
21impl From<String> for AgentInput {
22    fn from(s: String) -> Self {
23        Self::Text(s)
24    }
25}
26
27impl From<&str> for AgentInput {
28    fn from(s: &str) -> Self {
29        Self::Text(s.to_string())
30    }
31}
32
33impl From<Vec<ContentBlock>> for AgentInput {
34    fn from(blocks: Vec<ContentBlock>) -> Self {
35        Self::ContentBlocks(blocks)
36    }
37}
38
39impl From<Vec<InterruptResponseContent>> for AgentInput {
40    fn from(responses: Vec<InterruptResponseContent>) -> Self {
41        Self::InterruptResponses(responses)
42    }
43}
44
45impl From<Messages> for AgentInput {
46    fn from(messages: Messages) -> Self {
47        Self::Messages(messages)
48    }
49}
50
51impl From<Option<String>> for AgentInput {
52    fn from(opt: Option<String>) -> Self {
53        match opt {
54            Some(s) => Self::Text(s),
55            None => Self::None,
56        }
57    }
58}
59
60impl Default for AgentInput {
61    fn default() -> Self {
62        Self::None
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_agent_input_from_string() {
72        let input: AgentInput = "Hello".into();
73        assert!(matches!(input, AgentInput::Text(_)));
74    }
75
76    #[test]
77    fn test_agent_input_from_none() {
78        let input: AgentInput = None::<String>.into();
79        assert!(matches!(input, AgentInput::None));
80    }
81
82    #[test]
83    fn test_agent_input_default() {
84        let input = AgentInput::default();
85        assert!(matches!(input, AgentInput::None));
86    }
87}
88