Rename agent to thread in tests to avoid confusion
Preparing for the introduction of a new Agent type that will implement the agent-client-protocol Agent trait. The existing Thread type represents individual conversation sessions, while Agent will manage multiple sessions.
This commit is contained in:
parent
387ee1be8d
commit
9e1c7fdfea
1 changed files with 37 additions and 37 deletions
|
@ -17,17 +17,17 @@ use test_tools::*;
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_echo(cx: &mut TestAppContext) {
|
async fn test_echo(cx: &mut TestAppContext) {
|
||||||
let AgentTest { model, agent, .. } = setup(cx).await;
|
let ThreadTest { model, thread, .. } = setup(cx).await;
|
||||||
|
|
||||||
let events = agent
|
let events = thread
|
||||||
.update(cx, |agent, cx| {
|
.update(cx, |thread, cx| {
|
||||||
agent.send(model.clone(), "Testing: Reply with 'Hello'", cx)
|
thread.send(model.clone(), "Testing: Reply with 'Hello'", cx)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
.await;
|
.await;
|
||||||
agent.update(cx, |agent, _cx| {
|
thread.update(cx, |thread, _cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
agent.messages().last().unwrap().content,
|
thread.messages().last().unwrap().content,
|
||||||
vec![MessageContent::Text("Hello".to_string())]
|
vec![MessageContent::Text("Hello".to_string())]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -36,13 +36,13 @@ async fn test_echo(cx: &mut TestAppContext) {
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_basic_tool_calls(cx: &mut TestAppContext) {
|
async fn test_basic_tool_calls(cx: &mut TestAppContext) {
|
||||||
let AgentTest { model, agent, .. } = setup(cx).await;
|
let ThreadTest { model, thread, .. } = setup(cx).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 = agent
|
let events = thread
|
||||||
.update(cx, |agent, cx| {
|
.update(cx, |thread, cx| {
|
||||||
agent.add_tool(EchoTool);
|
thread.add_tool(EchoTool);
|
||||||
agent.send(
|
thread.send(
|
||||||
model.clone(),
|
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,
|
||||||
|
@ -56,11 +56,11 @@ async fn test_basic_tool_calls(cx: &mut TestAppContext) {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Test a tool calls that's likely to complete *after* streaming stops.
|
// Test a tool calls that's likely to complete *after* streaming stops.
|
||||||
let events = agent
|
let events = thread
|
||||||
.update(cx, |agent, cx| {
|
.update(cx, |thread, cx| {
|
||||||
agent.remove_tool(&AgentTool::name(&EchoTool));
|
thread.remove_tool(&AgentTool::name(&EchoTool));
|
||||||
agent.add_tool(DelayTool);
|
thread.add_tool(DelayTool);
|
||||||
agent.send(
|
thread.send(
|
||||||
model.clone(),
|
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,
|
||||||
|
@ -72,8 +72,8 @@ async fn test_basic_tool_calls(cx: &mut TestAppContext) {
|
||||||
stop_events(events),
|
stop_events(events),
|
||||||
vec![StopReason::ToolUse, StopReason::EndTurn]
|
vec![StopReason::ToolUse, StopReason::EndTurn]
|
||||||
);
|
);
|
||||||
agent.update(cx, |agent, _cx| {
|
thread.update(cx, |thread, _cx| {
|
||||||
assert!(agent
|
assert!(thread
|
||||||
.messages()
|
.messages()
|
||||||
.last()
|
.last()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -91,20 +91,20 @@ async fn test_basic_tool_calls(cx: &mut TestAppContext) {
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_streaming_tool_calls(cx: &mut TestAppContext) {
|
async fn test_streaming_tool_calls(cx: &mut TestAppContext) {
|
||||||
let AgentTest { model, agent, .. } = setup(cx).await;
|
let ThreadTest { model, thread, .. } = setup(cx).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 = agent.update(cx, |agent, cx| {
|
let mut events = thread.update(cx, |thread, cx| {
|
||||||
agent.add_tool(WordListTool);
|
thread.add_tool(WordListTool);
|
||||||
agent.send(model.clone(), "Test the word_list tool.", cx)
|
thread.send(model.clone(), "Test the word_list tool.", cx)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut saw_partial_tool_use = false;
|
let mut saw_partial_tool_use = false;
|
||||||
while let Some(event) = events.next().await {
|
while let Some(event) = events.next().await {
|
||||||
if let Ok(LanguageModelCompletionEvent::ToolUse(tool_use_event)) = event {
|
if let Ok(LanguageModelCompletionEvent::ToolUse(tool_use_event)) = event {
|
||||||
agent.update(cx, |agent, _cx| {
|
thread.update(cx, |thread, _cx| {
|
||||||
// Look for a tool use in the agent's last message
|
// Look for a tool use in the thread's last message
|
||||||
let last_content = agent.messages().last().unwrap().content.last().unwrap();
|
let last_content = thread.messages().last().unwrap().content.last().unwrap();
|
||||||
if let MessageContent::ToolUse(last_tool_use) = last_content {
|
if let MessageContent::ToolUse(last_tool_use) = last_content {
|
||||||
assert_eq!(last_tool_use.name.as_ref(), "word_list");
|
assert_eq!(last_tool_use.name.as_ref(), "word_list");
|
||||||
if tool_use_event.is_input_complete {
|
if tool_use_event.is_input_complete {
|
||||||
|
@ -138,13 +138,13 @@ async fn test_streaming_tool_calls(cx: &mut TestAppContext) {
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_concurrent_tool_calls(cx: &mut TestAppContext) {
|
async fn test_concurrent_tool_calls(cx: &mut TestAppContext) {
|
||||||
let AgentTest { model, agent, .. } = setup(cx).await;
|
let ThreadTest { model, thread, .. } = setup(cx).await;
|
||||||
|
|
||||||
// Test concurrent tool calls with different delay times
|
// Test concurrent tool calls with different delay times
|
||||||
let events = agent
|
let events = thread
|
||||||
.update(cx, |agent, cx| {
|
.update(cx, |thread, cx| {
|
||||||
agent.add_tool(DelayTool);
|
thread.add_tool(DelayTool);
|
||||||
agent.send(
|
thread.send(
|
||||||
model.clone(),
|
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,
|
||||||
|
@ -169,8 +169,8 @@ async fn test_concurrent_tool_calls(cx: &mut TestAppContext) {
|
||||||
panic!("Expected either 1 or 2 tool uses followed by end turn");
|
panic!("Expected either 1 or 2 tool uses followed by end turn");
|
||||||
}
|
}
|
||||||
|
|
||||||
agent.update(cx, |agent, _cx| {
|
thread.update(cx, |thread, _cx| {
|
||||||
let last_message = agent.messages().last().unwrap();
|
let last_message = thread.messages().last().unwrap();
|
||||||
let text = last_message
|
let text = last_message
|
||||||
.content
|
.content
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -200,16 +200,16 @@ fn stop_events(
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AgentTest {
|
struct ThreadTest {
|
||||||
model: Arc<dyn LanguageModel>,
|
model: Arc<dyn LanguageModel>,
|
||||||
agent: Entity<Thread>,
|
thread: Entity<Thread>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn setup(cx: &mut TestAppContext) -> AgentTest {
|
async fn setup(cx: &mut TestAppContext) -> ThreadTest {
|
||||||
cx.executor().allow_parking();
|
cx.executor().allow_parking();
|
||||||
cx.update(settings::init);
|
cx.update(settings::init);
|
||||||
let templates = Templates::new();
|
let templates = Templates::new();
|
||||||
let agent = cx.new(|_| Thread::new(templates));
|
let thread = cx.new(|_| Thread::new(templates));
|
||||||
|
|
||||||
let model = cx
|
let model = cx
|
||||||
.update(|cx| {
|
.update(|cx| {
|
||||||
|
@ -239,7 +239,7 @@ async fn setup(cx: &mut TestAppContext) -> AgentTest {
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
AgentTest { model, agent }
|
ThreadTest { model, thread }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue