From 9467e9556377e76353b45b76dd0541ffd13c074f Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Tue, 24 Mar 2026 22:28:21 +0000 Subject: [PATCH] agent: Mark subagent completions with Subagent intent (#52350) (cherry-pick to preview) (#52358) Cherry-pick of #52350 to preview ---- ## Context Ensure subagent threads build requests with the Subagent intent instead of UserPrompt. This allows us to properly attribute this as a tool call for certain providers instead of a user request. ## Self-Review Checklist - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - copilot_chat: Fix subagent requests being marked as user requests. Co-authored-by: Ben Brandt --- crates/agent/src/tests/mod.rs | 5 +++++ crates/agent/src/thread.rs | 7 +++++++ crates/cloud_llm_client/src/cloud_llm_client.rs | 1 + crates/language_models/src/provider/copilot_chat.rs | 4 +++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/agent/src/tests/mod.rs b/crates/agent/src/tests/mod.rs index 7482ffda5854525f78efb2fcd3fd8cc9f757e3be..2dc2ad9e9bb47c2cf9e09a260513e3f8ac4454f5 100644 --- a/crates/agent/src/tests/mod.rs +++ b/crates/agent/src/tests/mod.rs @@ -5039,6 +5039,11 @@ async fn test_subagent_thread_inherits_parent_thread_properties(cx: &mut TestApp subagent_thread.parent_thread_id(), Some(parent_thread.read(cx).id().clone()) ); + + let request = subagent_thread + .build_completion_request(CompletionIntent::UserPrompt, cx) + .unwrap(); + assert_eq!(request.intent, Some(CompletionIntent::Subagent)); }); } diff --git a/crates/agent/src/thread.rs b/crates/agent/src/thread.rs index 2f6eee28b6ab7311bde461170e56704daa5b7b9f..6fb47ac5cd7e95a76760d615844e60911d522ab8 100644 --- a/crates/agent/src/thread.rs +++ b/crates/agent/src/thread.rs @@ -2646,6 +2646,13 @@ impl Thread { completion_intent: CompletionIntent, cx: &App, ) -> Result { + let completion_intent = + if self.is_subagent() && completion_intent == CompletionIntent::UserPrompt { + CompletionIntent::Subagent + } else { + completion_intent + }; + let model = self.model().context("No language model configured")?; let tools = if let Some(turn) = self.running_turn.as_ref() { turn.tools diff --git a/crates/cloud_llm_client/src/cloud_llm_client.rs b/crates/cloud_llm_client/src/cloud_llm_client.rs index d2d25ff5b84ef524f4e573a13149b26fe32fc4a5..beca3ca74a9bc93dd3bef2be6fd25e2d637e1501 100644 --- a/crates/cloud_llm_client/src/cloud_llm_client.rs +++ b/crates/cloud_llm_client/src/cloud_llm_client.rs @@ -193,6 +193,7 @@ pub enum EditPredictionRejectReason { #[serde(rename_all = "snake_case")] pub enum CompletionIntent { UserPrompt, + Subagent, ToolResults, ThreadSummarization, ThreadContextSummarization, diff --git a/crates/language_models/src/provider/copilot_chat.rs b/crates/language_models/src/provider/copilot_chat.rs index 286eb872795642be47dfd46f16e561dcd53f93dc..8e38b7cb470ae4fa5e970a1b760f5f2fe71a6023 100644 --- a/crates/language_models/src/provider/copilot_chat.rs +++ b/crates/language_models/src/provider/copilot_chat.rs @@ -357,7 +357,8 @@ impl LanguageModel for CopilotChatLanguageModel { | CompletionIntent::TerminalInlineAssist | CompletionIntent::GenerateGitCommitMessage => true, - CompletionIntent::ToolResults + CompletionIntent::Subagent + | CompletionIntent::ToolResults | CompletionIntent::ThreadSummarization | CompletionIntent::CreateFile | CompletionIntent::EditFile => false, @@ -1072,6 +1073,7 @@ fn compute_thinking_budget( fn intent_to_chat_location(intent: Option) -> ChatLocation { match intent { Some(CompletionIntent::UserPrompt) => ChatLocation::Agent, + Some(CompletionIntent::Subagent) => ChatLocation::Agent, Some(CompletionIntent::ToolResults) => ChatLocation::Agent, Some(CompletionIntent::ThreadSummarization) => ChatLocation::Panel, Some(CompletionIntent::ThreadContextSummarization) => ChatLocation::Panel,