agent2: Remove model param from Thread::send method (#35936)

It instead uses the currently selected model

Release Notes:

- N/A
This commit is contained in:
Ben Brandt 2025-08-09 23:40:44 +02:00 committed by GitHub
parent ce39644cbd
commit 5901aec40a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 22 deletions

View file

@ -491,8 +491,7 @@ impl acp_thread::AgentConnection for NativeAgentConnection {
// Send to thread // Send to thread
log::info!("Sending message to thread with model: {:?}", model.name()); log::info!("Sending message to thread with model: {:?}", model.name());
let mut response_stream = let mut response_stream = thread.update(cx, |thread, cx| thread.send(message, cx))?;
thread.update(cx, |thread, cx| thread.send(model, message, cx))?;
// Handle response stream and forward to session.acp_thread // Handle response stream and forward to session.acp_thread
while let Some(result) = response_stream.next().await { while let Some(result) = response_stream.next().await {

View file

@ -29,11 +29,11 @@ use test_tools::*;
#[gpui::test] #[gpui::test]
#[ignore = "can't run on CI yet"] #[ignore = "can't run on CI yet"]
async fn test_echo(cx: &mut TestAppContext) { async fn test_echo(cx: &mut TestAppContext) {
let ThreadTest { model, thread, .. } = setup(cx, TestModel::Sonnet4).await; let ThreadTest { thread, .. } = setup(cx, TestModel::Sonnet4).await;
let events = thread let events = thread
.update(cx, |thread, cx| { .update(cx, |thread, cx| {
thread.send(model.clone(), "Testing: Reply with 'Hello'", cx) thread.send("Testing: Reply with 'Hello'", cx)
}) })
.collect() .collect()
.await; .await;
@ -49,12 +49,11 @@ async fn test_echo(cx: &mut TestAppContext) {
#[gpui::test] #[gpui::test]
#[ignore = "can't run on CI yet"] #[ignore = "can't run on CI yet"]
async fn test_thinking(cx: &mut TestAppContext) { async fn test_thinking(cx: &mut TestAppContext) {
let ThreadTest { model, thread, .. } = setup(cx, TestModel::Sonnet4Thinking).await; let ThreadTest { thread, .. } = setup(cx, TestModel::Sonnet4Thinking).await;
let events = thread let events = thread
.update(cx, |thread, cx| { .update(cx, |thread, cx| {
thread.send( thread.send(
model.clone(),
indoc! {" indoc! {"
Testing: Testing:
@ -91,7 +90,7 @@ async fn test_system_prompt(cx: &mut TestAppContext) {
project_context.borrow_mut().shell = "test-shell".into(); project_context.borrow_mut().shell = "test-shell".into();
thread.update(cx, |thread, _| thread.add_tool(EchoTool)); thread.update(cx, |thread, _| thread.add_tool(EchoTool));
thread.update(cx, |thread, cx| thread.send(model.clone(), "abc", cx)); thread.update(cx, |thread, cx| thread.send("abc", cx));
cx.run_until_parked(); cx.run_until_parked();
let mut pending_completions = fake_model.pending_completions(); let mut pending_completions = fake_model.pending_completions();
assert_eq!( assert_eq!(
@ -121,14 +120,13 @@ async fn test_system_prompt(cx: &mut TestAppContext) {
#[gpui::test] #[gpui::test]
#[ignore = "can't run on CI yet"] #[ignore = "can't run on CI yet"]
async fn test_basic_tool_calls(cx: &mut TestAppContext) { async fn test_basic_tool_calls(cx: &mut TestAppContext) {
let ThreadTest { model, thread, .. } = setup(cx, TestModel::Sonnet4).await; let ThreadTest { thread, .. } = setup(cx, TestModel::Sonnet4).await;
// Test a tool call that's likely to complete *before* streaming stops. // Test a tool call that's likely to complete *before* streaming stops.
let events = thread let events = thread
.update(cx, |thread, cx| { .update(cx, |thread, cx| {
thread.add_tool(EchoTool); thread.add_tool(EchoTool);
thread.send( thread.send(
model.clone(),
"Now test the echo tool with 'Hello'. Does it work? Say 'Yes' or 'No'.", "Now test the echo tool with 'Hello'. Does it work? Say 'Yes' or 'No'.",
cx, cx,
) )
@ -143,7 +141,6 @@ async fn test_basic_tool_calls(cx: &mut TestAppContext) {
thread.remove_tool(&AgentTool::name(&EchoTool)); thread.remove_tool(&AgentTool::name(&EchoTool));
thread.add_tool(DelayTool); thread.add_tool(DelayTool);
thread.send( thread.send(
model.clone(),
"Now call the delay tool with 200ms. When the timer goes off, then you echo the output of the tool.", "Now call the delay tool with 200ms. When the timer goes off, then you echo the output of the tool.",
cx, cx,
) )
@ -171,12 +168,12 @@ async fn test_basic_tool_calls(cx: &mut TestAppContext) {
#[gpui::test] #[gpui::test]
#[ignore = "can't run on CI yet"] #[ignore = "can't run on CI yet"]
async fn test_streaming_tool_calls(cx: &mut TestAppContext) { async fn test_streaming_tool_calls(cx: &mut TestAppContext) {
let ThreadTest { model, thread, .. } = setup(cx, TestModel::Sonnet4).await; let ThreadTest { thread, .. } = setup(cx, TestModel::Sonnet4).await;
// Test a tool call that's likely to complete *before* streaming stops. // Test a tool call that's likely to complete *before* streaming stops.
let mut events = thread.update(cx, |thread, cx| { let mut events = thread.update(cx, |thread, cx| {
thread.add_tool(WordListTool); thread.add_tool(WordListTool);
thread.send(model.clone(), "Test the word_list tool.", cx) thread.send("Test the word_list tool.", cx)
}); });
let mut saw_partial_tool_use = false; let mut saw_partial_tool_use = false;
@ -223,7 +220,7 @@ async fn test_tool_authorization(cx: &mut TestAppContext) {
let mut events = thread.update(cx, |thread, cx| { let mut events = thread.update(cx, |thread, cx| {
thread.add_tool(ToolRequiringPermission); thread.add_tool(ToolRequiringPermission);
thread.send(model.clone(), "abc", cx) thread.send("abc", cx)
}); });
cx.run_until_parked(); cx.run_until_parked();
fake_model.send_last_completion_stream_event(LanguageModelCompletionEvent::ToolUse( fake_model.send_last_completion_stream_event(LanguageModelCompletionEvent::ToolUse(
@ -290,7 +287,7 @@ async fn test_tool_hallucination(cx: &mut TestAppContext) {
let ThreadTest { model, thread, .. } = setup(cx, TestModel::Fake).await; let ThreadTest { model, thread, .. } = setup(cx, TestModel::Fake).await;
let fake_model = model.as_fake(); let fake_model = model.as_fake();
let mut events = thread.update(cx, |thread, cx| thread.send(model.clone(), "abc", cx)); let mut events = thread.update(cx, |thread, cx| thread.send("abc", cx));
cx.run_until_parked(); cx.run_until_parked();
fake_model.send_last_completion_stream_event(LanguageModelCompletionEvent::ToolUse( fake_model.send_last_completion_stream_event(LanguageModelCompletionEvent::ToolUse(
LanguageModelToolUse { LanguageModelToolUse {
@ -375,14 +372,13 @@ async fn next_tool_call_authorization(
#[gpui::test] #[gpui::test]
#[ignore = "can't run on CI yet"] #[ignore = "can't run on CI yet"]
async fn test_concurrent_tool_calls(cx: &mut TestAppContext) { async fn test_concurrent_tool_calls(cx: &mut TestAppContext) {
let ThreadTest { model, thread, .. } = setup(cx, TestModel::Sonnet4).await; let ThreadTest { thread, .. } = setup(cx, TestModel::Sonnet4).await;
// Test concurrent tool calls with different delay times // Test concurrent tool calls with different delay times
let events = thread let events = thread
.update(cx, |thread, cx| { .update(cx, |thread, cx| {
thread.add_tool(DelayTool); thread.add_tool(DelayTool);
thread.send( thread.send(
model.clone(),
"Call the delay tool twice in the same message. Once with 100ms. Once with 300ms. When both timers are complete, describe the outputs.", "Call the delay tool twice in the same message. Once with 100ms. Once with 300ms. When both timers are complete, describe the outputs.",
cx, cx,
) )
@ -414,13 +410,12 @@ async fn test_concurrent_tool_calls(cx: &mut TestAppContext) {
#[gpui::test] #[gpui::test]
#[ignore = "can't run on CI yet"] #[ignore = "can't run on CI yet"]
async fn test_cancellation(cx: &mut TestAppContext) { async fn test_cancellation(cx: &mut TestAppContext) {
let ThreadTest { model, thread, .. } = setup(cx, TestModel::Sonnet4).await; let ThreadTest { thread, .. } = setup(cx, TestModel::Sonnet4).await;
let mut events = thread.update(cx, |thread, cx| { let mut events = thread.update(cx, |thread, cx| {
thread.add_tool(InfiniteTool); thread.add_tool(InfiniteTool);
thread.add_tool(EchoTool); thread.add_tool(EchoTool);
thread.send( thread.send(
model.clone(),
"Call the echo tool and then call the infinite tool, then explain their output", "Call the echo tool and then call the infinite tool, then explain their output",
cx, cx,
) )
@ -466,7 +461,7 @@ async fn test_cancellation(cx: &mut TestAppContext) {
// Ensure we can still send a new message after cancellation. // Ensure we can still send a new message after cancellation.
let events = thread let events = thread
.update(cx, |thread, cx| { .update(cx, |thread, cx| {
thread.send(model.clone(), "Testing: reply with 'Hello' then stop.", cx) thread.send("Testing: reply with 'Hello' then stop.", cx)
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.await; .await;
@ -484,7 +479,7 @@ async fn test_refusal(cx: &mut TestAppContext) {
let ThreadTest { model, thread, .. } = setup(cx, TestModel::Fake).await; let ThreadTest { model, thread, .. } = setup(cx, TestModel::Fake).await;
let fake_model = model.as_fake(); let fake_model = model.as_fake();
let events = thread.update(cx, |thread, cx| thread.send(model.clone(), "Hello", cx)); let events = thread.update(cx, |thread, cx| thread.send("Hello", cx));
cx.run_until_parked(); cx.run_until_parked();
thread.read_with(cx, |thread, _| { thread.read_with(cx, |thread, _| {
assert_eq!( assert_eq!(
@ -648,7 +643,7 @@ async fn test_tool_updates_to_completion(cx: &mut TestAppContext) {
thread.update(cx, |thread, _cx| thread.add_tool(ThinkingTool)); thread.update(cx, |thread, _cx| thread.add_tool(ThinkingTool));
let fake_model = model.as_fake(); let fake_model = model.as_fake();
let mut events = thread.update(cx, |thread, cx| thread.send(model.clone(), "Think", cx)); let mut events = thread.update(cx, |thread, cx| thread.send("Think", cx));
cx.run_until_parked(); cx.run_until_parked();
// Simulate streaming partial input. // Simulate streaming partial input.

View file

@ -200,11 +200,11 @@ impl Thread {
/// The returned channel will report all the occurrences in which the model stops before erroring or ending its turn. /// The returned channel will report all the occurrences in which the model stops before erroring or ending its turn.
pub fn send( pub fn send(
&mut self, &mut self,
model: Arc<dyn LanguageModel>,
content: impl Into<MessageContent>, content: impl Into<MessageContent>,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> mpsc::UnboundedReceiver<Result<AgentResponseEvent, LanguageModelCompletionError>> { ) -> mpsc::UnboundedReceiver<Result<AgentResponseEvent, LanguageModelCompletionError>> {
let content = content.into(); let content = content.into();
let model = self.selected_model.clone();
log::info!("Thread::send called with model: {:?}", model.name()); log::info!("Thread::send called with model: {:?}", model.name());
log::debug!("Thread::send content: {:?}", content); log::debug!("Thread::send content: {:?}", content);