engine
agentic_ml.core.engine
¶
Research run configuration, shared context and the LLM-agnostic actions.
The actions here (create_trial_action, read_leaderboard_action, select_best)
contain all the real logic behind the agent tools, but import no LLM library. This keeps the
whole research pipeline testable without Strands or a live model, and lets the thin tool
wrappers in :mod:agentic_ml.research.tools simply forward to them.
ResearchConfig
dataclass
¶
ResearchConfig(
metrics: list[str],
primary_metric: str,
maximize: bool,
n_splits: int = 5,
seed: int = 0,
tolerance: float = 1e-06,
timeout: float = 120.0,
iterations: int = 10,
ideas: str | None = None,
partitions: list[Partition] | None = None,
sleep: float = 0.0,
)
Everything that parameterizes a research run.
ResearchContext
dataclass
¶
ResearchContext(
workspace: Workspace,
task: Task,
x_data: DataFrame,
y_data: Series,
schema: DatasetSchema,
config: ResearchConfig,
leaderboard: Leaderboard,
agent_config: AgentConfig,
profile_text: str = "",
history: list[dict] = list(),
)
Mutable state shared between the researcher, the tools and the actions.
Built once by :func:setup_research at the start of a run, then threaded through every
tool call (:mod:agentic_ml.research.tools) and action in this module. Holding no LLM
library reference is what keeps the actions unit-testable without Strands.
Attributes:
| Name | Type | Description |
|---|---|---|
workspace |
Workspace
|
On-disk layout of the run (trial folders, dataset, leaderboard, run
metadata); see :class: |
task |
Task
|
The :class: |
x_data |
DataFrame
|
Feature columns only (target excluded), split out by :func: |
y_data |
Series
|
The target column, row-aligned with |
schema |
DatasetSchema
|
The original :class: |
config |
ResearchConfig
|
The :class: |
leaderboard |
Leaderboard
|
The :class: |
profile_text |
str
|
The aggregate, LLM-safe description of the dataset shown at kickoff (see
:meth: |
history |
list[dict]
|
Every trial summary recorded so far in this process (id, status, metrics,
runtime, description). Kept in memory only — unlike |
agent_config |
AgentConfig
|
The :class: |
setup_research
¶
setup_research(
task: Task,
data: DataFrame,
schema: DatasetSchema,
config: ResearchConfig,
research_dir: str,
agent_config: AgentConfig | None = None,
) -> ResearchContext
Create the workspace, persist the dataset and build a :class:ResearchContext.
agent_config defaults to AgentConfig() (all field defaults) when not passed.
Source code in src/agentic_ml/core/engine.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
create_trial_action
¶
create_trial_action(
ctx: ResearchContext,
description: str,
model_py: str,
helpers_py: str = "",
) -> dict
Write a new trial, evaluate it with the task's fixed scheme and record the result.
Refuses to create a trial once len(ctx.history) already reached ctx.config.iterations
— a hard cap enforced here, not just suggested to the agent via the kickoff prompt. Runs the
trial before checking the cap, so a rejected call never happens: the trial that reaches the
budget still gets created/evaluated normally; iterations_remaining/budget_note in the
returned dict (never error, which is reserved for real evaluation failures) tell the agent
when it's time to call finish_research instead of proposing another trial.
Source code in src/agentic_ml/core/engine.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
read_leaderboard_action
¶
read_leaderboard_action(
ctx: ResearchContext, trial_id: str | None = None
) -> str
Return the leaderboard as CSV text for the agent to reason about.
Source code in src/agentic_ml/core/engine.py
205 206 207 208 209 210 | |
select_best
¶
select_best(ctx: ResearchContext) -> str | None
Return the best successful trial id by the primary metric, or None.
Source code in src/agentic_ml/core/engine.py
213 214 215 | |