EngineAdvanced L3

Examples

Exercise deterministic oversight and provider response validation with complete L3 scripts.

Use the getting-started guard for a complete deterministic intent example. Use the policy quickstart to express that oversight through reusable modules.

Observe a fake-provider response

This complete L3 script uses the runtime's fake provider. It records a validated observation once per session, makes no execution request, and deliberately propagates errors to the runtime for visibility.

export const config = { enabled: true, provider: "fake" };

export async function app({ context, bar, provider, log }) {
  const state = (context.l3State ??= {}).providerObservation ??= {};
  if (state.completed || state.processing) return;
  const timestamp = bar?.date == null ? NaN : new Date(bar.date).getTime();
  if (!Number.isFinite(timestamp)) return;
  if (typeof provider?.provider?.complete !== "function") {
    throw new Error("L3 provider is unavailable");
  }
  state.processing = true;
  try {
    const response = await provider.provider.complete({
      purpose: "frame",
      input: { timestamp },
      fake: { output: { allowed: true, reason: "Deterministic observation" } },
    });
    const output = response?.output;
    if (!output || typeof output.allowed !== "boolean" || typeof output.reason !== "string") {
      throw new Error("Invalid provider observation");
    }
    state.last = { timestamp, allowed: output.allowed, reason: output.reason };
    state.completed = true;
    log?.("l3-provider-observation", state.last);
  } finally {
    state.processing = false;
  }
}

There is no intent export here, so this observer does not reject ordinary execution requests. The stored allowed field is demonstration data, not a gate automatically enforced by the engine.

The busy flag prevents overlapping calls in this script's state. The completed flag limits successful observation to one per session. A failure releases the busy flag; a later invocation can try again. This is intentionally a small fixture, not a production retry/backoff policy.

Exercise failure behavior

In a separate experiment revision, replace the fake output option with a supported fake.error string to exercise a thrown provider error. Run it historically and inspect the Lab failure. In a normal session, inspect the runtime's recorded frame error and the behavior of any subsequent intent checks.

Do not switch this historical example to a real provider and expect the fake-provider exemption to carry over.

Grow into reusable oversight

For multiple checks, keep the L3 app and intent as orchestration hooks and move focused logic into policy objects. Follow defining a policy, requirements, and intents.

Continue with debugging.

On this page