diff --git a/frontend/src/App.js b/frontend/src/App.js index 333dd70..bcc6fc8 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -2,13 +2,15 @@ import React, { useEffect, useState } from 'react'; import { connectWebSocket, subscribeToTopic } from './services/websocket'; import AgentNetworkGraph from './components/AgentNetworkGraph'; -import ConversationStateDiagram from './components/ConversationStateDiagram'; +import ConversationDisplay from './components/ConversationDisplay'; import TaskProgressIndicator from './components/TaskProgressIndicator'; import TreeOfThoughtVisual from './components/TreeOfThoughtVisual'; function App() { const [agentNetwork, setAgentNetwork] = useState(null); const [conversationState, setConversationState] = useState({ currentState: '', possibleTransitions: [] }); + const [conversationMessages, setConversationMessages] = useState([]); + const [conversationParticipants, setConversationParticipants] = useState([]); const [taskProgress, setTaskProgress] = useState({ taskId: '', status: '', progressPercentage: 0 }); const [treeOfThought, setTreeOfThought] = useState(null); @@ -16,6 +18,8 @@ function App() { connectWebSocket(() => { subscribeToTopic('agent_network', setAgentNetwork); subscribeToTopic('conversation_state', setConversationState); + subscribeToTopic('conversation_message', (message) => setConversationMessages(prev => [...prev, message])); + subscribeToTopic('conversation_participants', setConversationParticipants); subscribeToTopic('task_progress', setTaskProgress); subscribeToTopic('tree_of_thought', setTreeOfThought); }); @@ -29,10 +33,10 @@ function App() { {agentNetwork && }
-

Conversation State

- Conversation +
diff --git a/frontend/src/components/ConversationDisplay.js b/frontend/src/components/ConversationDisplay.js new file mode 100644 index 0000000..85fcf15 --- /dev/null +++ b/frontend/src/components/ConversationDisplay.js @@ -0,0 +1,27 @@ +// src/components/ConversationDisplay.js +import React from 'react'; + +const ConversationDisplay = ({ messages, participants }) => { + return ( +
+

Conversation

+
+

Participants:

+
    + {participants.map((participant, index) => ( +
  • {participant.name}
  • + ))} +
+
+
+ {messages.map((message, index) => ( +
+ {message.sender}: {message.content} +
+ ))} +
+
+ ); +}; + +export default ConversationDisplay; \ No newline at end of file diff --git a/src/main/java/com/ioa/IoASystem.java b/src/main/java/com/ioa/IoASystem.java index 74ec3b3..b3214df 100644 --- a/src/main/java/com/ioa/IoASystem.java +++ b/src/main/java/com/ioa/IoASystem.java @@ -2,6 +2,7 @@ package com.ioa; import com.ioa.agent.AgentInfo; import com.ioa.agent.AgentRegistry; +import com.ioa.conversation.ConversationManager; import com.ioa.task.Task; import com.ioa.task.TaskManager; import com.ioa.team.TeamFormation; @@ -29,6 +30,11 @@ public class IoASystem { return new WebSocketService(messagingTemplate); } + @Bean + public ConversationManager conversationManager(BedrockLanguageModel model, WebSocketService webSocketService) { + return new ConversationManager(model, webSocketService); + } + @Bean public BedrockLanguageModel bedrockLanguageModel() { return new BedrockLanguageModel("anthropic.claude-3-sonnet-20240229-v1:0"); @@ -40,17 +46,17 @@ public class IoASystem { } @Bean - public AgentRegistry agentRegistry(ToolRegistry toolRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService) { + public AgentRegistry agentRegistry(ToolRegistry toolRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService, ConversationManager conversationManager) { AgentRegistry registry = new AgentRegistry(toolRegistry); - // Other agent creation code + // Agent creation is now moved to processTasksAndAgents method return registry; } @Bean - public TaskManager taskManager(AgentRegistry agentRegistry, BedrockLanguageModel model, ToolRegistry toolRegistry, TreeOfThought treeOfThought) { - return new TaskManager(agentRegistry, model, toolRegistry, treeOfThought); + public TaskManager taskManager(AgentRegistry agentRegistry, BedrockLanguageModel model, ToolRegistry toolRegistry, TreeOfThought treeOfThought, ConversationManager conversationManager) { + return new TaskManager(agentRegistry, model, toolRegistry, treeOfThought, conversationManager); } @Bean @@ -58,12 +64,6 @@ public class IoASystem { return new TeamFormation(agentRegistry, treeOfThought, webSocketService, model); } - public static void main(String[] args) { - ConfigurableApplicationContext context = SpringApplication.run(IoASystem.class, args); - IoASystem system = context.getBean(IoASystem.class); - system.processTasksAndAgents(context); - } - @Bean public ToolRegistry toolRegistry() { ToolRegistry toolRegistry = new ToolRegistry(); @@ -87,6 +87,12 @@ public class IoASystem { return toolRegistry; } + public static void main(String[] args) { + ConfigurableApplicationContext context = SpringApplication.run(IoASystem.class, args); + IoASystem system = context.getBean(IoASystem.class); + system.processTasksAndAgents(context); + } + public void processTasksAndAgents(ConfigurableApplicationContext context) { AgentRegistry agentRegistry = context.getBean(AgentRegistry.class); TeamFormation teamFormation = context.getBean(TeamFormation.class); @@ -94,36 +100,37 @@ public class IoASystem { TreeOfThought treeOfThought = context.getBean(TreeOfThought.class); WebSocketService webSocketService = context.getBean(WebSocketService.class); ToolRegistry toolRegistry = context.getBean(ToolRegistry.class); + ConversationManager conversationManager = context.getBean(ConversationManager.class); // Register all agents agentRegistry.registerAgent("agent1", new AgentInfo("agent1", "General Assistant", Arrays.asList("general", "search"), Arrays.asList("webSearch", "getWeather", "setReminder"), - treeOfThought, webSocketService, toolRegistry)); + treeOfThought, webSocketService, toolRegistry, conversationManager)); agentRegistry.registerAgent("agent2", new AgentInfo("agent2", "Travel Expert", Arrays.asList("travel", "booking"), Arrays.asList("bookTravel", "calculateDistance", "findRestaurants"), - treeOfThought, webSocketService, toolRegistry)); + treeOfThought, webSocketService, toolRegistry, conversationManager)); agentRegistry.registerAgent("agent3", new AgentInfo("agent3", "Event Planner Extraordinaire", Arrays.asList("event planning", "team management", "booking"), Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment", "getWeather"), - treeOfThought, webSocketService, toolRegistry)); + treeOfThought, webSocketService, toolRegistry, conversationManager)); agentRegistry.registerAgent("agent4", new AgentInfo("agent4", "Fitness Guru", Arrays.asList("health", "nutrition", "motivation"), Arrays.asList("findFitnessClasses", "getRecipe", "setReminder", "getWeather"), - treeOfThought, webSocketService, toolRegistry)); + treeOfThought, webSocketService, toolRegistry, conversationManager)); agentRegistry.registerAgent("agent5", new AgentInfo("agent5", "Research Specialist", Arrays.asList("research", "writing", "analysis"), Arrays.asList("webSearch", "getNewsUpdates", "translate", "compareProductPrices"), - treeOfThought, webSocketService, toolRegistry)); + treeOfThought, webSocketService, toolRegistry, conversationManager)); agentRegistry.registerAgent("agent6", new AgentInfo("agent6", "Digital Marketing Expert", Arrays.asList("marketing", "social media", "content creation"), Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment", "getMovieRecommendations"), - treeOfThought, webSocketService, toolRegistry)); + treeOfThought, webSocketService, toolRegistry, conversationManager)); agentRegistry.registerAgent("agent7", new AgentInfo("agent7", "Family Travel Coordinator", Arrays.asList("travel", "family planning", "budgeting"), Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants", "getFinancialAdvice"), - treeOfThought, webSocketService, toolRegistry)); + treeOfThought, webSocketService, toolRegistry, conversationManager)); // Create all tasks List tasks = Arrays.asList( @@ -174,17 +181,38 @@ public class IoASystem { System.out.println("Formed team: " + team); if (!team.isEmpty()) { + // Create a conversation for the team + String conversationId = conversationManager.createConversation(); + + // Add team members to the conversation + for (AgentInfo agent : team) { + conversationManager.addParticipant(conversationId, agent); + } + // Assign the task to all team members for (AgentInfo agent : team) { Task agentTask = new Task(task.getId() + "_" + agent.getId(), task.getDescription(), task.getRequiredCapabilities(), task.getRequiredTools()); agentTask.setAssignedAgent(agent); taskManager.addTask(agentTask); - taskManager.executeTask(agentTask.getId()); - System.out.println("Task result for " + agent.getId() + ": " + agentTask.getResult()); + taskManager.executeTask(agentTask.getId(), conversationId); } + + // Start the conversation + conversationManager.startConversation(conversationId, "Let's work on the task: " + task.getDescription()); + + // Wait for the conversation to finish (you might want to implement a more sophisticated mechanism) + try { + Thread.sleep(30000); // Wait for 30 seconds + } catch (InterruptedException e) { + e.printStackTrace(); + } + + // Get the result + String result = conversationManager.getConversationResult(conversationId); + System.out.println("Task result: " + result); } else { System.out.println("No suitable agents found for this task. Consider updating the agent pool or revising the task requirements."); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/ioa/agent/AgentInfo.java b/src/main/java/com/ioa/agent/AgentInfo.java index b4e2321..86f1b50 100644 --- a/src/main/java/com/ioa/agent/AgentInfo.java +++ b/src/main/java/com/ioa/agent/AgentInfo.java @@ -1,10 +1,15 @@ package com.ioa.agent; +import com.ioa.conversation.Message; import com.ioa.util.TreeOfThought; import com.ioa.service.WebSocketService; import com.ioa.tool.ToolRegistry; +import com.ioa.conversation.ConversationFSM; +import com.ioa.conversation.ConversationManager; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class AgentInfo { private String id; @@ -14,9 +19,11 @@ public class AgentInfo { private TreeOfThought treeOfThought; private WebSocketService webSocketService; private ToolRegistry toolRegistry; + private final ConversationManager conversationManager; -public AgentInfo(String id, String name, List capabilities, List tools, - TreeOfThought treeOfThought, WebSocketService webSocketService, ToolRegistry toolRegistry) { + public AgentInfo(String id, String name, List capabilities, List tools, + TreeOfThought treeOfThought, WebSocketService webSocketService, + ToolRegistry toolRegistry, ConversationManager conversationManager) { this.id = id; this.name = name; this.capabilities = capabilities; @@ -24,6 +31,19 @@ public AgentInfo(String id, String name, List capabilities, List this.treeOfThought = treeOfThought; this.webSocketService = webSocketService; this.toolRegistry = toolRegistry; + this.conversationManager = conversationManager; + } + + public void sendMessage(String conversationId, String content) { + conversationManager.postMessage(conversationId, this.id, content); + } + + public void receiveMessage(Message message) { + // Process the received message + Map reasoningResult = treeOfThought.reason("Respond to message: " + message.getContent(), 2, 2); + String response = (String) reasoningResult.get("response"); // Assuming the response is stored under the key "response" + // Send the response back to the conversation + sendMessage(message.getConversationId(), response); } public List getCapabilities() { @@ -98,4 +118,8 @@ public AgentInfo(String id, String name, List capabilities, List return result; } + + public void voteToFinish(String conversationId) { + conversationManager.postMessage(conversationId, this.id, "/vote"); + } } \ No newline at end of file diff --git a/src/main/java/com/ioa/conversation/ConversationFSM.java b/src/main/java/com/ioa/conversation/ConversationFSM.java index 2bf96ac..b67853e 100644 --- a/src/main/java/com/ioa/conversation/ConversationFSM.java +++ b/src/main/java/com/ioa/conversation/ConversationFSM.java @@ -1,79 +1,140 @@ package com.ioa.conversation; +import java.util.stream.Collectors; +import com.ioa.agent.AgentInfo; 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.*; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; + @Component public class ConversationFSM { private ConversationState currentState; - private BedrockLanguageModel model; + private final BedrockLanguageModel model; + private final WebSocketService webSocketService; + private final Queue messageQueue; + private final List participants; + private final Map votes; + private final AtomicBoolean finished; + private String result; + private final ScheduledExecutorService executorService; - @Autowired - private WebSocketService webSocketService; - - public ConversationFSM(BedrockLanguageModel model) { + public ConversationFSM(BedrockLanguageModel model, WebSocketService webSocketService) { + this.executorService = Executors.newScheduledThreadPool(1); this.currentState = ConversationState.DISCUSSION; this.model = model; + this.webSocketService = webSocketService; + this.messageQueue = new ConcurrentLinkedQueue<>(); + this.participants = new ArrayList<>(); + this.votes = new HashMap<>(); + this.finished = new AtomicBoolean(false); + this.result = ""; } - public void handleMessage(Message message) { - String stateTransitionTask = "Decide the next conversation state based on this message: " + message.getContent() + - "\nCurrent state: " + currentState; - - String reasoning = model.generate(stateTransitionTask, null); - - String decisionPrompt = "Based on this reasoning:\n" + reasoning + - "\nProvide the next conversation state (DISCUSSION, TASK_ASSIGNMENT, EXECUTION, or CONCLUSION)."; - String response = model.generate(decisionPrompt, null); - - ConversationState newState = ConversationState.valueOf(response.trim()); - transitionTo(newState); - - // Handle the message based on the new state - switch (newState) { - case DISCUSSION: - handleDiscussionMessage(message); - break; - case TASK_ASSIGNMENT: - handleTaskAssignmentMessage(message); - break; - case EXECUTION: - handleExecutionMessage(message); - break; - case CONCLUSION: - handleConclusionMessage(message); - break; + public void addParticipant(AgentInfo agent) { + participants.add(agent); + votes.put(agent.getId(), false); + webSocketService.sendUpdate("conversation_participants", participants); + } + + public void removeParticipant(AgentInfo agent) { + participants.remove(agent); + votes.remove(agent.getId()); + webSocketService.sendUpdate("conversation_participants", participants); + } + + public void postMessage(Message message) { + messageQueue.offer(message); + processMessages(); + } + + private void processMessages() { + while (!messageQueue.isEmpty() && !finished.get()) { + Message message = messageQueue.poll(); + handleMessage(message); } } + private void handleMessage(Message message) { + if (message.getContent().startsWith("/vote")) { + handleVote(message.getSender()); + } else { + String stateTransitionTask = "Decide the next conversation state based on this message: " + message.getContent() + + "\nCurrent state: " + currentState + + "\nParticipants: " + participants; + + String reasoning = model.generate(stateTransitionTask, null); + + String decisionPrompt = "Based on this reasoning:\n" + reasoning + + "\nProvide the next conversation state (DISCUSSION, TASK_ASSIGNMENT, EXECUTION, or CONCLUSION)."; + String response = model.generate(decisionPrompt, null); + + ConversationState newState = ConversationState.valueOf(response.trim()); + transitionTo(newState); + + // Broadcast the message to all participants + for (AgentInfo agent : participants) { + if (!agent.getId().equals(message.getSender())) { + agent.receiveMessage(message); + } + } + + webSocketService.sendUpdate("conversation_message", message); + + } + } + + private void handleVote(String agentId) { + votes.put(agentId, true); + checkVotes(); + } + + private void checkVotes() { + int totalVotes = (int) votes.values().stream().filter(v -> v).count(); + if (totalVotes > participants.size() / 2) { + finish("Majority vote reached"); + } + } + + public void finish(String reason) { + if (finished.compareAndSet(false, true)) { + result = "Conversation finished. Reason: " + reason + "\nFinal state: " + currentState; + webSocketService.sendUpdate("conversation_finished", result); + } + } + + public boolean isFinished() { + return finished.get(); + } + + public String getResult() { + return result; + } + private void transitionTo(ConversationState newState) { this.currentState = newState; - webSocketService.sendUpdate("conversation_state", new ConversationStateUpdate(currentState)); + webSocketService.sendUpdate("conversation_state", new ConversationStateUpdate(currentState, getPossibleTransitions())); } - private void handleDiscussionMessage(Message message) { - // Implement discussion logic - } - - private void handleTaskAssignmentMessage(Message message) { - // Implement task assignment logic - } - - private void handleExecutionMessage(Message message) { - // Implement execution logic - } - - private void handleConclusionMessage(Message message) { - // Implement conclusion logic + private List getPossibleTransitions() { + // This is a simplified version. You might want to implement more complex logic. + return Arrays.asList(ConversationState.values()).stream() + .map(Enum::name) + .collect(Collectors.toList()); } private class ConversationStateUpdate { - public ConversationState state; + public String currentState; + public List possibleTransitions; - ConversationStateUpdate(ConversationState state) { - this.state = state; + ConversationStateUpdate(ConversationState state, List transitions) { + this.currentState = state.name(); + this.possibleTransitions = transitions; } } } \ No newline at end of file diff --git a/src/main/java/com/ioa/conversation/ConversationManager.java b/src/main/java/com/ioa/conversation/ConversationManager.java new file mode 100644 index 0000000..421e38f --- /dev/null +++ b/src/main/java/com/ioa/conversation/ConversationManager.java @@ -0,0 +1,74 @@ +package com.ioa.conversation; + +import com.ioa.agent.AgentInfo; +import com.ioa.model.BedrockLanguageModel; +import com.ioa.service.WebSocketService; +import org.springframework.stereotype.Component; + +import java.util.*; +import java.util.concurrent.*; + +@Component +public class ConversationManager { + private final Map conversations; + private final BedrockLanguageModel model; + private final WebSocketService webSocketService; + private final ScheduledExecutorService executorService; + + public ConversationManager(BedrockLanguageModel model, WebSocketService webSocketService) { + this.conversations = new ConcurrentHashMap<>(); + this.model = model; + this.webSocketService = webSocketService; + this.executorService = Executors.newScheduledThreadPool(1); + } + + public String createConversation() { + String conversationId = UUID.randomUUID().toString(); + ConversationFSM conversation = new ConversationFSM(model, webSocketService); + conversations.put(conversationId, conversation); + return conversationId; + } + + public void addParticipant(String conversationId, AgentInfo agent) { + ConversationFSM conversation = conversations.get(conversationId); + if (conversation != null) { + conversation.addParticipant(agent); + } + } + + public void removeParticipant(String conversationId, AgentInfo agent) { + ConversationFSM conversation = conversations.get(conversationId); + if (conversation != null) { + conversation.removeParticipant(agent); + } + } + + public void postMessage(String conversationId, String senderId, String content) { + ConversationFSM conversation = conversations.get(conversationId); + if (conversation != null) { + conversation.postMessage(new Message(conversationId, senderId, content)); + } + } + + public void startConversation(String conversationId, String initialMessage) { + ConversationFSM conversation = conversations.get(conversationId); + if (conversation != null) { + conversation.postMessage(new Message(conversationId, "SYSTEM", initialMessage)); + + // Start a timer to end the conversation after 10 minutes + executorService.schedule(() -> { + if (!conversation.isFinished()) { + conversation.finish("Time limit reached"); + } + }, 10, TimeUnit.MINUTES); + } + } + + public String getConversationResult(String conversationId) { + ConversationFSM conversation = conversations.get(conversationId); + if (conversation != null) { + return conversation.getResult(); + } + return "Conversation not found"; + } +} \ No newline at end of file diff --git a/src/main/java/com/ioa/conversation/Message.java b/src/main/java/com/ioa/conversation/Message.java index b5d825b..1e02b49 100644 --- a/src/main/java/com/ioa/conversation/Message.java +++ b/src/main/java/com/ioa/conversation/Message.java @@ -1,14 +1,25 @@ package com.ioa.conversation; -import lombok.Data; - -@Data public class Message { - private String sender; - private String content; + private final String conversationId; + private final String sender; + private final String content; - public Message(String sender, String content) { + public Message(String conversationId, String sender, String content) { + this.conversationId = conversationId; this.sender = sender; this.content = content; } + + public String getConversationId() { + return conversationId; + } + + public String getSender() { + return sender; + } + + public String getContent() { + return content; + } } \ No newline at end of file diff --git a/src/main/java/com/ioa/model/BedrockLanguageModel.java b/src/main/java/com/ioa/model/BedrockLanguageModel.java index 3126ddb..f85bab5 100644 --- a/src/main/java/com/ioa/model/BedrockLanguageModel.java +++ b/src/main/java/com/ioa/model/BedrockLanguageModel.java @@ -38,8 +38,8 @@ public class BedrockLanguageModel { ArrayNode messages = requestBody.putArray("messages"); ObjectNode message = messages.addObject(); message.put("role", "user"); - requestBody.put("max_tokens", 2000); - requestBody.put("temperature", 0.7); + requestBody.put("max_tokens", 20000); + requestBody.put("temperature", 0.4); requestBody.put("top_p", 0.9); ArrayNode content = message.putArray("content"); diff --git a/src/main/java/com/ioa/task/TaskManager.java b/src/main/java/com/ioa/task/TaskManager.java index e068495..f4b7d07 100644 --- a/src/main/java/com/ioa/task/TaskManager.java +++ b/src/main/java/com/ioa/task/TaskManager.java @@ -6,13 +6,11 @@ import com.ioa.model.BedrockLanguageModel; import com.ioa.service.WebSocketService; import com.ioa.tool.ToolRegistry; import com.ioa.util.TreeOfThought; -import org.springframework.beans.factory.annotation.Autowired; +import com.ioa.conversation.ConversationManager; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; -import java.util.List; -import java.util.ArrayList; @Component public class TaskManager { @@ -21,90 +19,56 @@ public class TaskManager { private BedrockLanguageModel model; private ToolRegistry toolRegistry; private TreeOfThought treeOfThought; + private ConversationManager conversationManager; - @Autowired - private WebSocketService webSocketService; - - public TaskManager(AgentRegistry agentRegistry, BedrockLanguageModel model, ToolRegistry toolRegistry, TreeOfThought treeOfThought) { + public TaskManager(AgentRegistry agentRegistry, BedrockLanguageModel model, ToolRegistry toolRegistry, TreeOfThought treeOfThought, ConversationManager conversationManager) { this.agentRegistry = agentRegistry; this.model = model; this.toolRegistry = toolRegistry; this.treeOfThought = treeOfThought; + this.conversationManager = conversationManager; } public void addTask(Task task) { tasks.put(task.getId(), task); - System.out.println("DEBUG: Task added: " + task.getId()); - webSocketService.sendUpdate("task_added", Map.of("taskId", task.getId(), "description", task.getDescription())); } - public void executeTask(String taskId) { + public void executeTask(String taskId, String conversationId) { Task task = tasks.get(taskId); AgentInfo agent = task.getAssignedAgent(); - updateTaskProgress(taskId, "STARTED", 0); + conversationManager.postMessage(conversationId, agent.getId(), "Starting task: " + task.getDescription()); String executionPlanningTask = "Plan the execution of this task: " + task.getDescription() + "\nAssigned agent capabilities: " + agent.getCapabilities() + "\nAvailable tools: " + agent.getTools(); - Map reasoningTree = treeOfThought.reason(executionPlanningTask, 3, 2); - String reasoning = formatReasoning(reasoningTree); + Map reasoningResult = treeOfThought.reason(executionPlanningTask, 3, 2); + String reasoning = (String) reasoningResult.get("reasoning"); // Assuming the reasoning is stored under the key "reasoning" - System.out.println("DEBUG: Task execution reasoning:\n" + reasoning); - webSocketService.sendUpdate("task_reasoning", Map.of("taskId", taskId, "reasoning", reasoning)); + conversationManager.postMessage(conversationId, agent.getId(), "Task execution plan:\n" + reasoning); - updateTaskProgress(taskId, "IN_PROGRESS", 25); + String executionPrompt = "Based on this execution plan:\n" + reasoning + + "\nExecute the task using the available tools and provide the result."; + Map executionResult = treeOfThought.reason(executionPrompt, 1, 1); + String response = (String) executionResult.get("response"); // Assuming the response is stored under the key "response" - List selectedTools = extractToolSelection(reasoning); - System.out.println("DEBUG: Selected tools: " + selectedTools); - webSocketService.sendUpdate("tools_selected", Map.of("taskId", taskId, "tools", selectedTools)); - - updateTaskProgress(taskId, "IN_PROGRESS", 50); - - String result = executeTools(selectedTools, task.getDescription(), agent); + String result = executeToolsFromResponse(response, agent); task.setResult(result); - updateTaskProgress(taskId, "COMPLETED", 100); - System.out.println("DEBUG: Task completed: " + taskId + ", Result: " + result); - webSocketService.sendUpdate("task_completed", Map.of("taskId", taskId, "result", result)); + conversationManager.postMessage(conversationId, agent.getId(), "Task result: " + result); } - private void updateTaskProgress(String taskId, String status, int progressPercentage) { - Map progressUpdate = new HashMap<>(); - progressUpdate.put("taskId", taskId); - progressUpdate.put("status", status); - progressUpdate.put("progressPercentage", progressPercentage); - webSocketService.sendUpdate("task_progress", progressUpdate); - } - - private String formatReasoning(Map reasoningTree) { - // Implement a method to format the reasoning tree into a string - // This is a placeholder implementation - return reasoningTree.toString(); - } - - private List extractToolSelection(String reasoning) { - // Implement a method to extract tool selection from reasoning - // This is a placeholder implementation that selects all available tools - return new ArrayList<>(toolRegistry.getAllTools().keySet()); - } - - private String executeTools(List tools, String taskDescription, AgentInfo agent) { + private String executeToolsFromResponse(String response, AgentInfo agent) { StringBuilder result = new StringBuilder(); - for (String tool : tools) { - System.out.println("DEBUG: Executing tool: " + tool); - webSocketService.sendUpdate("tool_execution", Map.of("taskId", taskDescription, "tool", tool)); - - Object toolInstance = toolRegistry.getTool(tool); - // Execute the tool (this is a simplified representation) - String toolResult = tool + " result: " + toolInstance.toString(); - result.append(toolResult).append("\n"); - - System.out.println("DEBUG: Tool result: " + toolResult); - webSocketService.sendUpdate("tool_result", Map.of("taskId", taskDescription, "tool", tool, "result", toolResult)); + for (String tool : agent.getTools()) { + if (response.contains(tool)) { + Object toolInstance = toolRegistry.getTool(tool); + // Execute the tool (this is a simplified representation) + result.append(tool).append(" result: ").append(toolInstance.toString()).append("\n"); + } } - return result.toString().trim(); + return result.toString(); } } \ No newline at end of file diff --git a/src/main/java/com/ioa/team/TeamFormation.java b/src/main/java/com/ioa/team/TeamFormation.java index 3485348..ad64ab2 100644 --- a/src/main/java/com/ioa/team/TeamFormation.java +++ b/src/main/java/com/ioa/team/TeamFormation.java @@ -35,7 +35,7 @@ public class TeamFormation { "\nRequired tools: " + requiredTools + "\nAvailable agents and their tools: " + formatAgentTools(potentialAgents); - Map reasoningTree = treeOfThought.reason(teamFormationTask, 3, 2); + Map reasoningTree = treeOfThought.reason(teamFormationTask, 1, 2); String reasoning = formatReasoning(reasoningTree); // Send update about the reasoning process diff --git a/target/classes/com/ioa/IoASystem.class b/target/classes/com/ioa/IoASystem.class index 200ee20..b3d58e1 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/agent/AgentInfo.class b/target/classes/com/ioa/agent/AgentInfo.class index 245b350..d55c746 100644 Binary files a/target/classes/com/ioa/agent/AgentInfo.class and b/target/classes/com/ioa/agent/AgentInfo.class differ diff --git a/target/classes/com/ioa/conversation/ConversationFSM$1.class b/target/classes/com/ioa/conversation/ConversationFSM$1.class deleted file mode 100644 index 7cc4f34..0000000 Binary files a/target/classes/com/ioa/conversation/ConversationFSM$1.class and /dev/null differ diff --git a/target/classes/com/ioa/conversation/ConversationFSM$ConversationStateUpdate.class b/target/classes/com/ioa/conversation/ConversationFSM$ConversationStateUpdate.class index 806dc8c..49bea4b 100644 Binary files a/target/classes/com/ioa/conversation/ConversationFSM$ConversationStateUpdate.class and b/target/classes/com/ioa/conversation/ConversationFSM$ConversationStateUpdate.class differ diff --git a/target/classes/com/ioa/conversation/ConversationFSM.class b/target/classes/com/ioa/conversation/ConversationFSM.class index 9f915b6..186c4a5 100644 Binary files a/target/classes/com/ioa/conversation/ConversationFSM.class and b/target/classes/com/ioa/conversation/ConversationFSM.class differ diff --git a/target/classes/com/ioa/conversation/ConversationManager.class b/target/classes/com/ioa/conversation/ConversationManager.class new file mode 100644 index 0000000..b45cbcb Binary files /dev/null and b/target/classes/com/ioa/conversation/ConversationManager.class differ diff --git a/target/classes/com/ioa/conversation/Message.class b/target/classes/com/ioa/conversation/Message.class index 0fcdecb..e65d262 100644 Binary files a/target/classes/com/ioa/conversation/Message.class and b/target/classes/com/ioa/conversation/Message.class differ diff --git a/target/classes/com/ioa/model/BedrockLanguageModel.class b/target/classes/com/ioa/model/BedrockLanguageModel.class index b2f598d..04de7eb 100644 Binary files a/target/classes/com/ioa/model/BedrockLanguageModel.class and b/target/classes/com/ioa/model/BedrockLanguageModel.class differ diff --git a/target/classes/com/ioa/task/TaskManager.class b/target/classes/com/ioa/task/TaskManager.class index 8a3ba1a..1dc76d8 100644 Binary files a/target/classes/com/ioa/task/TaskManager.class and b/target/classes/com/ioa/task/TaskManager.class differ diff --git a/target/classes/com/ioa/team/TeamFormation.class b/target/classes/com/ioa/team/TeamFormation.class index 4ea8bfc..f9c603b 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/static/asset-manifest.json b/target/classes/static/asset-manifest.json index 86f22a1..6a1e07e 100644 --- a/target/classes/static/asset-manifest.json +++ b/target/classes/static/asset-manifest.json @@ -1,15 +1,15 @@ { "files": { "main.css": "/static/css/main.e6c13ad2.css", - "main.js": "/static/js/main.720bb114.js", + "main.js": "/static/js/main.a73628f2.js", "static/js/453.d855a71b.chunk.js": "/static/js/453.d855a71b.chunk.js", "index.html": "/index.html", "main.e6c13ad2.css.map": "/static/css/main.e6c13ad2.css.map", - "main.720bb114.js.map": "/static/js/main.720bb114.js.map", + "main.a73628f2.js.map": "/static/js/main.a73628f2.js.map", "453.d855a71b.chunk.js.map": "/static/js/453.d855a71b.chunk.js.map" }, "entrypoints": [ "static/css/main.e6c13ad2.css", - "static/js/main.720bb114.js" + "static/js/main.a73628f2.js" ] } \ No newline at end of file diff --git a/target/classes/static/index.html b/target/classes/static/index.html index b93df9f..48bdb78 100644 --- a/target/classes/static/index.html +++ b/target/classes/static/index.html @@ -1 +1 @@ -React App
\ No newline at end of file +React App
\ No newline at end of file diff --git a/target/classes/static/static/js/main.a73628f2.js b/target/classes/static/static/js/main.a73628f2.js new file mode 100644 index 0000000..c0f10e3 --- /dev/null +++ b/target/classes/static/static/js/main.a73628f2.js @@ -0,0 +1,3 @@ +/*! For license information please see main.a73628f2.js.LICENSE.txt */ +(()=>{var e={446:e=>{var t=function(){if("object"===typeof self&&self)return self;if("object"===typeof window&&window)return window;throw new Error("Unable to resolve global `this`")};e.exports=function(){if(this)return this;if("object"===typeof globalThis&&globalThis)return globalThis;try{Object.defineProperty(Object.prototype,"__global__",{get:function(){return this},configurable:!0})}catch(e){return t()}try{return __global__||t()}finally{delete Object.prototype.__global__}}()},6329:e=>{"function"===typeof Object.create?e.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}},5663:(e,t,n)=>{var r=n(5663);for(k in r)n.g[k]=r[k]},7237:(e,t)=>{"use strict";var n=Object.prototype.hasOwnProperty;function r(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(t){return null}}function o(e){try{return encodeURIComponent(e)}catch(t){return null}}t.stringify=function(e,t){t=t||"";var r,i,a=[];for(i in"string"!==typeof t&&(t="?"),e)if(n.call(e,i)){if((r=e[i])||null!==r&&undefined!==r&&!isNaN(r)||(r=""),i=o(i),r=o(r),null===i||null===r)continue;a.push(i+"="+r)}return a.length?t+a.join("&"):""},t.parse=function(e){for(var t,n=/([^=?#&]+)=?([^&]*)/g,o={};t=n.exec(e);){var i=r(t[1]),a=r(t[2]);null===i||null===a||i in o||(o[i]=a)}return o}},2730:(e,t,n)=>{"use strict";var r=n(5043),o=n(8853);function i(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n