# Creating custom optimization packs

To create a custom optimization pack, the following fixed directory structure and several YAML manifests need to be created.

#### Optimization pack directory structure <a href="#directory-structure" id="directory-structure"></a>

```
my_dir
  | optimizationPack.yaml
  | component-types
           | componentType1.yaml
  | metrics
           | metricsGroup1.yaml
  | parameters
           | parametersGroup1.yaml
  | telemetry-providers
           | provider1.yaml
```

#### Optimization pack manifest <a href="#optimization-pack-manifest" id="optimization-pack-manifest"></a>

The `optimizationPack.yaml` file is the manifest of the optimization pack to be created, which should always be named `optimizationPack` and have the following structure:

```yaml
name: My Pack
description: An optimization pack to optimize a custom framework
version: 0.0.1
tags: [Apache, Framework]
weight: 1
```

| Field         | Type            | Value restrictions                     | Is required | Default value  | Description                                                                                    |
| ------------- | --------------- | -------------------------------------- | ----------- | -------------- | ---------------------------------------------------------------------------------------------- |
| `name`        | string          | It should not contain spaces.          | TRUE        |                | The name of the optimization pack.                                                             |
| `description` | string          |                                        | TRUE        |                | A description to characterize the optimization pack.                                           |
| `weight`      | integer         | weight > 0                             | TRUE        |                | A weight to be associated to the optimization pack. This field is used for licensing purposes. |
| `version`     | string          | It should match the regexp: `\d.\d.\d` | TRUE        |                | The version of the optimization pack.                                                          |
| `tags`        | array of string |                                        | FALSE       | An empty array | A set of tags to make the optimization pack more easily searchable and discoverable.           |

#### Component types <a href="#component-types" id="component-types"></a>

The `component-types` directory should contain the manifests of the component types to be included in the optimization pack. No particular naming constraint is enforced on those manifests. See [Component Types template](/akamas-docs/reference/glossary/component-type.md) for details on the structure of those manifests.

#### Metrics <a href="#metrics" id="metrics"></a>

The `metrics` directory should contain the manifests of the groups of metrics to be included in the optimization pack. No particular naming constraint is enforced on those manifests. See [Metric template](/akamas-docs/reference/construct-templates/metric-template.md) for details on the structure of those manifests.

#### Parameters <a href="#parameters" id="parameters"></a>

The `parameters` directory should contain the manifests of the groups of parameters to be included in the optimization pack. No particular naming constraint is enforced on those manifests. See [Parameter template](/akamas-docs/reference/construct-templates/parameter-template.md) for details on the structure of those manifests.

### Building optimization pack descriptor <a href="#using-the-akamas-cli-to-build-the-final-optimization-pack-descriptor" id="using-the-akamas-cli-to-build-the-final-optimization-pack-descriptor"></a>

The following command needs to be executed to produce the final JSON descriptor:

```bash
akamas build optimization-pack PATH_TO_THE_DIRECTORY
```

After this, the optimization pack can be installed and used.

### Installing an Optimization Pack

Once the JSON descriptor is generated, the optimization pack can be created in Akamas by executing the following command:

```
akamas install optimization-pack PATH_TO_THE_JSON
```

### Upgrading an Optimization Pack

To upgrade an optimization pack, ensure the following:

1. The name of the optimization pack in the updated JSON is identical to the one already present in Akamas.
2. A new version is specified in the updated JSON.

Run the following command to apply the upgrade:

```
akamas install -f optimization-pack PATH_TO_THE_JSON
```

This will replace the existing optimization pack with the updated version.

### Rollback to a Previous Version

To rollback to a previous version of the optimization pack, execute the following command, specifying the desired version:

```
akamas install -f optimization-pack -v OLD_VERSION
```

This will revert the optimization pack in Akamas to the specified version.

***

By following these steps, you can effectively create, upgrade, and manage optimization packs in Akamas.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.akamas.io/akamas-docs/knowledge-base/creating-custom-optimization-packs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
