Browse documentation
aner.agent · Reference

Delegate an approved energy prediction

Give a specialist the approved observation, limit its calls and verify its scientific report from the native receipt.

Released in Aner 0.1.2Aner 0.1.2 or newer

A scientist has approved one prediction for building observation 401. A second agent can propose the tool call, obtain the fitted model’s answer and give a colleague the receipt. In the building pilot the specialist returned 108 kWh. A request for row 402 in the same building received a scope denial. Delegation first appeared in 0.1.2-dev.6. Use Aner 0.1.2 on macOS or Linux for the Aner notebook client, offline verifier and vLLM example. Scientific agent reference

The scientist grants four submissions to one specialist. Native Aner and the external notebook share those four calls and the same row 401 receipt.

Grant one specialist access to row 401

Start in a fresh project directory. Save the coordinator, specialist and synthetic energy CSV at the paths used below. Start local Ollama with qwen2.5:14b-instruct available. Run the coordinator from the project root to create energy-401.run.

Run aner run examples/agent_energy.aner --prod from the project root.

Open an Aner notebook at the same root. Review the proposal, row and fitted input identity in this cell before approving anything.

aner
import aner.agent
let run = agent.open_run("energy-401.run")
print(run.replay())

If the proposal matches your scientific intent, approve it and grant four submissions to the named specialist. The handoff must be issued before the first dispatch. Record the identifier printed by delegation_id() for use after restarting.

aner
print(run.approve())
let task = run.delegate_prediction("energy-specialist", max_calls: 4)
print(task.delegation_id())
print(task.remaining_calls())

Run the specialist from the project root. Requesting the same handoff again returns its existing identity and budget. A different recipient or limit requires a different approval.

Run aner run examples/agent_energy_delegation.aner --prod from the project root.

The specialist makes its own model turn. Its typed argument gives it access to the approved prediction. Inside the downloadable function, fit and scaler come from the training buildings and observations holds the validation buildings.

aner
fn energy_specialist(task: PredictionDelegation, request: String, fit: ContextLinearModel,
                     scaler: FeatureLedger, observations: AdaptiveFrame) -> String {
    let local = llm.client(provider: "ollama", model: "qwen2.5:14b-instruct", endpoint: "http://127.0.0.1:11434")
    let proposal = local.prediction_turn(request)
    print(proposal.text())
    return task.predict_delegated(proposal, fit, scaler, observations)
}

The model proposes predict_observation and a decimal row ID. Aner checks the typed proposal, the active grant, the row and the fitted inputs. On success the caller receives JSON containing row_id, numeric value, unit and evidence_id. The scientist retains pause, resume and cancellation through the original run. Keep the original journal on one local filesystem so competing processes coordinate through the same file lock. The recipient name and handoff ID select a grant within that trusted project. Anyone with full operating system access to the journal retains the authority of its local account. Scientist controls and crash recovery

Inspect the allowance after a restart

In a fresh notebook session, use the saved ID. The default allowance is eight submissions and the accepted range is 1 through 1024. Each admitted tool request uses one submission, including a scope denial and a returned copy of an existing prediction. The charge is recorded before dispatch and survives an interrupted request. An exhausted worker can still read its receipt and reports.

aner
import aner.agent
let task = agent.open_delegation("energy-401.run", "energy-specialist", "REPLACE_WITH_DELEGATION_ID")
print(task.remaining_calls())
print(task.replay_delegation())
print(task.prediction_report("point_prediction"))
print(task.prediction_report("prediction_interval_95"))

The point report includes the exact recorded measurement and receipt ID. The fitted model supplies a point estimate only. Its 95% prediction interval has status unavailable, reason model_provides_no_prediction_interval and the same receipt ID. Reading either report requires only the journal. If a process dies after recording dispatch intent and before storing a receipt, the owner sees reconciliation_required. The runtime blocks automatic redispatch because it cannot establish whether the predictor finished.

Choose the specialist’s local model interface

The downloadable coordinator and specialist select local Ollama. To use the vLLM engine, select the same client in both programs. On Apple silicon, vLLM 0.34.0 with the Metal plugin served all ten coordinator and specialist calls across two fits. The specialist received 108 kWh on the original fixture and 145 kWh after shifting the training targets. It proposed row 402 before and after each approved prediction, and each request received a scope denial. Each fit produced one native receipt. This configuration uses the served model name energy-qwen on loopback, a Qwen2.5 1.5B Instruct model and the Hermes tool parser. The typed call carries the requested row. Aner validates the returned function and argument before the specialist can dispatch it. Custom registered function proposals through llm.tool_turn currently use Ollama. vLLM tool calling

aner
import aner.llm
let client = llm.client(provider: "vllm", model: "energy-qwen", endpoint: "http://127.0.0.1:18743/v1")
let proposal = client.prediction_turn("Predict energy for validation observation 401.")
print(proposal.text())

Use the same handoff from an external notebook

Save the delegated MCP service as examples/agent_energy_delegated_mcp.aner. Replace REPLACE_WITH_DELEGATION_ID in that file with the scientist’s saved ID. The service opens that handoff and exposes one tool over stdio. The grant, remaining calls and prediction receipt are shared with the native specialist.

Open the Aner notebook at the project root. Select the delegated service as shown below. With two submissions remaining, this cell requests the approved result and tests the scope boundary. Each call discovers and invokes the prediction tool over stdio. External notebook setup

aner
import aner.agent
let service = "examples/agent_energy_delegated_mcp.aner"
print(agent.mcp_prediction(service, 401))
print(agent.mcp_prediction(service, 402))

Verify who produced the prediction

The public study interleaved native and external requests. Each interface received one row 402 denial and one row 401 result. All four charged submissions referred to the original grant. The next external request received delegated tool-call budget exhausted. Two fresh processes replayed the same receipt with the CSV removed. Across six runs, a separate direct Aner fit matched every agent prediction. Raising every training target by 37 kWh moved the prediction from 108 kWh to 145 kWh even when the measured validation target was replaced with −999 kWh.

Direct Aner fits and specialist receipts agree at 108 kWh on the original data and 145 kWh after raising the training targets.

For your own study, run the native exporter and retain its printed manifest digest separately. Save either report printed by prediction_report as a JSON file. For the recorded sample, put the manifest and telemetry in a directory named evidence. Save the point report and interval report alongside that directory. Open the Aner verifier example or run this cell.

aner
import aner.agent
let digest = "03859428abd52479ab320325c052853ada8d46b9ea2a926ea1bcc6e6b98cead0"
print(agent.verify_run("evidence", digest, 401, 402, 108.0, "kWh", "energy-specialist", "interval.json"))

Use point.json to verify the point report. The verifier reconstructs the journal and checks the specialist that dispatched, its charged submission, the native receipt and the recorded scope denial. Supplying a grant that only retrieved an existing result fails this check. For your own study supply the digest you retained separately.

Aner documentation · Reference and guides