> For the complete documentation index, see [llms.txt](https://docs.amesa.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.amesa.com/reference/sdk-reference/train.md).

# Train

## AMESA Train API Documentation

### Overview

The AMESA Train API provides the training infrastructure for agents using Ray for distributed computing. It handles the complete training lifecycle, including algorithm configuration, resource management, checkpointing, and deployment preparation.

### Trainer API

The `Trainer` class is the main interface for training agents.

#### Basic Usage

```python
from composabl import Trainer
from composabl_core.config.trainer_config import (
    BenchmarkConfig,
    RecordConfig,
    PostProcessingConfig,
)

# Create trainer with configuration
trainer = Trainer({
    "target": {
        "local": {"address": "localhost:1337"}
    },
    "env": {
        "name": "my-environment"
    }
})

# Train agent
trainer.train(agent, train_cycles=100)

# Evaluate performance
results = trainer.postprocess(
        agent,
        postprocess_config=PostProcessingConfig(
            file_path="model_files/",
            record=RecordConfig(
                avi_file_name="output.avi",
                gif_file_name="output.gif",
                max_frames=24 * 5,
            ),
            benchmark=BenchmarkConfig(
                num_episodes_per_scenario=2,
                file_name="benchmark.json",
            ),
        ),
    )

# Package for deployment
deployed_agent = trainer.package(agent)

# Clean up resources
trainer.close()
```

### Training Configuration

#### Complete Configuration Example

```python
config = {
    # License (required)
    "license": "your-license-key",
    
    # Training target (required)
    "target": {
        # See Training Targets section for options
    },
    
    # Environment configuration
    "env": {
        "name": "environment-id",
        "init": {
            "param1": "value1",
            "difficulty": "medium"
        }
    }
}
```

### Training Targets

#### Local Target

Train with a simulator running locally:

```python
config = {
    "target": {
        "local": {
            "address": "localhost:1337"
        }
    }
}
```

#### Docker Target

Train with simulators in Docker containers:

```python
config = {
    "target": {
        "docker": {
            "image": "composabl/sim-reactor:latest"
        }
    }
}
```

### Benchmarking

#### Benchmarking

For every scenario on the top-level skill, this will perform \`num\_episodes\_per\_scenario\` amount of inference episodes.

```python
# Evaluate trained agent
eval_results = trainer.postprocess(
        agent,
        postprocess_config=PostProcessingConfig(
            file_path="model_files/",
            benchmark=BenchmarkConfig(
                num_episodes_per_scenario=2,
                file_name="benchmark.json",
            ),
        ),
    )
```

#### Recording

```python
# Evaluation with recording
eval_results = trainer.postprocess(
        agent,
        postprocess_config=PostProcessingConfig(
            file_path="model_files/",
            record=RecordConfig(
                avi_file_name="output.avi",
                gif_file_name="output.gif",
                max_frames=24 * 5,
            ),
        ),
    )
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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 following URL with the `ask` and `goal` query parameters:

```
GET https://docs.amesa.com/reference/sdk-reference/train.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

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.
