diff --git a/src/main/java/com/ioa/IoASystem.java b/src/main/java/com/ioa/IoASystem.java index ade07e2..6b0a4c1 100644 --- a/src/main/java/com/ioa/IoASystem.java +++ b/src/main/java/com/ioa/IoASystem.java @@ -10,10 +10,13 @@ import com.ioa.tool.ToolRegistry; import com.ioa.model.BedrockLanguageModel; import com.ioa.service.WebSocketService; import com.ioa.tool.Tool; +import com.ioa.util.TreeOfThought; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.messaging.simp.SimpMessagingTemplate; import java.lang.reflect.Method; import java.util.Arrays; @@ -46,8 +49,13 @@ public class IoASystem { } @Bean - public TeamFormation teamFormation(AgentRegistry agentRegistry, BedrockLanguageModel model) { - return new TeamFormation(agentRegistry, model); + public TreeOfThought treeOfThought(BedrockLanguageModel model, WebSocketService webSocketService) { + return new TreeOfThought(model, webSocketService); + } + + @Bean + public TeamFormation teamFormation(AgentRegistry agentRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService) { + return new TeamFormation(agentRegistry, treeOfThought, webSocketService); } @Bean @@ -56,17 +64,17 @@ public class IoASystem { } @Bean - public WebSocketService webSocketService() { - return new WebSocketService(); + public WebSocketService webSocketService(SimpMessagingTemplate messagingTemplate) { + return new WebSocketService(messagingTemplate); } public static void main(String[] args) { - var context = SpringApplication.run(IoASystem.class, args); - + ConfigurableApplicationContext context = SpringApplication.run(IoASystem.class, args); + AgentRegistry agentRegistry = context.getBean(AgentRegistry.class); TeamFormation teamFormation = context.getBean(TeamFormation.class); TaskManager taskManager = context.getBean(TaskManager.class); - + // Register all agents agentRegistry.registerAgent("agent1", new AgentInfo("agent1", "General Assistant", Arrays.asList("general", "search"), @@ -92,32 +100,32 @@ public class IoASystem { // Create all tasks List tasks = Arrays.asList( - // new Task("task1", "Plan a weekend trip to Paris", - // Arrays.asList("travel", "booking"), - // Arrays.asList("bookTravel", "findRestaurants", "getWeather")), - // new Task("task2", "Organize a corporate team-building event in New York", - // Arrays.asList("event planning", "team management"), - // Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment")), - // new Task("task3", "Develop a personalized fitness and nutrition plan", - // Arrays.asList("health", "nutrition"), - // Arrays.asList("getWeather", "findFitnessClasses", "getRecipe")), - // new Task("task4", "Research and summarize recent advancements in renewable energy", - // Arrays.asList("research", "writing"), - // Arrays.asList("webSearch", "getNewsUpdates", "translate")), - // new Task("task5", "Plan and execute a social media marketing campaign for a new product launch", - // Arrays.asList("marketing", "social media"), - // Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment")), - // new Task("task6", "Assist in planning a multi-city European vacation for a family of four", - // Arrays.asList("travel", "family planning"), - // Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants")), + new Task("task1", "Plan a weekend trip to Paris", + Arrays.asList("travel", "booking"), + Arrays.asList("bookTravel", "findRestaurants", "getWeather")), + new Task("task2", "Organize a corporate team-building event in New York", + Arrays.asList("event planning", "team management"), + Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment")), + new Task("task3", "Develop a personalized fitness and nutrition plan", + Arrays.asList("health", "nutrition"), + Arrays.asList("getWeather", "findFitnessClasses", "getRecipe")), + new Task("task4", "Research and summarize recent advancements in renewable energy", + Arrays.asList("research", "writing"), + Arrays.asList("webSearch", "getNewsUpdates", "translate")), + new Task("task5", "Plan and execute a social media marketing campaign for a new product launch", + Arrays.asList("marketing", "social media"), + Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment")), + new Task("task6", "Assist in planning a multi-city European vacation for a family of four", + Arrays.asList("travel", "family planning"), + Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants")), - // new Task("task7", "Organize an international tech conference with virtual and in-person components", - // Arrays.asList("event planning", "tech expertise", "marketing", "travel coordination", "content creation"), - // Arrays.asList("scheduleAppointment", "webSearch", "bookTravel", "getWeather", "findRestaurants", "getNewsUpdates")), + new Task("task7", "Organize an international tech conference with virtual and in-person components", + Arrays.asList("event planning", "tech expertise", "marketing", "travel coordination", "content creation"), + Arrays.asList("scheduleAppointment", "webSearch", "bookTravel", "getWeather", "findRestaurants", "getNewsUpdates")), - // new Task("task8", "Develop and launch a multi-lingual mobile app for sustainable tourism", - // Arrays.asList("software development", "travel", "language expertise", "environmental science", "user experience design"), - // Arrays.asList("webSearch", "translate", "getWeather", "findRestaurants", "getNewsUpdates", "compareProductPrices")), + new Task("task8", "Develop and launch a multi-lingual mobile app for sustainable tourism", + Arrays.asList("software development", "travel", "language expertise", "environmental science", "user experience design"), + Arrays.asList("webSearch", "translate", "getWeather", "findRestaurants", "getNewsUpdates", "compareProductPrices")), new Task("task9", "Create a comprehensive health and wellness program for a large corporation, including mental health support", Arrays.asList("health", "nutrition", "psychology", "corporate wellness", "data analysis"), diff --git a/src/main/java/com/ioa/service/WebSocketService.java b/src/main/java/com/ioa/service/WebSocketService.java index 4e144b8..0591f69 100644 --- a/src/main/java/com/ioa/service/WebSocketService.java +++ b/src/main/java/com/ioa/service/WebSocketService.java @@ -1,14 +1,16 @@ package com.ioa.service; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; @Service public class WebSocketService { - @Autowired - private SimpMessagingTemplate messagingTemplate; + private final SimpMessagingTemplate messagingTemplate; + + public WebSocketService(SimpMessagingTemplate messagingTemplate) { + this.messagingTemplate = messagingTemplate; + } public void sendUpdate(String topic, Object payload) { messagingTemplate.convertAndSend("/topic/" + topic, payload); diff --git a/src/main/java/com/ioa/team/TeamFormation.java b/src/main/java/com/ioa/team/TeamFormation.java index 60edfe2..10d2913 100644 --- a/src/main/java/com/ioa/team/TeamFormation.java +++ b/src/main/java/com/ioa/team/TeamFormation.java @@ -5,8 +5,9 @@ import com.ioa.agent.AgentRegistry; import com.ioa.model.BedrockLanguageModel; import com.ioa.task.Task; import com.ioa.util.TreeOfThought; + import com.ioa.service.WebSocketService; -import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.stereotype.Component; import java.util.*; @@ -14,15 +15,14 @@ import java.util.stream.Collectors; @Component public class TeamFormation { - private AgentRegistry agentRegistry; - private TreeOfThought treeOfThought; - - @Autowired - private WebSocketService webSocketService; + private final AgentRegistry agentRegistry; + private final TreeOfThought treeOfThought; + private final WebSocketService webSocketService; - public TeamFormation(AgentRegistry agentRegistry, BedrockLanguageModel model) { + public TeamFormation(AgentRegistry agentRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService) { this.agentRegistry = agentRegistry; - this.treeOfThought = new TreeOfThought(model); + this.treeOfThought = treeOfThought; + this.webSocketService = webSocketService; } public List formTeam(Task task) { diff --git a/src/main/java/com/ioa/util/TreeOfThought.java b/src/main/java/com/ioa/util/TreeOfThought.java index a40a061..f9dc6d7 100644 --- a/src/main/java/com/ioa/util/TreeOfThought.java +++ b/src/main/java/com/ioa/util/TreeOfThought.java @@ -2,7 +2,6 @@ package com.ioa.util; import com.ioa.model.BedrockLanguageModel; import com.ioa.service.WebSocketService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -13,12 +12,11 @@ import java.util.Map; @Component public class TreeOfThought { private final BedrockLanguageModel model; - - @Autowired - private WebSocketService webSocketService; + private final WebSocketService webSocketService; - public TreeOfThought(BedrockLanguageModel model) { + public TreeOfThought(BedrockLanguageModel model, WebSocketService webSocketService) { this.model = model; + this.webSocketService = webSocketService; } public String reason(String task, int depth, int branches) { diff --git a/target/classes/com/ioa/IoASystem.class b/target/classes/com/ioa/IoASystem.class index b3a4301..ab713d3 100644 Binary files a/target/classes/com/ioa/IoASystem.class and b/target/classes/com/ioa/IoASystem.class differ diff --git a/target/classes/com/ioa/service/WebSocketService.class b/target/classes/com/ioa/service/WebSocketService.class index d49729f..8e1d367 100644 Binary files a/target/classes/com/ioa/service/WebSocketService.class and b/target/classes/com/ioa/service/WebSocketService.class differ diff --git a/target/classes/com/ioa/team/TeamFormation.class b/target/classes/com/ioa/team/TeamFormation.class index 66f7302..1325d7d 100644 Binary files a/target/classes/com/ioa/team/TeamFormation.class and b/target/classes/com/ioa/team/TeamFormation.class differ diff --git a/target/classes/com/ioa/util/TreeOfThought.class b/target/classes/com/ioa/util/TreeOfThought.class index d9fbd40..6050784 100644 Binary files a/target/classes/com/ioa/util/TreeOfThought.class and b/target/classes/com/ioa/util/TreeOfThought.class differ