---
title: "ClikaRT::runtime::FunctionModel"
sidebar_label: "FunctionModel"
description: "A concrete Model whose phases are served by callables instead of overrides."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--class">class</span>

**Header:** `ClikaRT/runtime/function_model.h`  
**Inherits:** [`ClikaRT::runtime::Model`](./Model.md)

[`ClikaRT::runtime::FunctionModel`](./FunctionModel.md): a ready-made `Model` you build from a schema and lambdas, so a simple pipeline node needs no subclass. Declare each phase with `on_run_once` / `on_iterate`; the runtime drives the model through the base `Model` seam and `FunctionModel` dispatches the phase to your callable. The callables run caller-side and MAY raise [`ClikaRT::Error`](../Error.md), contained exactly like a hand-written `Model` override.

runtime::FunctionModel m\{schema\}; m.on\_run\_once("run", \[\](runtime::PhaseContext\& ctx) \{ ctx.outputs-\>set("y", ctx.inputs-\>get("x") \* 2.0); \}); auto pipe = runtime::Pipeline::create(\{\{"node", \&m, \{\}, in\_map, out\_map\}\}, schema);

It is header-only and caller-side: its body, and any throw from your callable, is compiled into your translation unit, never the library.

A concrete [`Model`](./Model.md) whose phases are served by callables instead of overrides.

## Member functions

### FunctionModel() {#FunctionModel}

<div class="api-signature">

**`FunctionModel`**() `=default`

</div>

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 39

</div>

### FunctionModel(ModelSchema) {#FunctionModel-2}

<div class="api-signature">

`explicit` **`FunctionModel`**([`ModelSchema`](./ModelSchema.md) `schema`)

</div>

A model carrying [`schema`](./FunctionModel.md#schema) whose phases are bound as callbacks.

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 41

</div>

### FunctionModel(FunctionModel) {#FunctionModel-3}

<div class="api-signature">

**`FunctionModel`**(`const FunctionModel&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 46

</div>

### operator=(FunctionModel) {#operator-assign}

<div class="api-signature">

[`FunctionModel`](./FunctionModel.md)`&` **`operator=`**(`const` [`FunctionModel`](./FunctionModel.md)`&`) `=delete`

</div>

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 47

</div>

### FunctionModel(FunctionModel) {#FunctionModel-4}

<div class="api-signature">

**`FunctionModel`**(`FunctionModel&&`) `=default`

</div>

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 48

</div>

### operator=(FunctionModel) {#operator-assign-2}

<div class="api-signature">

[`FunctionModel`](./FunctionModel.md)`&` **`operator=`**([`FunctionModel`](./FunctionModel.md)`&&`) `=default`

</div>

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 49

</div>

### set\_schema() {#set_schema}

<div class="api-signature">

[`FunctionModel`](./FunctionModel.md)`&` **`set_schema`**([`ModelSchema`](./ModelSchema.md) `schema`)

</div>

Set / replace the I/O contract.

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 52

</div>

### on\_run\_once() {#on_run_once}

<div class="api-signature">

[`FunctionModel`](./FunctionModel.md)`&` **`on_run_once`**(`std::string_view` `name`, `std::function<void(`[`PhaseContext`](./PhaseContext.md) `&)>` `fn`)

</div>

Add a `RunOnce` phase served by `fn` (a single pass; e.g. prefill/encode).

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 58

</div>

### on\_iterate() {#on_iterate}

<div class="api-signature">

[`FunctionModel`](./FunctionModel.md)`&` **`on_iterate`**(`std::string_view` `name`, `std::function<`[`StepBatchOut`](./StepBatchOut.md)`(`[`StepContext`](./StepContext.md) `&)>` `fn`)

</div>

Add an `Iterate` phase served by `fn` (stepped over the active batch).

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 68

</div>

### with\_state() {#with_state}

<div class="api-signature">

[`FunctionModel`](./FunctionModel.md)`&` **`with_state`**(`std::function<`[`ModelState`](./ModelState.md) `*(`[`Stream`](../Stream.md)`)>` `factory`)

</div>

Supply a per-session state factory (only for a stateful model).

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 78

</div>

### schema() {#schema}

<div class="api-signature">

`virtual` `const` [`ModelSchema`](./ModelSchema.md)`&` **`schema`**() `const override`

</div>

the schema given at construction

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 83

</div>

### phases() {#phases}

<div class="api-signature">

`virtual` [`ClikaRT::Span`](../Span.md)`<const` [`PhaseSpec`](./PhaseSpec.md)`>` **`phases`**() `const override`

</div>

the phases declared so far

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 84

</div>

### make\_state() {#make_state}

<div class="api-signature">

`virtual` [`ModelState`](./ModelState.md)`*` **`make_state`**([`Stream`](../Stream.md) `stream`) `const override`

</div>

Creates the per-session state the bound [`with_state`](./FunctionModel.md#with_state) factory produces (null factory = stateless).

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 88

</div>

### Phase\_RunOnce() {#Phase_RunOnce}

<div class="api-signature">

`virtual` `void` **`Phase_RunOnce`**(`const` [`PhaseSpec`](./PhaseSpec.md)`&` `phase`, [`PhaseContext`](./PhaseContext.md)`&` `ctx`) `override`

</div>

Dispatches the phase to its bound run-once callback.

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 93

</div>

### Phase\_Iterate() {#Phase_Iterate}

<div class="api-signature">

`virtual` [`StepBatchOut`](./StepBatchOut.md) **`Phase_Iterate`**(`const` [`PhaseSpec`](./PhaseSpec.md)`&` `phase`, [`StepContext`](./StepContext.md)`&` `ctx`) `override`

</div>

Dispatches the phase to its bound per-step callback.

<div class="api-declared">

Declared in `ClikaRT/runtime/function_model.h`, line 104

</div>
