Compare energy predictors with a typed agent tool
Register a checked Aner function and measure two energy predictors on unseen buildings.
Released in Aner 0.1.2Aner 0.1.2 or newerCan an energy model trained on one set of buildings predict demand in buildings it has never seen? This example gives a local language model access to a scientist’s named prediction function. Aner fits and runs two Ridge regressions. A separate evaluator compares their predictions with the withheld energy measurements. For local model setup and tool responses, see the language model guide.
Register the function
In Aner 0.1.2, declare both input types and the return type, then register the function by its Aner name. Registration checks the function body and its read only effect before it creates an AgentTool.
import aner.agent
import aner.llm
import aner.ml
import aner.data
fn predict_energy(model: FittedRidge, observations: AdaptiveFrame) -> ContextPrediction {
return model.predict(observations)
}
let tool = agent.register_tool(predict_energy, "read_only")This version supports functions with two arguments. The first must be a FittedRidge or FittedHistogramBoost, the second an AdaptiveFrame, and the declared return type a ContextPrediction. Aner checks the function and its called helpers. They can project features, inspect the row count, slice a view and predict. Global captures, fitting, I/O and mutable bindings are rejected at registration.
On the model connection, the function takes one string named scope. In Aner, the scientist supplies the trusted fit, the observation view and the scope they expect. The native response carries the registration identity. Dispatch checks that identity and scope before entering the function.
Run both predictors on held out buildings
Download the complete comparison example, its Aner source and the public building data. Save the CSV at examples/fixtures/contextual/energy_comparison.csv under your working directory. Run a local Ollama service with qwen2.5:14b-instruct installed, then execute aner run examples/agent_energy_comparison.aner --prod from the project root.
The example registers one function and asks for a separate tool call for each predictor. Use different scopes for the two fits. The following cells use the client, training fit and split from the downloadable example. The scientist can inspect the returned proposal before executing the next call.
let occupancy_turn = llm.tool_turn(client, tool, "unseen_occupancy",
"Call predict_energy for the exact scope unseen_occupancy.")
print(occupancy_turn.text())
let occupancy_agent = agent.call_tool(tool, occupancy_turn, "unseen_occupancy",
richer_fit, occupancy.test().features())
print(occupancy_agent.unit())Pass a nonempty validation or test view. Aner exposes only its features to the function and checks that the result covers the exact granted row IDs in order. The target unit comes from the fitted model. The registration and proposal live in the current interpreter session. Calling agent.call_tool again runs the read only function again. After restarting, register the function and obtain a new proposal.
How the comparison was run
The synthetic study contains 360 observations from 30 buildings, with 12 observations per building. Twenty four buildings supply the development data. Four folds hold out whole buildings, and each fold fits its preprocessing on its own training buildings. Both models use Ridge regression with penalty alpha = 1 and training only standardization. The baseline uses outdoor temperature. The candidate adds occupancy and the number of degrees that the temperature falls below 18 °C. The final six buildings have 12 synthetic daily readings each.
The 72 final energy measurements are withheld from the public CSV, the model connection and the predictor fits. Each registered tool result is paired with the direct Aner prediction by observation ID. A separate scorer joins the frozen prediction submission to the private measurements. Replaying the accepted submission reads its recorded score. Submitting revised predictions cannot consume a second look at the same held out buildings.
Error on unseen buildings
Across the 72 held out daily readings, adding occupancy and heating gap reduced root mean squared error (RMSE) by 13.04 kWh, or 74.0%. The richer predictor had lower error in each of the six buildings.
| Held out observations | Temperature RMSE (kWh) | Temperature, occupancy and heating gap RMSE (kWh) |
|---|---|---|
| All 72 readings | 17.62 | 4.58 |
| B25 | 19.45 | 5.04 |
| B26 | 14.90 | 3.38 |
| B27 | 20.11 | 6.21 |
| B28 | 18.09 | 2.43 |
| B29 | 16.02 | 6.29 |
| B30 | 16.58 | 2.22 |

The local Qwen model proposed the two scoped calls. All 144 predictions from those calls matched direct Aner execution exactly. A separate implementation fitted both Ridge models from the public training data. Its largest disagreement with Aner was below 0.00000001 kWh, the tolerance set before scoring.
The two proposal cells took 2.19 seconds in this run. Direct prediction for both fitted models took about 0.13 milliseconds. These elapsed times include interpreter cell overhead. Human review time was unmeasured. The agent adds an inspectable proposal to an existing scientific calculation. The accuracy gain comes from the additional predictors.
This study used synthetic data whose generation explicitly depends on occupancy and heating demand. Testing on measured energy from other buildings would be necessary to establish how well these predictors transfer to an actual building portfolio.
See the Scientific agents in Aner module reference for the shared API.