Local tasks generate tabs on pages and are defined in a {module}.links.action.yml file in the root directory of your module. In this file, you have two or more local task declarations like:
mastering_drupal_8.test:
route_name: mastering_drupal_8.test_page
title: 'Test'
appears_on:
- mastering_drupal_8.test_page
For each local action element, you have the following attributes:
- route_name: Machine name of the route that the local action directs to
- title: Title shown on the local action
- weight: Determines the order of the local actions; higher weight links appear later
- appears_on: Array of routes that the local action is displayed on
The local task, where the route_name matches the base_route, is the default local task that is active when the user visits the route.

Like menu links, you are able to create local actions dynamically by adding a deriver to the local actions YAML file. The getDerivativeDefinitions() function returns an array in the same format as the local tasks YAML element.