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.
npm install @asyncnative/core export ASYNCNATIVE_TOKEN="an_live_..."
Create a guard once at startup, then run each inbound request through triageAndRoute.
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().
| Option | Type | Description |
|---|---|---|
| apiKey | string | Your platform token. Read from an environment variable. |
| models.fastHeuristic | string | System 1 triage model used on every request. |
| models.deliberative | string | System 2 route that sanitized requests are dispatched to. |
| enforceZeroDayInjectionShield | boolean | Enable the injection shield. Set to false only while testing. |
| policy | string | Path 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.
{
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.
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.
| Code | Meaning | What to do |
|---|---|---|
| 401 | Invalid or revoked token | Rotate the token and redeploy |
| 429 | Rate limit reached for your plan | Back off and retry, or contact us to raise limits |
| 503 | Guard temporarily unavailable | Apply your fail-closed or fail-open rule |