Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions crates/agent/src/tools/spawn_agent_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Result;
use gpui::{App, SharedString, Task};
use language_model::LanguageModelToolResultContent;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Deserializer, Serialize};
use std::rc::Rc;
use std::sync::Arc;

Expand Down Expand Up @@ -42,10 +42,18 @@ pub struct SpawnAgentToolInput {
/// The prompt for the agent. For new sessions, include full context needed for the task. For follow-ups (with session_id), you can rely on the agent already having the previous message.
pub message: String,
/// Session ID of an existing agent session to continue instead of creating a new one.
#[serde(default)]
#[serde(default, deserialize_with = "deserialize_session_id")]
pub session_id: Option<acp::SessionId>,
}

fn deserialize_session_id<'de, D>(deserializer: D) -> Result<Option<acp::SessionId>, D::Error>
where
D: Deserializer<'de>,
{
let session_id = Option::<acp::SessionId>::deserialize(deserializer)?;
Ok(session_id.filter(|session_id| !session_id.0.is_empty()))
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
#[serde(rename_all = "snake_case")]
Expand Down Expand Up @@ -254,3 +262,20 @@ impl AgentTool for SpawnAgentTool {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn empty_session_id_deserializes_as_none() {
let input: SpawnAgentToolInput = serde_json::from_value(serde_json::json!({
"label": "Minimal reproduction",
"message": "Reply with exactly `spawned`.",
"session_id": "",
}))
.expect("spawn_agent input should deserialize");

assert_eq!(input.session_id, None);
}
}