← Dashboard

How the agent works

This page explains the orchestration loop and shows the real request/response shapes the agent works with for each downstream system. The mocks under src/lib/integrations/ emit the same shapes so the agent code is unchanged when real credentials land — flip the env vars and the same logic runs against production endpoints.

The orchestration loop

The agent is a LangGraph state machine with four nodes. Every turn flows through the same loop until it either finishes the chain or hands off to a human.

  1. 1

    plan / decide

    The LLM looks at the hire's record, what it's already done, and the dependency rules in the system prompt. It picks exactly one tool to call next — or it declares the work complete.

  2. 2

    act

    The execute node validates the tool arguments through Zod, persists a `step` row to Convex, then calls the integration. Mock or real — the agent's code path is identical.

  3. 3

    observe

    On success, the agent inspects the response. If the response is a known business-rule escalation (Checkr 'consider', Shippo invalid address, DocuSign declined), the agent stops calling the LLM and routes straight to escalate — it doesn't trust the LLM to remember the rule.

  4. 4

    retry / escalate / finish

    Transient errors (5xx, rate limits) bump a per-tool retry counter and the LLM is shown the failure so it can choose to retry. Hard failures, business escalations, and stalls all route to escalate, which writes an exception row + flips the hire to awaiting_human. Only a clean run reaches finish.

The tools the agent calls

