> ## 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.

# AgentPredictorWorker

> AID.selector.interface.AgentPredictorWorker

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

Step 18: AIDflow Production Agent: The Deployment Artifact.

This is the final, promoted agent destined for production inference.
Unlike the ensemble agents used during training, this class encapsulates
the entire 'winning' logic—integrating its specific fitting strategy,
associated preprocessing encoders, and feature mappings into a single,
deployable unit.

Strategic Role:

* Inference Encapsulation: Acts as the sole interface for production scoring,
  removing all ensemble complexity to provide a lean, high-performance API.
* End-to-End Lineage: Bridges the gap between raw input data and final
  probability scores by internalizing the preprocessing pipeline.
* Governance & Audit: Maintains an immutable record of selected features
  and encoder states, ensuring that production predictions are perfectly
  reproducible and compliant with model governance standards.

> [!NOTE]
>
> * AgentPredictorWorker is automatically executed during Step 17 (Champion Promotion)    based on user configuration.
> * Can be run independently to bypass Step 17 when feature tuning or overview analysis    is not required.

#### Parameters

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

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

> [!NOTE]
>
> Inputs full schema can be obtained by `ctx.workers.champion_predictor.spec` with main params:
>
> <table>
>   <tbody>
>     <tr><td>`inputs    == None`</td><td>→</td><td>pipeline data context</td></tr>
>     <tr><td>`train_set != None`</td><td>→</td><td>custom train data for champion\_predictor training</td></tr>
>     <tr><td>`test_set  != None`</td><td>→</td><td>custom test data for champion\_predictor test metrics</td></tr>
>     <tr><td>`features  != None`</td><td>→</td><td>custom feature subset used for training champion\_predictor</td></tr>
>   </tbody>
> </table>

#### Returns

*`AgentPredictorWorker`*
The populated instance of AgentPredictorWorker.

> [!NOTE]
>
> Populates attributes into the worker context:
>
> <table>
>   <tbody>
>     <tr><td>`model`</td><td>→</td><td>ctx.workers.champion\_predictor</td></tr>
>     <tr><td>`inputs`</td><td>→</td><td>ctx.workers.champion\_predictor.spec</td></tr>
>     <tr><td>`result`</td><td>→</td><td>ctx.workers.champion\_predictor.result</td></tr>
>     <tr><td>`state`</td><td>→</td><td>ctx.workers.champion\_predictor.state</td></tr>
>     <tr><td>`report`</td><td>→</td><td>ctx.workers.champion\_predictor.report</td></tr>
>     <tr><td>`stats`</td><td>→</td><td>ctx.workers.champion\_predictor.stats</td></tr>
>     <tr><td>`fitter`</td><td>→</td><td>ctx.workers.champion\_predictor.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.champion_predictor.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.champion_predictor.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.champion_predictor()    # 4. direct champion agent training - skipping selection overview and tuning
```

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.champion_predictor
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.champion_predictor.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.champion_predictor.fitter
```

The fitted fitter provides all populated attributes.

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
fitter    = ctx.workers.champion_predictor.fitter
result_   = fitter.result
features_ = fitter.features
params_   = fitter.params
stats_    = fitter.stats
model_    = fitter.model
```

Direct choice and parametrization of internal fitter:

```python theme={"theme":{"light":"dracula-soft","dark":"dracula"}}
fx  = ctx.workers.champion_predictor.fitters[0]
prm = dict(
    agent_choice = 1
)
champion_predictor = ctx.workers.champion_predictor(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',
    val_size = 0.3
)
champion_predictor = ctx.workers.champion_predictor(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.