Tools

AIOS Tool Manager

The AIOS Tool Manager serves as a central hub for handling tool executions within the kernel. It provides a structured way to load and execute these tools while preventing conflicts.

How Tool Execution Works

  1. Receives the tool request with specific parameters

  2. Prevents tool conflicts by tracking active tool executions

  3. Loads the appropriate tool instance on demand

  4. Executes the tool with the provided parameters

  5. Returns the result back to the requesting component

The Tool Manager implements a key method called address_request that handles incoming tool requests:

def address_request(self, syscall) -> None:
    tool_calls = syscall.tool_calls
    try:
        for tool_call in tool_calls:
            tool_org_and_name, tool_params = (
                tool_call["name"],
                tool_call["parameters"],
            )
            
            # Check if the tool is already being used to prevent conflicts
            if tool_org_and_name not in self.tool_conflict_map.keys():
                # Mark the tool as in-use
                self.tool_conflict_map[tool_org_and_name] = 1
                
                # Load the tool instance dynamically
                tool = self.load_tool_instance(tool_org_and_name)
                
                # Execute the tool with the provided parameters
                tool_result = tool.run(params=tool_params)
                
                # Release the tool for other uses
                self.tool_conflict_map.pop(tool_org_and_name)
                
            return Response(
                response_message=tool_result,
                finished=True
            )
    except Exception as e:
        return Response(
            response_message=f"Tool calling error: {e}",
            finished=True
        )

Dynamic Tool Loading

One of the most powerful features of the Tool Manager is its ability to dynamically load tool instances when needed:

def load_tool_instance(self, tool_org_and_name):
    # Create a new instance of the requested tool
    tool_instance = AutoTool.from_preloaded(tool_org_and_name)
    return tool_instance

Details of how to use AutoTool can be found in https://github.com/agiresearch/Cerebrum/blob/main/cerebrum/interface/__init__.py.

Last updated