model
agentic_ml.core.model
¶
The light, production-ready model exported from a research run.
:class:AgenticModel is intentionally free of any LLM / Strands dependency. It binds to the
code of a single trial (its model.py and optional helpers.py) and delegates
fit/predict/save/load to that trial's Model class.
Loading an :class:AgenticModel executes the trial's code. Treat saved artifacts with the
same trust as a pickle.
NotFittedError
¶
Bases: Exception
Raised when predict or save is called before fit.
AgenticModel
¶
AgenticModel(
model_py: str,
helpers_py: str,
model_cls: type,
inner: object | None = None,
)
Wraps a trial's Model implementation as a reusable, scikit-learn-like estimator.
An :class:AgenticModel holds no model logic itself: it stores the trial's source code
(model.py / helpers.py) and the Model class loaded from it, and forwards
fit/predict/save/load to an instance of that class. This is what lets a
research run export a plain, LLM-free object that still runs the exact code the agent
wrote and evaluated.
Attributes:
| Name | Type | Description |
|---|---|---|
is_fitted |
bool
|
Whether :meth: |
Build a model wrapper. Prefer :meth:from_trial or :meth:load over this directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_py
|
str
|
Source code of the trial's |
required |
helpers_py
|
str
|
Source code of the trial's optional |
required |
model_cls
|
type
|
The |
required |
inner
|
object | None
|
An already-fitted instance of |
None
|
Source code in src/agentic_ml/core/model.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
is_fitted
property
¶
is_fitted: bool
Whether the model currently has a fitted (or loaded) inner instance.
from_trial
classmethod
¶
from_trial(trial_dir: str | Path) -> AgenticModel
Build an (unfitted) model bound to the code in trial_dir.
Reads model.py (and helpers.py if present) from trial_dir and loads the
Model class from them, without fitting or restoring any state. Typically called
via Researcher.export_model right after research finishes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trial_dir
|
str | Path
|
Directory containing a trial's |
required |
Returns:
| Type | Description |
|---|---|
AgenticModel
|
A new, unfitted :class: |
Source code in src/agentic_ml/core/model.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
fit
¶
fit(X: object, y: object) -> AgenticModel
Fit a fresh instance of the underlying trial model.
Instantiates model_cls and calls its fit(X, y), replacing any previously
fitted state. Safe to call more than once; each call starts from a fresh instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
object
|
Feature data in whatever shape the trial's |
required |
y
|
object
|
Target values aligned with |
required |
Returns:
| Type | Description |
|---|---|
AgenticModel
|
|
Source code in src/agentic_ml/core/model.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
predict
¶
predict(X: object) -> object
Predict on new data using the fitted inner model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
object
|
Feature data in the same shape accepted by :meth: |
required |
Returns:
| Type | Description |
|---|---|
object
|
The trial's raw prediction output (typically a |
object
|
|
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If called before :meth: |
Source code in src/agentic_ml/core/model.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
save
¶
save(path: str | Path) -> None
Persist the trial code plus the fitted state to path.
Writes model.py (and helpers.py if non-empty), delegates saving the fitted
state to the inner model's own save under a state/ subdirectory, and writes a
small manifest.json recording the contract version. The result is self-contained:
:meth:load needs only this directory to reconstruct the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Directory to write to; created (with parents) if it does not exist. |
required |
Raises:
| Type | Description |
|---|---|
NotFittedError
|
If called before :meth: |
Source code in src/agentic_ml/core/model.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
load
classmethod
¶
load(path: str | Path) -> AgenticModel
Restore a fitted model previously written by :meth:save.
Loads the Model class from the saved model.py/helpers.py, then calls its
load(state_dir) to restore the fitted inner instance. This executes the trial's
saved code — treat saved artifacts with the same trust as a pickle (see the module
docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Directory previously written by :meth: |
required |
Returns:
| Type | Description |
|---|---|
AgenticModel
|
A fitted :class: |
Source code in src/agentic_ml/core/model.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |