def create_tool_instance(
        self, tool_name: str, format_function: Callable, context=None
    ) -> Optional[Tool]:
        """
        Create, configure, and return an instance of the specified tool.
        Returns None if the tool doesn't exist or instantiation fails.
        """
        tool_class = self.get_tool_class(tool_name)
        if not tool_class:
            logger.warning(f"Tool class not found for '{tool_name}'")
            return None

        try:
            tool_instance = tool_class()
            if hasattr(tool_instance, "llm_format_function"):
                tool_instance.llm_format_function = format_function

            # Set the context on the specific tool instance
            tool_instance.set_context(context)

            return tool_instance

        except Exception as e:
            logger.error(
                f"Error creating or setting context for tool instance '{tool_name}': {e}"
            )
            return None

        Create, configure, and return an instance of the specified tool.
        Returns None if the tool doesn't exist or instantiation fails.
        
py/core/base/agent/tools/registry.py