AsyncNative

Documentation

Get a guarded request running in a few minutes. The SDK is available to customers with platform access; request access to receive your token.

Quickstart

Install the package and set your token as an environment variable. Never commit tokens to source control.

terminal
npm install @asyncnative/core
export ASYNCNATIVE_TOKEN="an_live_..."

Create a guard once at startup, then run each inbound request through triageAndRoute.

handler.ts
import { AsyncGuard } from '@asyncnative/core';

const guard = new AsyncGuard({
  apiKey: process.env.ASYNCNATIVE_TOKEN,
  models: { fastHeuristic: 'system1-sub-millisecond', deliberative: 'system2-reasoning' },
  enforceZeroDayInjectionShield: true
});

export async function handleInboundInference(rawPayload: string) {
  const inspection = await guard.triageAndRoute(rawPayload);
  if (inspection.hasAdversarialIntent) {
    return guard.quarantine(inspection.threatSignature);
  }
  return await guard.dispatchDeliberativeSystem2(inspection.sanitizedContext);
}

Configuration

Options passed to new AsyncGuard().

OptionTypeDescription
apiKeystringYour platform token. Read from an environment variable.
models.fastHeuristicstringSystem 1 triage model used on every request.
models.deliberativestringSystem 2 route that sanitized requests are dispatched to.
enforceZeroDayInjectionShieldbooleanEnable the injection shield. Set to false only while testing.
policystringPath to an asyncnative.policy.yaml file. Defaults to the strict baseline.

Reading a verdict

triageAndRoute resolves to an inspection object. Branch on hasAdversarialIntent, and log threatSignature and riskScore for your own audit trail.

inspection (example)
{
  hasAdversarialIntent: true,
  threatSignature: "DELIMITER_ESCAPE_AND_ROLE_SUBVERSION",
  riskScore: 0.998,
  route: "quarantine",
  latencyMs: 3.12,
  sanitizedContext: null
}

Shadow mode

Set mode: shadow in your policy to record verdicts without blocking anything. Run it against production traffic first, review what would have been quarantined, then switch to enforce.

Agent guardrails

Wrap each agent session so tool calls are checked against policy. When a limit such as tool depth or session spend is exceeded, the breaker trips and further calls are refused.

agent.ts
const session = guard.session({ agent: 'support-bot' });

const call = await session.authorizeTool('crm.lookup', args);
if (!call.allowed) return session.halt(call.reason);

Errors and limits

Handle failures explicitly. Decide per route whether to fail closed (reject the request) or fail open (continue unguarded) if the guard cannot be reached. We recommend fail closed for anything touching sensitive data.

CodeMeaningWhat to do
401Invalid or revoked tokenRotate the token and redeploy
429Rate limit reached for your planBack off and retry, or contact us to raise limits
503Guard temporarily unavailableApply your fail-closed or fail-open rule