Skip to main content

agent_sdk/types/
agent.rs

1use serde::{Deserialize, Serialize};
2
3/// Configuration for a subagent defined programmatically.
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct AgentDefinition {
6    /// Natural language description of when to use this agent.
7    pub description: String,
8
9    /// The agent's system prompt defining its role and behavior.
10    pub prompt: String,
11
12    /// Array of allowed tool names. If None, inherits all tools from parent.
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub tools: Option<Vec<String>>,
15
16    /// Array of tool names to explicitly disallow for this agent.
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub disallowed_tools: Option<Vec<String>>,
19
20    /// Model override for this agent.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub model: Option<AgentModel>,
23
24    /// MCP server specifications for this agent.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub mcp_servers: Option<Vec<AgentMcpServerSpec>>,
27
28    /// Array of skill names to preload into the agent context.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub skills: Option<Vec<String>>,
31
32    /// Maximum number of agentic turns before stopping.
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub max_turns: Option<u32>,
35}
36
37impl AgentDefinition {
38    pub fn new(description: impl Into<String>, prompt: impl Into<String>) -> Self {
39        Self {
40            description: description.into(),
41            prompt: prompt.into(),
42            tools: None,
43            disallowed_tools: None,
44            model: None,
45            mcp_servers: None,
46            skills: None,
47            max_turns: None,
48        }
49    }
50
51    pub fn with_tools(mut self, tools: Vec<String>) -> Self {
52        self.tools = Some(tools);
53        self
54    }
55
56    pub fn with_model(mut self, model: AgentModel) -> Self {
57        self.model = Some(model);
58        self
59    }
60
61    pub fn with_max_turns(mut self, max_turns: u32) -> Self {
62        self.max_turns = Some(max_turns);
63        self
64    }
65}
66
67/// Model selection for subagents.
68#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
69#[serde(rename_all = "lowercase")]
70pub enum AgentModel {
71    Sonnet,
72    Opus,
73    Haiku,
74    Inherit,
75}
76
77/// MCP server specification for subagents.
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum AgentMcpServerSpec {
81    /// Reference to a parent MCP server by name.
82    Name(String),
83    /// Inline MCP server configuration.
84    Config(std::collections::HashMap<String, serde_json::Value>),
85}
86
87/// Input for the Agent tool (spawning subagents).
88#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct AgentInput {
90    pub description: String,
91    pub prompt: String,
92    pub subagent_type: String,
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub model: Option<AgentModel>,
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub resume: Option<String>,
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub run_in_background: Option<bool>,
99    #[serde(skip_serializing_if = "Option::is_none")]
100    pub max_turns: Option<u32>,
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub name: Option<String>,
103    #[serde(skip_serializing_if = "Option::is_none")]
104    pub isolation: Option<AgentIsolation>,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
108#[serde(rename_all = "lowercase")]
109pub enum AgentIsolation {
110    Worktree,
111}