Browse documentation
aner.agent · Reference

Synchronous and asynchronous agent execution

Choose how to run a model turn or an approved prediction, check its progress and retrieve the result.

Released in Aner 0.1.2Aner 0.1.2 or newer

In Aner 0.1.2, a notebook can fit a scientific model while a local language model prepares a proposal. It can also schedule an approved prediction in the background and read the receipt later. Use the synchronous call when the next statement needs its result. Use the asynchronous form when the caller has independent work to do.

OperationSynchronous call and returnAsynchronous call and return
Propose one observation on loopback Ollama or a compatible chat completions endpointllm.prediction_turn(client, question) → LLMResponsellm.prediction_turn_async(client, question) → LLMTurnTask
Propose a registered read only tool call on loopback Ollamallm.tool_turn(client, tool, scope, question) → LLMResponsellm.tool_turn_async(client, tool, scope, question) → LLMTurnTask
Attempt one step of a durable prediction runrun.step(fit, scaler, observations) → journal state as Stringrun.step_async(fit, scaler, observations) → PredictionStepTask

Overlap a proposal with model fitting

Run the complete building energy example at the project root with the energy CSV and the local Ollama model used in the prediction guide. It submits the request before fitting the scaler and linear model. The following lines show how to collect the response.

aner
import aner.llm
let local = llm.client(provider: "ollama", model: "qwen2.5:14b-instruct", endpoint: "http://127.0.0.1:11434")
let pending = llm.prediction_turn_async(local, "Predict energy for validation observation 401.")
print(pending.ready())
let proposal = pending.wait()
print(proposal.text())

ready() polls once and returns a Bool. A fast operation may already be ready at the first poll. wait() blocks until it can return the checked result or raise the task’s error. A second wait, including through a copy of the handle, observes the same outcome. Two separate submissions make two independent attempts. For registered tools, the completed proposal still goes through the existing scope, registration and input checks at dispatch. Registered prediction tools

Schedule an approved step

The complete example creates energy-async-401.run in awaiting_approval. In the same notebook session, inspect the proposal, row and fitted inputs. If you authorize that prediction, execute the following cell. Here run, fit, scaler and split are the variables from the example.

aner
print(run.approve())
let work = run.step_async(fit, scaler, split.validation())
print(work.ready())
let outcome = work.wait()
print(outcome)
if outcome == "completed" {
    print(run.value())
    print(run.unit())
}

The synchronous equivalent is let outcome = run.step(fit, scaler, split.validation()). Both paths read the same approval and scientific binding when dispatching. They share the journal’s execution lease, dispatch intent and receipt. Concurrent attempts may return an intermediate journal state while another worker owns the lease. Read run.state() to inspect subsequent progress. Read run.value() and run.unit() after completion.

Capacity, errors and recovery

Each interpreter process shares four background workers across these calls and admits up to 32 requests including queued and running work. Submission at capacity raises an error immediately. Wait for an outstanding task before submitting again. A provider timeout or invalid response is reported by wait(). Independent requests may finish in a different order. The client timeout applies to each HTTP request once a worker starts it. The Ollama capability check and proposal request have separate timeouts. Queue time is additional.

Task handles belong to the interpreter process. Dropping a handle lets the work continue. Normal interpreter exit drains accepted work and can therefore wait for a provider timeout. Use run.cancel() on a durable run to stop further dispatch. A computation already in progress can still record its receipt. After an interrupted process, reopen the journal with agent.open_run(path), inspect its state and use the documented recovery procedure for an unsettled dispatch. A provider proposal that existed only in memory must be requested again. Journal recovery and reconciliation

The durable run workflow requires macOS or Linux and a private local journal directory. The asynchronous proposal APIs use the same local endpoints and input limits as their synchronous counterparts.

See the Scientific agents in Aner module reference for the shared API.

Aner documentation · Reference and guides