Major cleanup and organization.....

This commit is contained in:
Mahesh Kommareddi 2024-07-17 02:21:03 -04:00
parent b91631f562
commit a355bf3183
54 changed files with 469 additions and 250 deletions

View File

@ -5,20 +5,19 @@ import com.ioa.agent.AgentRegistry;
import com.ioa.task.Task;
import com.ioa.task.TaskManager;
import com.ioa.team.TeamFormation;
import com.ioa.tool.CommonTools;
import com.ioa.tool.ToolRegistry;
import com.ioa.tool.Tool;
import com.ioa.tool.common.*;
import com.ioa.model.BedrockLanguageModel;
import com.ioa.service.WebSocketService;
import com.ioa.tool.Tool;
import com.ioa.util.TreeOfThought;
import org.springframework.context.ConfigurableApplicationContext;
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;
import java.util.List;
@ -26,26 +25,13 @@ import java.util.List;
public class IoASystem {
@Bean
public ToolRegistry toolRegistry() {
ToolRegistry toolRegistry = new ToolRegistry();
CommonTools commonTools = new CommonTools();
for (Method method : CommonTools.class.getMethods()) {
if (method.isAnnotationPresent(Tool.class)) {
toolRegistry.registerTool(method.getName(), method);
}
}
return toolRegistry;
}
@Bean
public AgentRegistry agentRegistry(ToolRegistry toolRegistry) {
return new AgentRegistry(toolRegistry);
public WebSocketService webSocketService(SimpMessagingTemplate messagingTemplate) {
return new WebSocketService(messagingTemplate);
}
@Bean
public BedrockLanguageModel bedrockLanguageModel() {
return new BedrockLanguageModel("anthropic.claude-3-5-sonnet-20240620-v1:0");
return new BedrockLanguageModel("anthropic.claude-3-sonnet-20240229-v1:0");
}
@Bean
@ -54,18 +40,22 @@ public class IoASystem {
}
@Bean
public TeamFormation teamFormation(AgentRegistry agentRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService) {
return new TeamFormation(agentRegistry, treeOfThought, webSocketService);
public AgentRegistry agentRegistry(ToolRegistry toolRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService) {
AgentRegistry registry = new AgentRegistry(toolRegistry);
// Other agent creation code
return registry;
}
@Bean
public TaskManager taskManager(AgentRegistry agentRegistry, BedrockLanguageModel model, ToolRegistry toolRegistry) {
return new TaskManager(agentRegistry, model, toolRegistry);
public TaskManager taskManager(AgentRegistry agentRegistry, BedrockLanguageModel model, ToolRegistry toolRegistry, TreeOfThought treeOfThought) {
return new TaskManager(agentRegistry, model, toolRegistry, treeOfThought);
}
@Bean
public WebSocketService webSocketService(SimpMessagingTemplate messagingTemplate) {
return new WebSocketService(messagingTemplate);
public TeamFormation teamFormation(AgentRegistry agentRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService, BedrockLanguageModel model) {
return new TeamFormation(agentRegistry, treeOfThought, webSocketService, model);
}
public static void main(String[] args) {
@ -74,33 +64,66 @@ public class IoASystem {
system.processTasksAndAgents(context);
}
@Bean
public ToolRegistry toolRegistry() {
ToolRegistry toolRegistry = new ToolRegistry();
// Register all tools
toolRegistry.registerTool("webSearch", new WebSearchTool());
toolRegistry.registerTool("getWeather", new WeatherTool());
toolRegistry.registerTool("setReminder", new ReminderTool());
toolRegistry.registerTool("bookTravel", new TravelBookingTool());
toolRegistry.registerTool("calculateDistance", new DistanceCalculatorTool());
toolRegistry.registerTool("findRestaurants", new RestaurantFinderTool());
toolRegistry.registerTool("scheduleAppointment", new AppointmentSchedulerTool());
toolRegistry.registerTool("findFitnessClasses", new FitnessClassFinderTool());
toolRegistry.registerTool("getRecipe", new RecipeTool());
toolRegistry.registerTool("getNewsUpdates", new NewsUpdateTool());
toolRegistry.registerTool("translate", new TranslationTool());
toolRegistry.registerTool("compareProductPrices", new PriceComparisonTool());
toolRegistry.registerTool("getMovieRecommendations", new MovieRecommendationTool());
toolRegistry.registerTool("getFinancialAdvice", new FinancialAdviceTool());
return toolRegistry;
}
public void processTasksAndAgents(ConfigurableApplicationContext context) {
AgentRegistry agentRegistry = context.getBean(AgentRegistry.class);
TeamFormation teamFormation = context.getBean(TeamFormation.class);
TaskManager taskManager = context.getBean(TaskManager.class);
TreeOfThought treeOfThought = context.getBean(TreeOfThought.class);
WebSocketService webSocketService = context.getBean(WebSocketService.class);
ToolRegistry toolRegistry = context.getBean(ToolRegistry.class);
// Register all agents
agentRegistry.registerAgent("agent1", new AgentInfo("agent1", "General Assistant",
Arrays.asList("general", "search"),
Arrays.asList("webSearch", "getWeather", "setReminder")));
Arrays.asList("webSearch", "getWeather", "setReminder"),
treeOfThought, webSocketService, toolRegistry));
agentRegistry.registerAgent("agent2", new AgentInfo("agent2", "Travel Expert",
Arrays.asList("travel", "booking"),
Arrays.asList("bookTravel", "calculateDistance", "findRestaurants")));
Arrays.asList("bookTravel", "calculateDistance", "findRestaurants"),
treeOfThought, webSocketService, toolRegistry));
agentRegistry.registerAgent("agent3", new AgentInfo("agent3", "Event Planner Extraordinaire",
Arrays.asList("event planning", "team management", "booking"),
Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment", "getWeather")));
Arrays.asList("findRestaurants", "bookTravel", "scheduleAppointment", "getWeather"),
treeOfThought, webSocketService, toolRegistry));
agentRegistry.registerAgent("agent4", new AgentInfo("agent4", "Fitness Guru",
Arrays.asList("health", "nutrition", "motivation"),
Arrays.asList("findFitnessClasses", "getRecipe", "setReminder", "getWeather")));
Arrays.asList("findFitnessClasses", "getRecipe", "setReminder", "getWeather"),
treeOfThought, webSocketService, toolRegistry));
agentRegistry.registerAgent("agent5", new AgentInfo("agent5", "Research Specialist",
Arrays.asList("research", "writing", "analysis"),
Arrays.asList("webSearch", "getNewsUpdates", "translate", "compareProductPrices")));
Arrays.asList("webSearch", "getNewsUpdates", "translate", "compareProductPrices"),
treeOfThought, webSocketService, toolRegistry));
agentRegistry.registerAgent("agent6", new AgentInfo("agent6", "Digital Marketing Expert",
Arrays.asList("marketing", "social media", "content creation"),
Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment", "getMovieRecommendations")));
Arrays.asList("webSearch", "getNewsUpdates", "scheduleAppointment", "getMovieRecommendations"),
treeOfThought, webSocketService, toolRegistry));
agentRegistry.registerAgent("agent7", new AgentInfo("agent7", "Family Travel Coordinator",
Arrays.asList("travel", "family planning", "budgeting"),
Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants", "getFinancialAdvice")));
Arrays.asList("bookTravel", "calculateDistance", "getWeather", "findRestaurants", "getFinancialAdvice"),
treeOfThought, webSocketService, toolRegistry));
// Create all tasks
List<Task> tasks = Arrays.asList(

View File

@ -1,28 +1,101 @@
package com.ioa.agent;
import lombok.Data;
import java.util.List;
import com.ioa.util.TreeOfThought;
import com.ioa.service.WebSocketService;
import com.ioa.tool.ToolRegistry;
import java.util.*;
@Data
public class AgentInfo {
private String id;
private String name;
private List<String> capabilities;
private List<String> tools;
private TreeOfThought treeOfThought;
private WebSocketService webSocketService;
private ToolRegistry toolRegistry;
public AgentInfo(String id, String name, List<String> capabilities, List<String> tools) {
public AgentInfo(String id, String name, List<String> capabilities, List<String> tools,
TreeOfThought treeOfThought, WebSocketService webSocketService, ToolRegistry toolRegistry) {
this.id = id;
this.name = name;
this.capabilities = capabilities;
this.tools = tools;
this.treeOfThought = treeOfThought;
this.webSocketService = webSocketService;
this.toolRegistry = toolRegistry;
}
public List<String> getCapabilities() {
return this.capabilities;
}
public String getId() {
return this.id;
}
public List<String> getTools() {
return this.tools;
}
@Override
public String toString() {
return "AgentInfo{id='" + id + "', name='" + name + "'}";
}
public String executeTask(String taskDescription) {
System.out.println("DEBUG: Agent " + id + " executing task: " + taskDescription);
webSocketService.sendUpdate("agent_task", Map.of("agentId", id, "task", taskDescription));
// Use Tree of Thought to decide on tools and actions
Map<String, Object> reasoning = treeOfThought.reason("Select tools and actions for task: " + taskDescription +
"\nAvailable tools: " + tools, 2, 2);
String reasoningString = formatReasoning(reasoning);
System.out.println("DEBUG: Agent " + id + " reasoning:\n" + reasoningString);
webSocketService.sendUpdate("agent_reasoning", Map.of("agentId", id, "reasoning", reasoningString));
// Extract tool selection from reasoning
List<String> selectedTools = extractToolSelection(reasoningString);
System.out.println("DEBUG: Agent " + id + " selected tools: " + selectedTools);
webSocketService.sendUpdate("agent_tools_selected", Map.of("agentId", id, "tools", selectedTools));
// Execute actions using selected tools
StringBuilder result = new StringBuilder();
for (String tool : selectedTools) {
String actionResult = executeTool(tool, taskDescription);
result.append(actionResult).append("\n");
}
String finalResult = result.toString().trim();
System.out.println("DEBUG: Agent " + id + " task result: " + finalResult);
webSocketService.sendUpdate("agent_task_result", Map.of("agentId", id, "result", finalResult));
return finalResult;
}
private String formatReasoning(Map<String, Object> reasoning) {
// Implement a method to format the reasoning tree into a string
// This is a placeholder implementation
return reasoning.toString();
}
private List<String> extractToolSelection(String reasoning) {
// Implement a method to extract tool selection from reasoning
// This is a placeholder implementation
return new ArrayList<>(tools);
}
private String executeTool(String tool, String context) {
System.out.println("DEBUG: Agent " + id + " executing tool: " + tool);
webSocketService.sendUpdate("agent_tool_execution", Map.of("agentId", id, "tool", tool));
// Placeholder for tool execution
// In a real implementation, you would call the actual tool method from the ToolRegistry
String result = "Simulated result of using " + tool + " for context: " + context;
System.out.println("DEBUG: Agent " + id + " tool result: " + result);
webSocketService.sendUpdate("agent_tool_result", Map.of("agentId", id, "tool", tool, "result", result));
return result;
}
}

View File

@ -38,7 +38,7 @@ public class BedrockLanguageModel {
ArrayNode messages = requestBody.putArray("messages");
ObjectNode message = messages.addObject();
message.put("role", "user");
requestBody.put("max_tokens", 500);
requestBody.put("max_tokens", 2000);
requestBody.put("temperature", 0.7);
requestBody.put("top_p", 0.9);

View File

@ -5,11 +5,14 @@ import com.ioa.agent.AgentRegistry;
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 org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
@Component
public class TaskManager {
@ -17,18 +20,22 @@ public class TaskManager {
private AgentRegistry agentRegistry;
private BedrockLanguageModel model;
private ToolRegistry toolRegistry;
private TreeOfThought treeOfThought;
@Autowired
private WebSocketService webSocketService;
public TaskManager(AgentRegistry agentRegistry, BedrockLanguageModel model, ToolRegistry toolRegistry) {
public TaskManager(AgentRegistry agentRegistry, BedrockLanguageModel model, ToolRegistry toolRegistry, TreeOfThought treeOfThought) {
this.agentRegistry = agentRegistry;
this.model = model;
this.toolRegistry = toolRegistry;
this.treeOfThought = treeOfThought;
}
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) {
@ -41,18 +48,27 @@ public class TaskManager {
"\nAssigned agent capabilities: " + agent.getCapabilities() +
"\nAvailable tools: " + agent.getTools();
String reasoning = model.generate(executionPlanningTask, null);
Map<String, Object> reasoningTree = treeOfThought.reason(executionPlanningTask, 3, 2);
String reasoning = formatReasoning(reasoningTree);
System.out.println("DEBUG: Task execution reasoning:\n" + reasoning);
webSocketService.sendUpdate("task_reasoning", Map.of("taskId", taskId, "reasoning", reasoning));
updateTaskProgress(taskId, "IN_PROGRESS", 25);
List<String> 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 executionPrompt = "Based on this execution plan:\n" + reasoning +
"\nExecute the task using the available tools and provide the result.";
String response = model.generate(executionPrompt, null);
String result = executeToolsFromResponse(response, agent);
String result = executeTools(selectedTools, task.getDescription(), 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));
}
private void updateTaskProgress(String taskId, String status, int progressPercentage) {
@ -63,27 +79,32 @@ public class TaskManager {
webSocketService.sendUpdate("task_progress", progressUpdate);
}
private String executeToolsFromResponse(String response, AgentInfo agent) {
StringBuilder result = new StringBuilder();
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();
private String formatReasoning(Map<String, Object> reasoningTree) {
// Implement a method to format the reasoning tree into a string
// This is a placeholder implementation
return reasoningTree.toString();
}
private class TaskProgress {
public String taskId;
public String status;
public int progressPercentage;
private List<String> 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());
}
TaskProgress(String taskId, String status, int progressPercentage) {
this.taskId = taskId;
this.status = status;
this.progressPercentage = progressPercentage;
private String executeTools(List<String> tools, String taskDescription, 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));
}
return result.toString().trim();
}
}

View File

@ -5,6 +5,7 @@ import com.ioa.agent.AgentRegistry;
import com.ioa.task.Task;
import com.ioa.util.TreeOfThought;
import com.ioa.service.WebSocketService;
import com.ioa.model.BedrockLanguageModel;
import org.springframework.stereotype.Component;
import java.util.*;
@ -15,11 +16,13 @@ public class TeamFormation {
private final AgentRegistry agentRegistry;
private final TreeOfThought treeOfThought;
private final WebSocketService webSocketService;
private final BedrockLanguageModel model;
public TeamFormation(AgentRegistry agentRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService) {
public TeamFormation(AgentRegistry agentRegistry, TreeOfThought treeOfThought, WebSocketService webSocketService, BedrockLanguageModel model) {
this.agentRegistry = agentRegistry;
this.treeOfThought = treeOfThought;
this.webSocketService = webSocketService;
this.model = model;
}
public List<AgentInfo> formTeam(Task task) {
@ -30,28 +33,52 @@ public class TeamFormation {
String teamFormationTask = "Form the best team for this task: " + task.getDescription() +
"\nRequired capabilities: " + requiredCapabilities +
"\nRequired tools: " + requiredTools +
"\nAvailable agents and their tools: " + formatAgentTools(potentialAgents) +
"\nAnalyze the task, evaluate agents, and propose a team composition. " +
"Conclude with a final team selection in the format: 'Final Team Selection: agent1, agent2, ...'";
"\nAvailable agents and their tools: " + formatAgentTools(potentialAgents);
String reasoning = treeOfThought.reason(teamFormationTask, 3, 2);
Map<String, Object> reasoningTree = treeOfThought.reason(teamFormationTask, 3, 2);
String reasoning = formatReasoning(reasoningTree);
// Send update about the reasoning process
if (reasoning != null && !reasoning.isEmpty()) {
webSocketService.sendUpdate("team_formation_reasoning", reasoning);
}
webSocketService.sendUpdate("team_formation_reasoning", reasoning);
List<AgentInfo> team = parseTeamComposition(reasoning, potentialAgents);
String finalSelection = makeFinalSelection(teamFormationTask, reasoning);
List<AgentInfo> team = parseTeamComposition(finalSelection, potentialAgents);
// Send update about the formed team
if (team != null && !team.isEmpty()) {
webSocketService.sendUpdate("team_formed", team);
}
webSocketService.sendUpdate("team_formed", team);
return team;
}
private String formatReasoning(Map<String, Object> treeData) {
StringBuilder sb = new StringBuilder();
formatNode(treeData, sb, 0);
return sb.toString();
}
private void formatNode(Map<String, Object> 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<Map<String, Object>> children = (List<Map<String, Object>>) node.get("children");
for (Map<String, Object> child : children) {
formatNode(child, sb, depth + 1);
}
}
}
private String makeFinalSelection(String task, String reasoning) {
String prompt = "Based on the following reasoning about the task:\n" + task + "\n\nReasoning:\n" + reasoning +
"\n\nProvide a final team selection in the format: 'Final Team Selection: agent1, agent2, ...'\n" +
"Ensure you select at least one agent if any are suitable for the task.";
return model.generate(prompt, null);
}
private String formatAgentTools(List<AgentInfo> agents) {
return agents.stream()
@ -59,8 +86,10 @@ public class TeamFormation {
.collect(Collectors.joining(", "));
}
private List<AgentInfo> parseTeamComposition(String reasoning, List<AgentInfo> potentialAgents) {
String[] lines = reasoning.split("\n");
private List<AgentInfo> parseTeamComposition(String finalSelection, List<AgentInfo> potentialAgents) {
System.out.println("DEBUG: Final selection: " + finalSelection);
String[] lines = finalSelection.split("\n");
String selectedTeamLine = "";
for (String line : lines) {
if (line.toLowerCase().contains("final team selection")) {
@ -72,8 +101,8 @@ public class TeamFormation {
System.out.println("DEBUG: Selected team line: " + selectedTeamLine);
if (selectedTeamLine.isEmpty()) {
System.out.println("DEBUG: No team selection found in the response.");
return List.of();
System.out.println("DEBUG: No explicit team selection found. Using all potential agents.");
return potentialAgents;
}
List<String> selectedIds = Arrays.asList(selectedTeamLine.split("[,\\s]+"));
@ -85,10 +114,9 @@ public class TeamFormation {
System.out.println("DEBUG: Final team: " + team);
if (team.isEmpty() && !selectedIds.isEmpty()) {
// If no agents were matched but we did find IDs, add the first potential agent as a fallback
team = potentialAgents.stream().limit(1).collect(Collectors.toList());
System.out.println("DEBUG: No agents matched IDs. Using fallback: " + team);
if (team.isEmpty() && !potentialAgents.isEmpty()) {
System.out.println("DEBUG: No agents matched IDs. Using all potential agents as fallback.");
return potentialAgents;
}
return team;

View File

@ -1,126 +0,0 @@
package com.ioa.tool;
import com.ioa.tool.Tool;
public class CommonTools {
@Tool("Search the web for information")
public String webSearch(String query) {
// Implement web search functionality
return "Web search results for: " + query;
}
@Tool("Get current weather information")
public String getWeather(String location) {
// Implement weather API call
return "Weather information for " + location;
}
@Tool("Set a reminder")
public String setReminder(String task, String time) {
// Implement reminder functionality
return "Reminder set for " + task + " at " + time;
}
@Tool("Calculate distances between locations")
public String calculateDistance(String from, String to) {
// Implement distance calculation
return "Distance from " + from + " to " + to;
}
@Tool("Translate text between languages")
public String translate(String text, String fromLang, String toLang) {
// Implement translation API call
return "Translated text from " + fromLang + " to " + toLang;
}
@Tool("Get recipe suggestions")
public String getRecipe(String ingredients) {
// Implement recipe suggestion logic
return "Recipe suggestions for: " + ingredients;
}
@Tool("Check product prices and compare")
public String compareProductPrices(String product) {
// Implement price comparison logic
return "Price comparison for: " + product;
}
@Tool("Book travel arrangements")
public String bookTravel(String destination, String dates) {
// Implement travel booking logic
return "Travel arrangements for " + destination + " on " + dates;
}
@Tool("Find nearby restaurants")
public String findRestaurants(String location, String cuisine) {
// Implement restaurant search
return "Restaurants near " + location + " serving " + cuisine;
}
@Tool("Schedule appointments")
public String scheduleAppointment(String service, String date) {
// Implement appointment scheduling
return "Appointment scheduled for " + service + " on " + date;
}
@Tool("Get movie recommendations")
public String getMovieRecommendations(String genres, String mood) {
// Implement movie recommendation logic
return "Movie recommendations for " + genres + " matching " + mood + " mood";
}
@Tool("Find and book fitness classes")
public String findFitnessClasses(String type, String location) {
// Implement fitness class search and booking
return "Fitness classes for " + type + " near " + location;
}
@Tool("Get public transport information")
public String getPublicTransport(String from, String to) {
// Implement public transport routing
return "Public transport options from " + from + " to " + to;
}
@Tool("Track package deliveries")
public String trackPackage(String trackingNumber) {
// Implement package tracking
return "Tracking information for package: " + trackingNumber;
}
@Tool("Get news updates")
public String getNewsUpdates(String topics) {
// Implement news aggregation
return "Latest news updates on: " + topics;
}
@Tool("Find and apply for jobs")
public String jobSearch(String field, String location) {
// Implement job search functionality
return "Job openings in " + field + " near " + location;
}
@Tool("Get health and medical advice")
public String getMedicalAdvice(String symptoms) {
// Implement medical advice lookup (with disclaimer)
return "General health information for symptoms: " + symptoms;
}
@Tool("Find and book event tickets")
public String findEventTickets(String event, String location) {
// Implement event ticket search and booking
return "Ticket options for " + event + " in " + location;
}
@Tool("Get financial advice and budgeting tips")
public String getFinancialAdvice(String income, String expenses) {
// Implement financial advice generation
return "Financial advice based on income: " + income + " and expenses: " + expenses;
}
@Tool("Find and book home services")
public String findHomeServices(String service, String location) {
// Implement home service search and booking
return "Home service options for " + service + " in " + location;
}
}

View File

@ -1,12 +1,5 @@
package com.ioa.tool;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Tool {
String value();
public interface Tool {
String execute(String... args);
}

View File

@ -4,20 +4,29 @@ import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Component
public class ToolRegistry {
private Map<String, Object> tools = new HashMap<>();
private Map<String, Tool> tools = new HashMap<>();
public void registerTool(String name, Object tool) {
public void registerTool(String name, Tool tool) {
tools.put(name, tool);
}
public Object getTool(String name) {
public Tool getTool(String name) {
return tools.get(name);
}
public Map<String, Object> getAllTools() {
return new HashMap<>(tools);
public boolean hasTool(String name) {
return tools.containsKey(name);
}
public Set<String> getAllToolNames() {
return tools.keySet();
}
public Map<String, Tool> getAllTools() {
return tools;
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class AppointmentSchedulerTool implements Tool {
@Override
public String execute(String... args) {
return "Appointment scheduled for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class DistanceCalculatorTool implements Tool {
@Override
public String execute(String... args) {
return "Distance calculated between: " + String.join(" and ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class FinancialAdviceTool implements Tool {
@Override
public String execute(String... args) {
return "Financial advice for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class FitnessClassFinderTool implements Tool {
@Override
public String execute(String... args) {
return "Fitness classes found for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class MovieRecommendationTool implements Tool {
@Override
public String execute(String... args) {
return "Movie recommendations for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class NewsUpdateTool implements Tool {
@Override
public String execute(String... args) {
return "News updates for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class PriceComparisonTool implements Tool {
@Override
public String execute(String... args) {
return "Price comparison for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class RecipeTool implements Tool {
@Override
public String execute(String... args) {
return "Recipe found for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class ReminderTool implements Tool {
@Override
public String execute(String... args) {
return "Reminder set for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class RestaurantFinderTool implements Tool {
@Override
public String execute(String... args) {
return "Restaurants found near: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class TranslationTool implements Tool {
@Override
public String execute(String... args) {
return "Translation: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class TravelBookingTool implements Tool {
@Override
public String execute(String... args) {
return "Travel booked for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class WeatherTool implements Tool {
@Override
public String execute(String... args) {
return "Weather information for: " + String.join(" ", args);
}
}

View File

@ -0,0 +1,10 @@
package com.ioa.tool.common;
import com.ioa.tool.Tool;
public class WebSearchTool implements Tool {
@Override
public String execute(String... args) {
return "Web search results for: " + String.join(" ", args);
}
}

View File

@ -16,10 +16,10 @@ public class TreeOfThought {
this.webSocketService = webSocketService;
}
public String reason(String task, int depth, int branches) {
public Map<String, Object> reason(String task, int depth, int branches) {
Map<String, Object> treeData = exploreThought(task, depth, branches, "Root");
webSocketService.sendUpdate("tree_of_thought", treeData);
return (String) treeData.getOrDefault("selection", "No selection made");
return treeData;
}
private Map<String, Object> exploreThought(String task, int depth, int branches, String nodeName) {
@ -45,23 +45,26 @@ public class TreeOfThought {
node.put("children", children);
if (depth == 1) {
String selection = selectBestBranch(children);
node.put("selection", selection);
String conclusion = concludeThought(task, nodeName, children);
node.put("conclusion", conclusion);
}
return node;
}
private String evaluateLeaf(String task, String path) {
String prompt = "Evaluate the effectiveness of this approach for the task: " + task + "\nPath: " + path;
String prompt = "Evaluate this approach for the task: " + task + "\nPath: " + path;
return model.generate(prompt, null);
}
private String selectBestBranch(List<Map<String, Object>> children) {
// Logic to select the best branch based on evaluations
// For simplicity, let's just select the first child
Map<String, Object> selectedChild = children.get(0);
selectedChild.put("selected", true);
return (String) selectedChild.get("name");
private String concludeThought(String task, String path, List<Map<String, Object>> children) {
StringBuilder childEvaluations = new StringBuilder();
for (Map<String, Object> child : children) {
childEvaluations.append(child.get("name")).append(": ").append(child.get("evaluation")).append("\n");
}
String prompt = "Conclude on these approaches for the task: " + task +
"\nPath: " + path + "\nEvaluations:\n" + childEvaluations;
return model.generate(prompt, null);
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,15 +1,15 @@
{
"files": {
"main.css": "/static/css/main.e6c13ad2.css",
"main.js": "/static/js/main.03144112.js",
"main.js": "/static/js/main.720bb114.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.03144112.js.map": "/static/js/main.03144112.js.map",
"main.720bb114.js.map": "/static/js/main.720bb114.js.map",
"453.d855a71b.chunk.js.map": "/static/js/453.d855a71b.chunk.js.map"
},
"entrypoints": [
"static/css/main.e6c13ad2.css",
"static/js/main.03144112.js"
"static/js/main.720bb114.js"
]
}

View File

@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.03144112.js"></script><link href="/static/css/main.e6c13ad2.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.720bb114.js"></script><link href="/static/css/main.e6c13ad2.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,39 @@
/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

File diff suppressed because one or more lines are too long

View File

@ -1,19 +1,31 @@
com/ioa/conversation/ConversationFSM$1.class
com/ioa/service/WebSocketService.class
com/ioa/tool/common/WebSearchTool.class
com/ioa/conversation/ConversationFSM.class
com/ioa/conversation/Message.class
com/ioa/util/TreeOfThought.class
com/ioa/tool/common/NewsUpdateTool.class
com/ioa/conversation/ConversationFSM$ConversationStateUpdate.class
com/ioa/tool/common/FinancialAdviceTool.class
com/ioa/team/TeamFormation.class
com/ioa/tool/common/MovieRecommendationTool.class
com/ioa/config/WebSocketConfig.class
com/ioa/tool/common/WeatherTool.class
com/ioa/tool/common/TravelBookingTool.class
com/ioa/tool/common/FitnessClassFinderTool.class
com/ioa/tool/Tool.class
com/ioa/tool/common/ReminderTool.class
com/ioa/tool/common/TranslationTool.class
com/ioa/tool/common/PriceComparisonTool.class
com/ioa/tool/common/RestaurantFinderTool.class
com/ioa/IoASystem.class
com/ioa/tool/ToolRegistry.class
com/ioa/conversation/ConversationState.class
com/ioa/agent/AgentRegistry.class
com/ioa/team/TeamFormation.class
com/ioa/task/TaskManager.class
com/ioa/tool/CommonTools.class
com/ioa/model/BedrockLanguageModel.class
com/ioa/tool/common/DistanceCalculatorTool.class
com/ioa/tool/common/AppointmentSchedulerTool.class
com/ioa/agent/AgentInfo.class
com/ioa/task/Task.class
com/ioa/config/WebSocketConfig.class
com/ioa/task/TaskManager$TaskProgress.class
com/ioa/tool/Tool.class
com/ioa/tool/common/RecipeTool.class