Each integration below is currently mocked. The auth/endpoint/payload notes describe what the agent will do once we plug in credentials — the commented-out real-API blocks in src/lib/integrations/*.ts already contain the fetch calls, so flipping each one on is mostly removing comment markers.

DocuSign eSignature v2.1

https://demo.docusign.net (demo) or https://<base_uri> from /oauth/userinfo (prod)

Sends the offer letter for e-signature and tracks completion.

Auth
JWT Grant (RS256). Build a JWT signed with your RSA private key, exchange it at /oauth/token for a 1-hour access_token, then send Authorization: Bearer <token> on every call. Cache the token until ~5 minutes before it expires.
Rate limits + retry
3,000 calls/hour/account; burst 500/30s. Retry on 429, 500, 502, 503, 504 with exponential backoff. Do NOT retry 400, 401, 403, 404.
Webhooks
DocuSign Connect — attach an `eventNotification` block to the envelope when creating it. Subscribe to envelope-completed, envelope-declined, envelope-voided. Strongly preferred over polling in production.

Calls the agent makes

  1. Send the offer letter

    POST /restapi/v2.1/accounts/{accountId}/envelopes

    Request

    {
      "emailSubject": "Please sign your offer letter",
      "documents": [{
        "documentBase64": "JVBERi0xLjQK...",
        "name": "OfferLetter.pdf",
        "fileExtension": "pdf",
        "documentId": "1"
      }],
      "recipients": {
        "signers": [{
          "email": "jane.doe@example.com",
          "name": "Jane Doe",
          "recipientId": "1",
          "tabs": {
            "signHereTabs": [{
              "anchorString": "/sig1/",
              "anchorUnits": "pixels"
            }]
          }
        }]
      },
      "status": "sent"
    }

    Response

    {
      "envelopeId": "44c846ef-9d10-4c2d-b9e8-...",
      "status": "sent",
      "statusDateTime": "2026-04-18T14:03:11Z"
    }

    How the agent uses it: Agent persists the envelopeId so it can poll status. The 'sent' status means DocuSign emailed the candidate — no further action until polling shows progress.

  2. Poll envelope status

    GET /restapi/v2.1/accounts/{accountId}/envelopes/{envelopeId}

    Request

    (no body)

    Response

    {
      "envelopeId": "44c846ef-...",
      "status": "completed",
      "sentDateTime": "2026-04-18T14:03:11Z",
      "completedDateTime": "2026-04-18T14:21:02Z"
    }

    How the agent uses it: Agent reads `status`. "sent" or "delivered" → poll again. "completed" → candidate signed; advance to background check. "declined" or "voided" → escalate to a human (hard stop).

Checkr

https://api.checkr.com/v1 (prod) or https://api.checkr-staging.com/v1 (staging)

Background check + license verification for healthcare hires.

Auth
HTTP Basic with the secret key as username and an empty password: `Authorization: Basic base64(SECRET_KEY + ":")`. Test keys hit staging, live keys hit prod.
Rate limits + retry
1,200 req/min. Headers: X-Ratelimit-Remaining, X-Ratelimit-Reset (epoch). Retry on 429, 500, 502, 503, 504 with backoff. Send Idempotency-Key on POSTs so retries are safe.
Webhooks
Checkr Webhooks — events include report.completed, report.suspended, report.disputed. Verify with HMAC-SHA256 on X-Checkr-Signature. Strongly preferred — reports can take hours to days.

Calls the agent makes

  1. Create candidate (PII)

    POST /v1/candidates

    Request

    {
      "first_name": "Jane",
      "last_name": "Doe",
      "email": "jane.doe@example.com",
      "dob": "1990-05-14",
      "ssn": "111-11-2001",
      "zipcode": "94110",
      "no_middle_name": true
    }

    Response

    {
      "id": "551564b7865af96a28b13f36",
      "object": "candidate",
      "first_name": "Jane",
      "ssn": "XXX-XX-2001",
      "created_at": "2026-04-18T14:08:18Z"
    }

    How the agent uses it: Agent stores `id` (the candidate id). SSN comes back redacted in the response — Checkr handles the sensitive value. Required before ordering a report.

  2. Order background report

    POST /v1/reports

    Request

    {
      "candidate_id": "551564b7865af96a28b13f36",
      "package": "tasker_standard"
    }

    Response

    {
      "id": "a13f4827d8711ddc75abc56c",
      "status": "pending",
      "result": null,
      "package": "tasker_standard",
      "candidate_id": "551564b7865af96a28b13f36"
    }

    How the agent uses it: Agent stores `id` (the report id) and starts polling. `status: pending` means Checkr is still running checks.

  3. Poll report result

    GET /v1/reports/{report_id}

    Request

    (no body)

    Response

    {
      "id": "a13f4827d8711ddc75abc56c",
      "status": "complete",
      "result": "consider",
      "adjudication": null,
      "completed_at": "2026-04-19T10:03:00Z"
    }

    How the agent uses it: Agent reads `status` + `result`. "pending" → poll again. "complete" + "clear" → safe to proceed to payroll. "complete" + "consider" → adverse findings; FCRA requires human adjudication, agent escalates. "suspended" → Checkr needs more docs from the candidate; escalate.

Gusto Embedded Payroll

https://api.gusto.com (prod) or https://api.gusto-demo.com (demo)

Adds the new hire to payroll and (via partner) ICHRA benefits.

Auth
OAuth 2.0 Authorization Code grant. Exchange auth code at /oauth/token for an access_token (2h lifetime) and refresh_token (rotates on every refresh — always persist the new one). Header: Authorization: Bearer <token>, X-Gusto-API-Version: 2024-04-01.
Rate limits + retry
200 req/min per (application, company) pair, rolling 60s. On 429, respect Retry-After. Backoff: 1s, 2s, 4s, 8s capped.
Webhooks
Gusto webhook subscriptions cover events like employee.created and benefit.updated. Useful for keeping HRIS in sync; not strictly needed for agent-driven onboarding since the agent owns the timing.

Calls the agent makes

  1. Create employee

    POST /v1/companies/{company_uuid}/employees

    Request

    {
      "first_name": "Alexander",
      "middle_initial": "A",
      "last_name": "Hamilton",
      "date_of_birth": "1979-06-01",
      "email": "a.h@example.com",
      "ssn": "123451776",
      "self_onboarding": true
    }

    Response

    {
      "uuid": "8e63aa05-7d0e-4663-b9dc-...",
      "version": "414645000000abc",
      "first_name": "Alexander",
      "onboarded": false
    }

    How the agent uses it: Agent stores `uuid` (employee id) and `version` (used for optimistic locking on subsequent PUTs). `self_onboarding: true` lets the employee fill remaining PII via Gusto-hosted UI; otherwise the agent has to POST home_addresses + jobs + compensations next.

  2. Enroll in ICHRA benefit

    POST /v1/employees/{employee_uuid}/employee_benefits

    Request

    {
      "company_benefit_uuid": "f68abb42-431e-4392-bc3f-...",
      "active": true,
      "employee_deduction": "0.00",
      "contribution": { "type": "amount", "value": "400.00" }
    }

    Response

    {
      "uuid": "11e30d62-8b3f-4c0a-8442-...",
      "active": true,
      "company_benefit_uuid": "f68abb42-..."
    }

    How the agent uses it: Agent triggers payroll-side reimbursement enrollment. NOTE: Gusto does not natively administer ICHRA — it must be paired with a partner like Thatch or Take Command Health that handles the actual benefit. The agent's TODO is to also call the partner's API after this.

Shippo

https://api.goshippo.com

Verifies the home address and buys the laptop shipping label.

Auth
Single API token. Header: `Authorization: ShippoToken shippo_live_xxx` (or `shippo_test_xxx`). The token prefix picks live vs sandbox — no separate hostname.
Rate limits + retry
Live: 500 POST/min, 4,000 GET-single/min, 50 GET-list/min. 429 on overrun; no documented Retry-After header — back off and retry.
Webhooks
Tracking webhooks notify on shipment status changes (in transit, delivered, exception). Useful for keeping the dashboard live without polling Shippo.

Calls the agent makes

  1. Validate address

    POST /addresses/

    Request

    {
      "name": "Jane Nurse",
      "street1": "215 Clayton St.",
      "city": "San Francisco",
      "state": "CA",
      "zip": "94117",
      "country": "US",
      "validate": true
    }

    Response

    {
      "object_id": "67183b2e81e9421f894bfbcdc4236b16",
      "is_complete": true,
      "validation_results": { "is_valid": true, "messages": [] },
      "street1": "215 CLAYTON ST",
      "city": "SAN FRANCISCO",
      "state": "CA",
      "zip": "94117-1923"
    }

    How the agent uses it: Agent reads `validation_results.is_valid`. true → safe to buy a label, and the response's normalized address is what gets used downstream. false → escalate with `validation_results.messages` so a human can correct the address before we waste a label.

  2. Buy label (instalabel — combined call)

    POST /transactions/

    Request

    {
      "shipment": {
        "address_from": { "name": "Acme HR", "street1": "1 Market St", "city": "San Francisco", "state": "CA", "zip": "94105", "country": "US" },
        "address_to":   { "name": "Jane Nurse", "street1": "215 Clayton St.", "city": "San Francisco", "state": "CA", "zip": "94117", "country": "US" },
        "parcels": [{ "length": "15", "width": "12", "height": "3", "distance_unit": "in", "weight": "8", "mass_unit": "lb" }]
      },
      "carrier_account": "b741b99f95e841639b54272834bc478c",
      "servicelevel_token": "usps_priority",
      "label_file_type": "PDF",
      "async": false
    }

    Response

    {
      "object_id": "9a1b...",
      "status": "SUCCESS",
      "tracking_number": "9405511899563312345671",
      "tracking_url_provider": "https://tools.usps.com/...",
      "label_url": "https://shippo-delivery.s3.amazonaws.com/.../label.pdf"
    }

    How the agent uses it: Agent reads `status` ("SUCCESS" → keep the `tracking_number` and `label_url`) and persists both for the operator dashboard. "ERROR" status with carrier-rejected messages → escalate (we won't auto-retry a label the carrier said no to).

Kandji

https://<subdomain>.api.kandji.io (US) or https://<subdomain>.api.eu.kandji.io (EU). All paths prefixed /api/v1.

Pre-provisions the laptop's MDM enrollment so it auto-configures on first boot.

Auth
API token (Bearer). `Authorization: Bearer <KANDJI_API_TOKEN>`. Tokens are tenant-scoped with fine-grained per-endpoint permissions.
Rate limits + retry
10,000 req/hour per tenant (~166/min). 429 on overrun; no documented Retry-After — exponential backoff.
Webhooks
Kandji webhooks fire on device enrollment + check-in events. Recommended over polling once you're past the demo phase.

Calls the agent makes

  1. Find the device by candidate email

    GET /api/v1/devices?user.email=jane@example.com&limit=1

    Request

    (query param only)

    Response

    [{
      "device_id": "ab102b9d-8e9c-420d-a498-...",
      "serial_number": "C02XYZ123ABC",
      "user": { "email": "jane@example.com", "id": "9564" },
      "blueprint_id": null
    }]

    How the agent uses it: Agent looks up the device that the warehouse already registered in Apple Business Manager (ABM) for this candidate. If no device comes back, the ABM sync hasn't landed yet → retryable error (try again in a minute).

  2. Assign blueprint (pre-provision)

    PATCH /api/v1/devices/{device_id}

    Request

    {
      "blueprint_id": "ab102b9d-8e9c-420d-a498-f2a1123091c7",
      "asset_tag": "NURSE-042",
      "user": "9564"
    }

    Response

    {
      "device_id": "ab102b9d-...",
      "blueprint_id": "ab102b9d-...",
      "asset_tag": "NURSE-042"
    }

    How the agent uses it: Agent ties the nurse's clinical blueprint (apps, restrictions, profiles) to their device. When the nurse boots the laptop and signs into iCloud, Kandji auto-configures everything via DEP — no IT involvement needed.

  3. Poll enrollment status

    GET /api/v1/devices/{device_id}/details

    Request

    (no body)

    Response

    {
      "device_id": "ab102b9d-...",
      "mdm_enrollment": { "status": "Enrolled", "enrolled_at": "2026-04-22T15:31:08Z" },
      "last_check_in": "2026-04-22T15:32:11Z",
      "serial_number": "C02XYZ123ABC"
    }

    How the agent uses it: Agent reads `mdm_enrollment.status`. "Enrolled" → onboarding fully complete. Anything else → keep polling (the nurse hasn't unboxed the laptop yet).

Where this lives in code

  • src/lib/agent/graph.ts — the LangGraph state machine (decide / execute / escalate / finish nodes + routing rules).
  • src/lib/agent/narrator.ts — turns each agent event into the chat-style narration you see on the hire detail page.
  • src/lib/integrations/*.ts — one file per external system. Each contains the mock used today and the (commented-out) real-API code for when credentials arrive.
  • convex/schema.ts — the persistent data model: hires, steps, exceptions, audit_log, agent_thoughts.