diff --git a/src/main/java/com/ioa/IoASystem.java b/src/main/java/com/ioa/IoASystem.java index e8aa11b..5d7bee4 100644 --- a/src/main/java/com/ioa/IoASystem.java +++ b/src/main/java/com/ioa/IoASystem.java @@ -176,23 +176,23 @@ public class IoASystem { 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")), + 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"), - Arrays.asList("findFitnessClasses", "getRecipe", "setReminder", "getWeather", "scheduleAppointment", "getFinancialAdvice")), + // 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"), + // Arrays.asList("findFitnessClasses", "getRecipe", "setReminder", "getWeather", "scheduleAppointment", "getFinancialAdvice")), - new Task("task10", "Plan and execute a global product launch campaign for a revolutionary eco-friendly technology", - Arrays.asList("marketing", "environmental science", "international business", "public relations", "social media"), - Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment", "translate", "compareProductPrices", "bookTravel")), + // new Task("task10", "Plan and execute a global product launch campaign for a revolutionary eco-friendly technology", + // Arrays.asList("marketing", "environmental science", "international business", "public relations", "social media"), + // Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment", "translate", "compareProductPrices", "bookTravel")), - new Task("task11", "Design and implement a smart city initiative focusing on transportation, energy, and public safety", - Arrays.asList("urban planning", "environmental science", "data analysis", "public policy", "technology integration"), - Arrays.asList("webSearch", "getWeather", "calculateDistance", "getNewsUpdates", "getFinancialAdvice", "findHomeServices")) + // new Task("task11", "Design and implement a smart city initiative focusing on transportation, energy, and public safety", + // Arrays.asList("urban planning", "environmental science", "data analysis", "public policy", "technology integration"), + // Arrays.asList("webSearch", "getWeather", "calculateDistance", "getNewsUpdates", "getFinancialAdvice", "findHomeServices")) ); diff --git a/src/main/java/com/ioa/conversation/ConversationManager.java b/src/main/java/com/ioa/conversation/ConversationManager.java index 421e38f..7228efe 100644 --- a/src/main/java/com/ioa/conversation/ConversationManager.java +++ b/src/main/java/com/ioa/conversation/ConversationManager.java @@ -44,9 +44,16 @@ public class ConversationManager { } public void postMessage(String conversationId, String senderId, String content) { + System.out.println("DEBUG: Posting message - ConversationId: " + conversationId + ", SenderId: " + senderId + ", Content: " + content); ConversationFSM conversation = conversations.get(conversationId); if (conversation != null) { + if (content == null) { + System.out.println("WARNING: Attempting to post null content message"); + return; + } conversation.postMessage(new Message(conversationId, senderId, content)); + } else { + System.out.println("WARNING: Conversation not found for id: " + conversationId); } } diff --git a/src/main/java/com/ioa/model/BedrockLanguageModel.java b/src/main/java/com/ioa/model/BedrockLanguageModel.java index f85bab5..3b3fc30 100644 --- a/src/main/java/com/ioa/model/BedrockLanguageModel.java +++ b/src/main/java/com/ioa/model/BedrockLanguageModel.java @@ -10,6 +10,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.JsonNode; + import org.springframework.stereotype.Component; import java.nio.file.Files; @@ -32,6 +34,7 @@ public class BedrockLanguageModel { } public String generate(String prompt, String imagePath) { + System.out.println("DEBUG: Generating response for prompt: " + prompt); try { ObjectNode requestBody = objectMapper.createObjectNode(); requestBody.put("anthropic_version", "bedrock-2023-05-31"); @@ -39,7 +42,7 @@ public class BedrockLanguageModel { ObjectNode message = messages.addObject(); message.put("role", "user"); requestBody.put("max_tokens", 20000); - requestBody.put("temperature", 0.4); + requestBody.put("temperature", 0.7); requestBody.put("top_p", 0.9); ArrayNode content = message.putArray("content"); @@ -71,12 +74,30 @@ public class BedrockLanguageModel { InvokeModelResponse response = bedrockClient.invokeModel(invokeRequest); String responseBody = response.body().asUtf8String(); + System.out.println("DEBUG: Raw response from Bedrock: " + responseBody); - ObjectNode responseJson = (ObjectNode) objectMapper.readTree(responseBody); - return responseJson.path("content").get(0).path("text").asText(); + JsonNode responseJson = objectMapper.readTree(responseBody); + JsonNode contentArray = responseJson.path("content"); + + if (contentArray.isArray() && contentArray.size() > 0) { + JsonNode firstContent = contentArray.get(0); + String generatedText = firstContent.path("text").asText(); + if (generatedText.isEmpty()) { + System.out.println("WARNING: Generated text is empty. Full response: " + responseBody); + return "No response generated"; + } + + System.out.println("DEBUG: Generated text: " + generatedText); + return generatedText; + } else { + System.out.println("WARNING: Unexpected response format. Full response: " + responseBody); + return "Unexpected response format"; + } } catch (Exception e) { - throw new RuntimeException("Error generating text with Bedrock", e); + System.out.println("ERROR: Failed to generate text with Bedrock: " + e.getMessage()); + e.printStackTrace(); + return "Error: " + e.getMessage(); } } } \ No newline at end of file diff --git a/src/main/java/com/ioa/task/TaskManager.java b/src/main/java/com/ioa/task/TaskManager.java index f4b7d07..705ccd4 100644 --- a/src/main/java/com/ioa/task/TaskManager.java +++ b/src/main/java/com/ioa/task/TaskManager.java @@ -37,29 +37,48 @@ public class TaskManager { Task task = tasks.get(taskId); AgentInfo agent = task.getAssignedAgent(); + System.out.println("DEBUG: Executing task: " + taskId + " for agent: " + agent.getId()); + 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(); + System.out.println("DEBUG: Generating execution plan for task: " + taskId); Map reasoningResult = treeOfThought.reason(executionPlanningTask, 3, 2); - String reasoning = (String) reasoningResult.get("reasoning"); // Assuming the reasoning is stored under the key "reasoning" + String reasoning = (String) reasoningResult.get("reasoning"); + + System.out.println("DEBUG: Execution plan generated: " + reasoning); + + if (reasoning == null || reasoning.isEmpty()) { + System.out.println("WARNING: Empty execution plan generated for task: " + taskId); + reasoning = "No execution plan generated."; + } conversationManager.postMessage(conversationId, agent.getId(), "Task execution plan:\n" + reasoning); 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" + String response = (String) executionResult.get("response"); + + if (response == null || response.isEmpty()) { + System.out.println("WARNING: Empty response generated for task execution: " + taskId); + response = "No response generated."; + } String result = executeToolsFromResponse(response, agent); task.setResult(result); - conversationManager.postMessage(conversationId, agent.getId(), "Task result: " + result); + if (result != null && !result.isEmpty()) { + conversationManager.postMessage(conversationId, agent.getId(), "Task result: " + result); + } else { + conversationManager.postMessage(conversationId, agent.getId(), "Task completed, but no result was generated."); + } } - + private String executeToolsFromResponse(String response, AgentInfo agent) { StringBuilder result = new StringBuilder(); for (String tool : agent.getTools()) { diff --git a/src/main/java/com/ioa/util/TreeOfThought.java b/src/main/java/com/ioa/util/TreeOfThought.java index bc137e4..b9be837 100644 --- a/src/main/java/com/ioa/util/TreeOfThought.java +++ b/src/main/java/com/ioa/util/TreeOfThought.java @@ -17,8 +17,11 @@ public class TreeOfThought { } public Map reason(String task, int depth, int branches) { + System.out.println("DEBUG: Starting reasoning process for task: " + task); Map treeData = exploreThought(task, depth, branches, "Root"); webSocketService.sendUpdate("tree_of_thought", treeData); + String reasoning = formatReasoning(treeData); + System.out.println("DEBUG: Reasoning result: " + reasoning); return treeData; } @@ -67,4 +70,30 @@ public class TreeOfThought { "\nPath: " + path + "\nEvaluations:\n" + childEvaluations; return model.generate(prompt, null); } + + private String formatReasoning(Map treeData) { + StringBuilder sb = new StringBuilder(); + formatNode(treeData, sb, 0); + return sb.toString(); + } + + private void formatNode(Map node, StringBuilder sb, int depth) { + String indent = " ".repeat(depth); + sb.append(indent).append(node.get("name")).append("\n"); + + if (node.containsKey("evaluation")) { + sb.append(indent).append("Evaluation: ").append(node.get("evaluation")).append("\n"); + } + + if (node.containsKey("conclusion")) { + sb.append(indent).append("Conclusion: ").append(node.get("conclusion")).append("\n"); + } + + if (node.containsKey("children")) { + List> children = (List>) node.get("children"); + for (Map child : children) { + formatNode(child, sb, depth + 1); + } + } + } } \ No newline at end of file diff --git a/target/classes/com/ioa/IoASystem.class b/target/classes/com/ioa/IoASystem.class index 2a4f41c..6a0836c 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/conversation/ConversationManager.class b/target/classes/com/ioa/conversation/ConversationManager.class index b45cbcb..4de5c4e 100644 Binary files a/target/classes/com/ioa/conversation/ConversationManager.class and b/target/classes/com/ioa/conversation/ConversationManager.class differ diff --git a/target/classes/com/ioa/model/BedrockLanguageModel.class b/target/classes/com/ioa/model/BedrockLanguageModel.class index 04de7eb..752c35b 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 1dc76d8..88cbcb1 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/util/TreeOfThought.class b/target/classes/com/ioa/util/TreeOfThought.class index 8b0a699..cdbfc3d 100644 Binary files a/target/classes/com/ioa/util/TreeOfThought.class and b/target/classes/com/ioa/util/TreeOfThought.class differ