# Main

## AMESA Main API Documentation

### Overview

The AMESA Main API is the primary interface for the AMESA SDK. It provides a unified wrapper that combines functionality from `composabl-core`, `composabl-train`, and `composabl-cli` into a single, convenient package.

### Installation

```bash
pip install composabl
```

This single installation provides access to all AMESA SDK components.

### Package Structure

The main package re-exports all public APIs from:

* **composabl\_core**: Core components and building blocks
* **composabl\_train**: Training infrastructure
* **composabl\_cli**: Command-line interface (available via `composabl` command)

### Basic Usage

#### Importing

All functionality is available through the main `composabl` import:

```python
from composabl import (
    # Core Components
    Agent, Skill, Sensor, Scenario, Perceptor,
    
    # Skill Types
    SkillTeacher, SkillController, SkillSelector,
    SkillCoordinatedSet, SkillCoordinatedPopulation,
    
    # Goals
    MaintainGoal, ApproachGoal, AvoidGoal, 
    MaximizeGoal, MinimizeGoal,
    
    # Training
    Trainer,
)
```

#### Environment Setup

Before using AMESA, configure your environment:

```python
import os

# Required: Set your license key
os.environ["AMESA_LICENSE"] = "your-license-key"

# Required: Accept the EULA
os.environ["AMESA_EULA_AGREED"] = "1"

# Optional: Set log level
os.environ["LOGLEVEL"] = "INFO"  # DEBUG, INFO, WARNING, ERROR
```

#### Goal Types

```python
# Maintain a value
MaintainGoal(sensor_name, description, target, stop_distance)

# Approach a target
ApproachGoal(sensor_name, description, target)

# Avoid a value
AvoidGoal(sensor_name, description, target, stop_distance)

# Maximize a metric
MaximizeGoal(sensor_name, description)

# Minimize a metric
MinimizeGoal(sensor_name, description)
```

#### Configuration Options

```python
config = {
    "license": "key",
    "target": {
        # Choose one:
        "local": {"address": "host:port"},
        "docker": {"image": "name:tag"}
    },
    "env": {
        "name": "environment-id",
        "init": {}  # Environment parameters
    },
    "resources": {
        "sim_count": 4,
        "num_workers": 2,
        "num_gpus": 0
    }
}
```

### Core Classes

```python
# Agent - Main orchestrator
agent = Agent()
agent.add_sensor(sensor)
agent.add_sensors([sensor1, sensor2])
agent.add_skill(skill)
agent.add_skills([skill1, skill2])
agent.add_perceptor(perceptor)
agent.export(path)
agent.draw()  # Visualize structure

# Skill - Behavior module
skill = Skill(name, implementation)

# Sensor - Data transformer
sensor = Sensor(name, description, extractor_fn)

# Scenario - Initial conditions
scenario = Scenario(variable_dict)

# Trainer - Training orchestrator
trainer = Trainer(config)
trainer.train(agent, train_cycles)
trainer.evaluate(agent, num_episodes)
trainer.package(agent)
trainer.close()
```

### Migration Guide

If migrating from separate imports:

```python
# Old way
from composabl_core import Agent, Skill
from composabl_train import Trainer

# New way (recommended)
from composabl import Agent, Skill, Trainer
```

#### Debug Mode

Enable detailed logging:

```python
import logging
logging.basicConfig(level=logging.DEBUG)

# Or via environment
os.environ["LOGLEVEL"] = "DEBUG"
```


---

# 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.amesa.com/reference/sdk-reference/main.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.
