> ## Documentation Index
> Fetch the complete documentation index at: https://aidflow.aigensys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AgentSelectorWorker

> AID.selector.interface.AgentSelectorWorker

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
from AID.selector.interface import AgentSelectorWorker
```

Step 17: Champion Promotion (The Executive Decision).

The final gate of the pipeline. This method aggregates evidence from
the Prediction, Comparison, and Transition steps to officially promote
one agent as the 'Champion.' It locks the winning model's state and
generates a SHAP-based explainability report for audit purposes.

#### Parameters

**`inputs`** : *`AgentSelectorInput`*
Custom selection configuration. If None, resolves from 'test.ml' state.

**`**kwargs`** : *`dict`*
Additional parameters passed to the Selector worker.

> [!NOTE]
>
> Inputs full schema can be obtained by `ctx.workers.agent_selector.spec` with main params:
>
> <table>
>   <tbody>
>     <tr><td>`inputs == None`</td><td>→</td><td>pipeline data context</td></tr>
>     <tr><td>`data   != None`</td><td>→</td><td>custom data for agent\_selector overview and choice</td></tr>
>   </tbody>
> </table>

#### Returns

*`AgentSelectorWorker`*
The populated instance of AgentSelectorWorker.

> [!NOTE]
>
> Populates attributes into the worker context:
>
> <table>
>   <tbody>
>     <tr><td>`model`</td><td>→</td><td>ctx.workers.agent\_selector</td></tr>
>     <tr><td>`inputs`</td><td>→</td><td>ctx.workers.agent\_selector.spec</td></tr>
>     <tr><td>`result`</td><td>→</td><td>ctx.workers.agent\_selector.result</td></tr>
>     <tr><td>`state`</td><td>→</td><td>ctx.workers.agent\_selector.state</td></tr>
>     <tr><td>`report`</td><td>→</td><td>ctx.workers.agent\_selector.report</td></tr>
>     <tr><td>`stats`</td><td>→</td><td>ctx.workers.agent\_selector.stats</td></tr>
>     <tr><td>`fitter`</td><td>→</td><td>ctx.workers.agent\_selector.fitter</td></tr>
>   </tbody>
> </table>

> [!NOTE]
>
> Registers data into the datasets context:
>
> <table>
>   <tbody>
>     <tr><td>`predictions`</td><td>→</td><td>predictions.train.champion\_agent</td></tr>
>     <tr><td>`predictions`</td><td>→</td><td>predictions.test.champion\_agent</td></tr>
>     <tr><td>`features`</td><td>→</td><td>features.champion\_agent.predicted</td></tr>
>     <tr><td>`features`</td><td>→</td><td>features.champion\_agent.selected</td></tr>
>     <tr><td>`dropped`</td><td>→</td><td>features.champion\_agent.dropped</td></tr>
>     <tr><td>`stats`</td><td>→</td><td>stats.agents.champion\_agent</td></tr>
>     <tr><td>`stats`</td><td>→</td><td>stats.agents.selection</td></tr>
>   </tbody>
> </table>

#### Examples

Defining the Project Context (Control Plane) & Project Scope:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
import aidflow as aid

ctx = aid.ProjectContext()

ctx.genesis(
    project      = 'test',
    input_data   = 'test.csv',
    target       = 'target',
    yy_mm        = 'decision_date',
    yy_mm_format = '%Y-%m-%d'
)
ctx.params()
```

### Worker → Model → Fitter

Accessing worker's inputs schema → parameters & types (*shown in the display output*):

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.workers.agent_selector.spec
```

Accessing model's fitter options and schema → parameters & types
(*shown in the display output*):

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.workers.agent_selector.fitters
```

Executing workers with defaults → auto provided by the context:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.flow.process('data')        # 1. process workers 0-3 → data load - data stability
ctx.flow.process('encoding')    # 2. process workers 4-9 → train and apply encoding to train and test samples
ctx.flow.process('training')    # 3. process workers 10-13 → agents trainining on encoded train sample
ctx.workers.agents_comparator() # 4. process agents comparator on test sample to obtain assessment for selection
ctx.workers.agent_selector()    # 5. champion agent selection
```

Once worker has been executed, thus its main model has been built,    we have access to all populated attributes.

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
worker   = ctx.workers.agent_selector
inputs   = worker.spec.inputs
result   = worker.result
state    = worker.state
features = worker.features
params   = worker.params
stats    = worker.stats
fitter   = worker.fitter  # jump to chosen internal fitter
...
```

View to model report of executed worker:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.workers.agent_selector.report.show()
```

### Model → Fitter

Once worker has been executed, we can obtain internal fitter state    and its parametrization (*shown in the display output*):

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
ctx.workers.agent_selector.fitter
```

The fitted fitter provides all populated attributes.

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
fitter    = ctx.workers.agent_selector.fitter
params_   = fitter.params
stats_    = fitter.stats
```

Direct choice and parametrization of internal fitter:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
fx  = ctx.workers.agent_selector.fitters[0]
prm = dict(
    alpha = 0.05,
    proba_bins = 15,
    agent_choice = 1
)
agent_selector = ctx.workers.agent_selector(fx_choice = fx, fx_params = prm)
```

In the experimenting phase, when various parametrization settings might be under testing    (*note that internal fitter API (fx\_config) can vary with respect to chosen fitter*):

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
cfg = dict(
    target = 'target2',
    preprocess = True
)
agent_selector = ctx.workers.agent_selector(fx_config = cfg)
```

#### Attributes

> [!NOTE]
>
> All worker attributes return `None` prior its execution.

| Attribute | Type | Description |
| :- | :- | :- |
| `inputs` | `ModelInput` | Registered populated inputs containing execution timestamps and feature definitions. |
| `result` | `ModelResult` | Execution output payload containing model predictions and fit results. |
| `fitter` | `Fitter` | Underlying fitted estimator instance. |
| `state` | `ModelState` | Consolidated model state (fitter, choice, params, features, report, stats). |
| `report` | `DashboardInterface` | Interactive report interface. Call `report.show()` to render the visualization dashboard. |
| `stats` | `FitStats` | Performance metrics and training metadata gathered during fitting. |
| `features` | `TransResCols` | Feature schema dataclass required for downstream inference. |
| `params` | `tuple[FitParams, Parameters, ...]` | Tuple of fit settings, execution parameters, optionally transformer parameters. |
| `choice` | `RegGet.Choice` | Active configuration parameters including internal fitter choice (`fx_choice`). |
| `model_signature` | `str` | Unique hash identifier for the fitted model instance. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.