-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmultiagent_test.go
More file actions
49 lines (41 loc) · 1.44 KB
/
multiagent_test.go
File metadata and controls
49 lines (41 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package multiagent
import (
"testing"
)
func TestCrewExecution(t *testing.T) {
// Create a new Crew instance
crew := NewCrew()
// Define a simple agent function
agentFunc := func(input string, tasks []*Task) string {
return "Completed: " + input
}
// Create an agent and add it to the crew
agent := &Agent{Name: "Agent1", Function: agentFunc}
crew.AddAgent(agent)
// Create Tasks
task1 := &Task{Name: "Task1", Description: "First Task"}
task2 := &Task{Name: "Task2", Description: "Second Task"}
task3 := &Task{Name: "Task3", Description: "Third Task"}
// Add Tasks to the crew with dependencies
if err := crew.AddTask(task1, "Agent1", nil); err != nil {
t.Fatalf("Failed to add Task1: %v", err)
}
if err := crew.AddTask(task2, "Agent1", []string{"Task1"}); err != nil {
t.Fatalf("Failed to add Task2: %v", err)
}
if err := crew.AddTask(task3, "Agent1", []string{"Task2"}); err != nil {
t.Fatalf("Failed to add Task3: %v", err)
}
// Execute all Tasks
crew.Kickoff()
// Validate execution order
if output := task1.GetOutput(); output == nil || *output != "Completed: First Task" {
t.Errorf("Unexpected output for Task1: got %v", output)
}
if output := task2.GetOutput(); output == nil || *output != "Completed: Second Task" {
t.Errorf("Unexpected output for Task2: got %v", output)
}
if output := task3.GetOutput(); output == nil || *output != "Completed: Third Task" {
t.Errorf("Unexpected output for Task3: got %v", output)
}
}