Practical tutorials

Add L3 oversight

Compare ordinary SJS requests with and without a deterministic per-request quantity guard.

Prerequisites

Start with a working SJS historical baseline, one instrument, and fixed input/settings. Keep the main algorithm in SJS. This advanced layer uses no model provider or credentials.

Add the complete L3 source

Paste into the separate L3 editor:

export const config = { enabled: true };

export async function app({ context, bar }) {
  const state = (context.l3State ??= {}).requestGuard ??= {};
  const timestamp = bar?.date == null ? NaN : new Date(bar.date).getTime();
  state.lastMarketTime = Number.isFinite(timestamp) ? timestamp : null;
}

export async function intent({ context, intent, log }) {
  const state = (context.l3State ??= {}).requestGuard ??= {};
  const checked = ["place_order", "modify_order"].includes(intent?.kind);
  const quantity = intent?.options?.order?.quantity;
  const allowed = !checked || (
    typeof quantity === "number" && Number.isFinite(quantity)
    && quantity > 0 && quantity <= 2
  );
  state.lastCheck = {
    kind: intent?.kind ?? null,
    quantity: quantity ?? null,
    allowed,
  };
  log?.("l3-request-guard", state.lastCheck);
  return allowed;
}

Compare the boundary

Run the same SJS strategy with quantity one, then quantity three. The guard allows ordinary place/modify quantities up to two and returns literal false above that limit. Inspect l3-request-guard, requestGuard.lastCheck, and the SJS request outcome.

Expected result: unchanged signal evidence, but the quantity-three request is blocked by this gate. Other execution checks can still reject the allowed quantity-one case; permission is not acceptance or fill.

Check close behavior too

The explicit close kind is allowed by this hook. The shared simulated close can then delegate to placement, which receives the quantity check again. Closing a position larger than two can therefore be blocked at that second check.

This is a per-request limit, not a total exposure cap. Multiple allowed requests can accumulate more exposure. Manual requests can override the ordinary L3 result, and L3-source requests bypass this intent hook.

Keep the layers separate

L3 frames run before SJS, and its intent hook is called on eligible requests. A frame observation alone is not an execution gate. Keep request provenance as SJS and do not move the main strategy merely to access policies.

For reusable policy modules, continue with your first policy. For an observational model call, the retained AI review tutorial explains its separate credentials and runtime limitations.

Next: investigate an unexpected trade.

On this page