---
title: "Replay a saved model decision in C# without an API key"
url: https://recursiveai.org/onellm/cookbook/replay-recorded-decision-offline/
description: "Replay the saved inputs of a OneLLM decision in C# with a scripted provider. Run it locally, then check that the new run links back to the original."
version: "1.0.1"
---

# Replay a saved model decision in C# without an API key

**OneLLM** is a free, open-source LLM and agent library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneLlm) · [GitHub](https://github.com/recursive-ai-oss/onellm-csharp) · [Docs](https://recursiveai.org/onellm/docs/) · [Download example (.zip)](https://recursiveai.org/onellm/cookbook/replay-recorded-decision-offline/replay-recorded-decision-offline.zip)

Use `ReplayDecisionAsync` with a scripted provider to rerun saved inputs without calling a model.

A decider defines the questions to ask about an input; `type: noul` asks a yes/no question and returns the probability of yes.

```shell
dotnet add package RecursiveAI.OneLlm
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using System.Text.Json;
using OneLlm;
using OneLlm.Catalog;
using OneLlm.Deciders;
using OneLlm.Providers;
using OneLlm.Testing;

var (runtime, _) = Offline();
var decider = Decider.FromYaml("""
    model: local-decision
    state: "{{ .inputs.message }}"
    questions:
      refund:
        type: noul
        instructions: Does this ask for a refund?
    """, "refund-check");
using var input = JsonDocument.Parse("""
    {"message":"Please refund my order."}
    """);
var saved = await runtime.DecideAsync(
    decider, input.RootElement);
var id = saved.Instance.InstanceId;
var replay = await runtime.ReplayDecisionAsync(id, decider);
Console.WriteLine("New run: " +
    (replay.Instance.InstanceId != id));

static (Runtime, ScriptedDecisionProvider) Offline()
{
    var catalog = """
        providers:
          - name: offline
            modelPatterns: [local-decision]
            capabilities: { decisions: true }
            models:
              - name: local-decision
                kind: decision
        """;
    var provider = new ScriptedDecisionProvider("offline");
    var runtime = new Runtime
    {
        Catalog = ModelCatalog.Create([
            CatalogLayer.FromYaml("local", catalog)]),
        Providers = new ProviderRegistry(_ => null)
    };
    runtime.Providers.Set("offline", provider);
    return (runtime, provider);
}
```

Unzip [the example](https://recursiveai.org/onellm/cookbook/replay-recorded-decision-offline/replay-recorded-decision-offline.zip), then `dotnet run`.

```text
New run: True
```

## The full program

```csharp
using System.Text;
using System.Text.Json;
using OneLlm;
using OneLlm.Catalog;
using OneLlm.Deciders;
using OneLlm.Providers;
using OneLlm.Testing;

var (runtime, provider) = Offline();
var decider = Decider.FromYaml("""
    model: local-decision
    state: "{{ .inputs.message }}"
    questions:
      refund:
        type: noul
        instructions: Does this ask for a refund?
    """, "refund-check");
using var input = JsonDocument.Parse("""
    {"message":"Please refund my order."}
    """);
var saved = await runtime.DecideAsync(
    decider, input.RootElement);
var id = saved.Instance.InstanceId;
var replay = await runtime.ReplayDecisionAsync(id, decider);
var run = await runtime.GetDecisionAsync(
    replay.Instance.InstanceId);
Console.WriteLine("Replayed state: " +
    Encoding.UTF8.GetString(provider.Requests[1].State.Span));
Console.WriteLine("New run: " +
    (replay.Instance.InstanceId != id));
Console.WriteLine($"Linked to original: {run?.ReplayOf == id}");

static (Runtime, ScriptedDecisionProvider) Offline()
{
    var catalog = """
        providers:
          - name: offline
            modelPatterns: [local-decision]
            capabilities: { decisions: true }
            models:
              - name: local-decision
                kind: decision
        """;
    var provider = new ScriptedDecisionProvider("offline");
    var runtime = new Runtime
    {
        Catalog = ModelCatalog.Create([
            CatalogLayer.FromYaml("local", catalog)]),
        Providers = new ProviderRegistry(_ => null)
    };
    runtime.Providers.Set("offline", provider);
    return (runtime, provider);
}
```

```text
Replayed state: "Please refund my order."
New run: True
Linked to original: True
```

By default, `new ScriptedDecisionProvider("offline")` returns `0.5` for this yes/no question; that’s a canned answer, not a model prediction. The lines above show that the original message reached it again and that the new run points back to the saved one. The example uses an in-memory store, so both records last only as long as that store does; it doesn’t read a file or use credentials.

If the ID isn’t in the runtime’s store or names an instance that isn’t a decision run, `ReplayDecisionAsync` throws `KeyNotFoundException`.

## Variations

**Name the model explicitly.** Replace the replay call with this to select `local-decision` from the example’s catalog instead of taking the model name from the decider:

```csharp
var replay = await runtime.ReplayDecisionAsync(id,
    decider, model: "local-decision");
```

```text
New run: True
```

## Related recipes

- [Unit test LLM calls without an API key](https://recursiveai.org/onellm/cookbook/test-llm-code-without-api-key/)
- [Save and resume a chat in C#](https://recursiveai.org/onellm/cookbook/save-and-resume-a-chat/)

## The short answer

Call `runtime.ReplayDecisionAsync(id, decider)` with the ID of a decision run in the runtime’s store. The runtime loads the saved inputs and runs the supplied decider again. For offline replay, register a `ScriptedDecisionProvider` under the provider name in the catalog. The sample uses a registry with no fallback provider, so it can’t silently switch to a live endpoint.

## How do you replay an LLM decision without calling the real API?

In OneLLM, a [decider](https://recursiveai.org/onellm/docs/deciders/) tells the runtime what state to pass and what questions to ask. This example renders a single customer message into the state and asks whether the message requests a refund. The local catalog maps the model name to `offline`, and the script supplies the answer without doing any inference. The saved record is real: `DecideAsync` creates it and `ReplayDecisionAsync` loads it by ID.

For a regression check, compare the state and questions the provider received at replay with the ones you intended to send. That catches changes in how you prepare the decision request. It doesn’t tell you how a live model would classify that text. Use a scripted answer to exercise your handling of an outcome, not to measure model quality.

## Does replay return the original model response?

No. Replay runs the current definition with the stored inputs; it doesn’t return a cached answer. Give it the same decider definition to rerun that version’s logic. Give it an edited definition to see how that logic handles the same inputs. In either case the replay has its own instance ID. Its `ReplayOf` field identifies the source run, so you can keep the original and the rerun separate.

If all you need is a record of the original run, look it up by its original ID instead of starting a replay. If you want to replay after the process has restarted, configure the runtime with the [store that contains the original record](https://recursiveai.org/onellm/docs/stores/). A fresh in-memory store has no original IDs to load.
