Working version with increased timeout and slight messaging improvements

This commit is contained in:
Mahesh Kommareddi 2024-07-17 09:21:42 -04:00
parent 1634dfcdc5
commit 6eadf28c66
8 changed files with 27 additions and 19 deletions

View File

@ -155,9 +155,9 @@ public class IoASystem {
// Create all tasks // Create all tasks
List<Task> tasks = Arrays.asList( List<Task> tasks = Arrays.asList(
// new Task("task1", "Plan a weekend trip to Paris", new Task("task1", "Plan a weekend trip to Paris",
// Arrays.asList("travel", "booking"), Arrays.asList("travel", "booking"),
// Arrays.asList("bookTravel", "findRestaurants", "getWeather")), Arrays.asList("bookTravel", "findRestaurants", "getWeather"))//,
// new Task("task2", "Organize a corporate team-building event in New York", // new Task("task2", "Organize a corporate team-building event in New York",
// Arrays.asList("event planning", "team management"), // Arrays.asList("event planning", "team management"),
// Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment")), // Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment")),
@ -174,9 +174,9 @@ public class IoASystem {
// Arrays.asList("travel", "family planning"), // Arrays.asList("travel", "family planning"),
// Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants")), // Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants")),
new Task("task7", "Organize an international tech conference with virtual and in-person components", // 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("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", // 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("software development", "travel", "language expertise", "environmental science", "user experience design"),
@ -235,7 +235,7 @@ public class IoASystem {
// Wait for all agents to complete their tasks // Wait for all agents to complete their tasks
try { try {
latch.await(5, TimeUnit.MINUTES); // Wait for up to 5 minutes latch.await(40, TimeUnit.MINUTES); // Wait for up to 5 minutes
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -67,7 +67,7 @@ public class ConversationManager {
if (!conversation.isFinished()) { if (!conversation.isFinished()) {
conversation.finish("Time limit reached"); conversation.finish("Time limit reached");
} }
}, 10, TimeUnit.MINUTES); }, 40, TimeUnit.MINUTES);
} }
} }

View File

@ -53,7 +53,7 @@ public class TaskManager {
if (reasoning == null || reasoning.isEmpty()) { if (reasoning == null || reasoning.isEmpty()) {
System.out.println("WARNING: Empty execution plan generated for task: " + taskId); System.out.println("WARNING: Empty execution plan generated for task: " + taskId);
reasoning = "No execution plan generated."; reasoning = "No execution plan generated. Proceeding with a general approach to organize execution plan.";
} }
conversationManager.postMessage(conversationId, agent.getId(), "Task execution plan:\n" + reasoning); conversationManager.postMessage(conversationId, agent.getId(), "Task execution plan:\n" + reasoning);
@ -61,22 +61,22 @@ public class TaskManager {
String executionPrompt = "Based on this execution plan:\n" + reasoning + String executionPrompt = "Based on this execution plan:\n" + reasoning +
"\nExecute the task using the available tools and provide the result."; "\nExecute the task using the available tools and provide the result.";
Map<String, Object> executionResult = treeOfThought.reason(executionPrompt, 1, 1); Map<String, Object> executionResult = treeOfThought.reason(executionPrompt, 1, 1);
String response = (String) executionResult.get("response"); String response = (String) executionResult.get("reasoning");
if (response == null || response.isEmpty()) { if (response == null || response.isEmpty()) {
System.out.println("WARNING: Empty response generated for task execution: " + taskId); System.out.println("WARNING: Empty response generated for task execution: " + taskId);
response = "No response generated."; response = "Unable to execute the task due to technical difficulties. Please try again or seek assistance.";
} }
String result = executeToolsFromResponse(response, agent); String result = executeToolsFromResponse(response, agent);
if (result == null || result.isEmpty()) {
result = "No specific actions were taken based on the execution plan. Please review the plan and provide more detailed instructions if necessary.";
}
task.setResult(result); task.setResult(result);
if (result != null && !result.isEmpty()) {
conversationManager.postMessage(conversationId, agent.getId(), "Task result: " + result); 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) { private String executeToolsFromResponse(String response, AgentInfo agent) {

View File

@ -22,7 +22,11 @@ public class TreeOfThought {
webSocketService.sendUpdate("tree_of_thought", treeData); webSocketService.sendUpdate("tree_of_thought", treeData);
String reasoning = formatReasoning(treeData); String reasoning = formatReasoning(treeData);
System.out.println("DEBUG: Reasoning result: " + reasoning); System.out.println("DEBUG: Reasoning result: " + reasoning);
return treeData;
Map<String, Object> result = new HashMap<>();
result.put("reasoning", reasoning);
result.put("treeData", treeData);
return result;
} }
private Map<String, Object> exploreThought(String task, int depth, int branches, String nodeName) { private Map<String, Object> exploreThought(String task, int depth, int branches, String nodeName) {
@ -41,8 +45,12 @@ public class TreeOfThought {
"\nExplore a new branch of thought (branch " + (i+1) + "/" + branches + "):"; "\nExplore a new branch of thought (branch " + (i+1) + "/" + branches + "):";
String thought = model.generate(branchPrompt, null); String thought = model.generate(branchPrompt, null);
if (!thought.equals("No response generated") && !thought.startsWith("Error:")) {
Map<String, Object> childNode = exploreThought(task, depth - 1, branches, thought); Map<String, Object> childNode = exploreThought(task, depth - 1, branches, thought);
children.add(childNode); children.add(childNode);
} else {
System.out.println("WARNING: Failed to generate thought. Result: " + thought);
}
} }
node.put("children", children); node.put("children", children);