JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 27
  • Score
    100M100P100Q85560F
  • License MIT

TypeScript SDK for creating TryAgent escalations.

Package Exports

  • @tryagent/sdk

Readme

@tryagent/sdk

TypeScript SDK for creating TryAgent escalations from AI agents and workflows.

Use TryAgent when an agent reaches a decision it should not make alone. Your code sends the decision point, evidence, choices, and resume target. TryAgent routes the escalation to the right reviewers, records the decision or timeout path, and calls your workflow back when it can continue.

Full documentation: https://tryagentai.mintlify.app/quickstart

Install

pnpm add @tryagent/sdk
npm install @tryagent/sdk

Prerequisites

Before calling the SDK, create these in TryAgent:

  • A workspace API key, available to your runtime as TRYAGENT_API_KEY.
  • An escalation policy key, such as orders.auth_doc.
  • A resume webhook endpoint if your workflow should continue after the reviewer decides.

Create a client

import { TryAgent } from "@tryagent/sdk";

const tryagent = new TryAgent({
  apiKey: process.env.TRYAGENT_API_KEY!,
});

The SDK defaults to https://api.tryagent.ai. Pass baseUrl only for local development or tests.

const tryagent = new TryAgent({
  apiKey: process.env.TRYAGENT_API_KEY!,
  baseUrl: "http://localhost:4000",
});

Send an escalation

const escalation = await tryagent.escalate("orders.auth_doc", {
  agentId: "order-agent",
  runId: "run_4821",
  subject: {
    type: "order",
    id: "ord_4821",
    label: "Order #4821",
  },
  question: "The authorization document is missing a signature date. Continue?",
  evidence: [
    "Candidate name is present.",
    "Employer is present.",
    "Signature date is blank.",
  ],
  choices: [
    { id: "manual_review", label: "Send to manual review" },
    { id: "continue", label: "Continue anyway" },
  ],
  responseFields: [
    {
      type: "number",
      name: "approvedLimit",
      label: "Approved limit",
      min: 0,
      step: 0.01,
    },
    {
      type: "select",
      name: "riskLevel",
      label: "Risk level",
      options: [
        { value: "low", label: "Low" },
        { value: "high", label: "High" },
      ],
    },
  ],
  resume: {
    mode: "webhook",
    url: "https://api.example.com/tryagent/resume",
    secret: process.env.TRYAGENT_WEBHOOK_SECRET!,
  },
});

console.log(escalation.id, escalation.status);

escalate returns as soon as TryAgent creates the escalation. It does not wait for a human reviewer. Store the returned escalation ID if you want to correlate logs or audit records.

Resume your workflow

When a reviewer decides, or the policy timeout path applies, TryAgent sends a POST request to resume.url. Use the event's runId to load and continue the paused workflow. If you configured responseFields, the callback includes the validated structured values as response.

When resume.secret is set, TryAgent signs the exact JSON body with HMAC-SHA256 and includes:

  • x-tryagent-event: escalation.decided
  • x-tryagent-delivery: resume:<escalation id>
  • x-tryagent-signature: v1=<hex hmac>

Verify the signature before applying the decision. See the quickstart for the full callback handler:

https://tryagentai.mintlify.app/quickstart

Handle errors

Non-2xx API responses and network failures throw ApiError.

import { ApiError } from "@tryagent/sdk";

try {
  await tryagent.escalate("orders.auth_doc", input);
} catch (error) {
  if (error instanceof ApiError) {
    console.error(error.status, error.requestId, error.body);
    throw error;
  }

  throw error;
}