Skip to content

Framework objects

A framework object, such as a loaded model, an agent graph, a database client or a DataFrame, lives in the cell of the block that created it. It exists in that cell's memory, on that cell's library version, and only that cell's code can call it. Other blocks reach it through the block's interface.

Two ways to expose one

Return what it produces. Most methods use a framework object internally and return a typed value built from it, as the Any Python library example does with a DataFrame.

Hold it as a resource. When callers need the same live object across several calls, such as a model loaded once and queried many times, the interface declares it as a resource. The caller receives a handle, and every call through the handle runs in the owner cell, against the object that is already there.

For example, a block that loads a model once and serves predictions from it:

sequenceDiagram
  participant C as Caller cell
  participant K as Kernel
  participant O as Owner cell: model block
  C->>K: open_model
  K->>O: open_model
  O-->>K: resource created, model loaded in memory
  K-->>C: handle
  C->>K: predict(handle, features)
  K->>O: predict on the loaded model
  O-->>K: typed result
  K-->>C: typed result

The resource's declaration states whether the caller owns it or borrows it for one call, and whether calls on it run one at a time or in parallel. See Records, variants, resources, and streams.

What a handle carries

A handle is local to the caller and carries the rights the kernel granted: which methods it may call, a generation, and a lease. The kernel can revoke it, and it becomes stale when the owner cell ends. A stale handle is refused, and the caller opens the resource again.

Why the object stays in its cell

A framework object is bound to the memory, library version and native state of the process that built it. Keeping it in its cell means:

  1. each block runs on the library version it declared, whatever the caller uses;
  2. a crash or leak in the framework is contained to the owner cell;
  3. every use of the object passes through the interface, where it is validated, authorised and recorded.

A native object returned from a method, or emitted as a Run response, is refused at the owner cell's monitor. Convert it to a declared form first. See Block boundary.