Schedules, webhooks and callbacks

Schedules, webhooks and callbacks

An agent doesn't have to wait for a caller. A schedule runs it on a timer, a webhook runs it when another service calls a URL, and a callback sends the result of a run to your server when it finishes.

Schedules

Add one on the agent's Schedules tab, or:

lgr triggers create morning --agent support-bot \
  --schedule "0 8 * * 1-5" --message "Triage the tickets that came in overnight"

The Agents list shows enabled / total Agent schedules and the next run time. These counts include only schedules that directly run that agent; webhooks are counted separately. Use the row's Manage schedules menu to open them, or View instances to manage associated compute resources and their own triggers. Next-run times show your browser's local time zone. Unavailable means the schedule list could not be loaded, not that no schedules exist.

The enabled count describes saved trigger settings. If the agent's lifecycle is Paused, execution is blocked even when a trigger is enabled; the console labels its time Schedule time (blocked). You can still save trigger settings, but Run now and webhook execution remain blocked. Triggers of a Removed agent only allow pausing and deletion for cleanup.

Use Pause agent in the agent's actions menu to block all its new execution. This keeps each trigger's enabled setting. Resume agent moves still-enabled schedules, including those on resources currently bound to the agent, to their next future time without replaying missed ticks. It does not enable disabled triggers. If a disabled trigger was waiting for an OAuth reconnection, pausing the agent cancels that automatic re-enable; explicitly enable the trigger when you want it to run again.

Remove agent turns off triggers directly targeting that agent and clears their automatic OAuth re-enable. Restore agent returns to Paused and leaves those triggers off, including after a later Resume. Resource triggers are separate: unbinding or handing over an instance or fleet keeps its plans, so review and disable any you no longer want before changing that binding.

The Schedules tab of an agent with a weekday schedule and a webhook

In the console, pick how often it repeats and the time, in your own time zone. From the CLI or API a schedule is a five-field cron expression, read in UTC unless it starts with a time zone: TZ=America/New_York 0 9 * * 1-5 is 09:00 in New York on weekdays, and keeps to 09:00 when daylight saving starts or ends. Each time one fires, the agent's live version gets a new run in a fresh sandbox with the message, billed like any other run. A schedule missed while the platform was down fires once when it comes back.

Pausing the agent's API doesn't stop its schedules. Pause a schedule on its own on the Schedules tab, or lgr triggers disable morning (enable turns it back on). lgr triggers fire morning runs it now.

An MCP authorization failure can temporarily pause schedules until you reconnect. Those schedules say Automatically resumes after reconnect. Choose Keep paused to leave one off even after reconnecting; you can explicitly Resume it later. Pausing or deleting a trigger does not cancel a run it already started or stop an instance or fleet.

Webhooks

A webhook is a URL that starts a run when anything POSTs to it, such as a GitHub, Stripe or monitoring alert:

lgr triggers create alerts --agent oncall --webhook --message "New alert: {{body}}"

The URL is shown once, when the webhook is created. The token in it is the credential, so treat it like a key. {{body}} in the message is replaced with the request body, pretty-printed when it is JSON; without a message, the body is the message. Bodies of any content type up to 256 KB are accepted, and the answer is 202 with the run_id. A deleted or paused webhook answers 404.

To try one without the other service, send a sample body:

lgr triggers fire alerts --body '{"service":"checkout","error_rate":0.07}'

Callbacks

Give a run, message or trigger a callback URL and its result is POSTed there when the run finishes:

lgr triggers callback morning https://example.com/hooks/lagrange
lgr run --agent support-bot --callback https://example.com/hooks/lagrange "Summarise the open tickets"

The request looks like this:

POST /hooks/lagrange HTTP/1.1
content-type: application/json
user-agent: LagrangeCloud-Callbacks/1.0
lgr-delivery: dlv_3c9e01b2f7aa
lgr-event: run.completed
lgr-signature: t=1791403200,v1=5f1d…

{"id": "dlv_3c9e01b2f7aa", "type": "run.completed", "created_at": "2026-10-07T20:00:00.000Z", "run": { "id": "run_…", "status": "succeeded", "result": "…", "usage": { … }, "console_url": "…" }}

type is run.completed, run.failed or run.cancelled. Answer with any 2xx. Anything else, a redirect, or no answer within 10 seconds counts as a failure, and the same delivery is sent again after 30 seconds, 2 minutes, 10 minutes and 1 hour. Use lgr-delivery to drop duplicates.

Verifying the signature

lgr-signature is t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">, keyed with your project's signing secret (Settings → Callbacks, or lgr callbacks secret). Recompute it over the raw body, compare in constant time, and reject timestamps more than five minutes old:

Node.js

Save as callback.mjs:

import { createHmac, timingSafeEqual } from "node:crypto";

// body must be the raw request bytes, before parsing JSON.
export function verify(secret, header, body) {
  const match = /^t=([0-9]+),v1=([0-9a-fA-F]{64})$/.exec((header ?? "").trim());
  if (!match) return false;
  const [, timestamp, signature] = match;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
  const expected = createHmac("sha256", secret).update(timestamp + ".").update(body).digest();
  return timingSafeEqual(Buffer.from(signature, "hex"), expected);
}

Python

Save as callback.py:

import hashlib
import hmac
import re
import time


# body must be the raw request bytes, before parsing JSON.
def verify(secret, header, body):
    match = re.fullmatch(r"t=([0-9]+),v1=([0-9a-fA-F]{64})", (header or "").strip())
    if not match:
        return False
    timestamp, signature = match.groups()
    if abs(time.time() - float(timestamp)) > 300:
        return False
    expected = hmac.new(
        secret.encode("utf-8"), timestamp.encode("ascii") + b"." + body, hashlib.sha256
    ).digest()
    return hmac.compare_digest(bytes.fromhex(signature), expected)

Run a local check

These launch examples cover Node.js 22+ and Python 3.10+, using only standard libraries. Keep the original request bytes: Node.js handlers pass a Buffer; Python handlers pass bytes. Read the secret from your server environment, pass the request's lgr-signature header to verify, and reject a false result before parsing or acting on the payload. Use lgr-delivery for persistent duplicate detection in your application.

After saving either example, run the matching check from the same directory. The checks use a local sample secret, sign the same payload, and verify that altering the payload is rejected; they do not send a callback or start a run.

Node.js:

node --input-type=module <<'JS'
import assert from "node:assert/strict";
import { createHmac } from "node:crypto";
import { verify } from "./callback.mjs";
const secret = "whsec_local_example";
const body = Buffer.from('{"type":"run.completed","run":{"id":"run_example"}}');
const timestamp = Math.floor(Date.now() / 1000);
const signature = createHmac("sha256", secret).update(timestamp + ".").update(body).digest("hex");
const header = `t=${timestamp},v1=${signature}`;
assert(verify(secret, header, body));
assert(!verify(secret, header, Buffer.from("{}")));
console.log("Callback verification passed");
JS

Python:

python3 <<'PY'
import hashlib
import hmac
import time
from callback import verify
secret = "whsec_local_example"
body = b'{"type":"run.completed","run":{"id":"run_example"}}'
timestamp = str(int(time.time()))
signature = hmac.new(secret.encode(), timestamp.encode() + b"." + body, hashlib.sha256).hexdigest()
header = f"t={timestamp},v1={signature}"
assert verify(secret, header, body)
assert not verify(secret, header, b"{}")
print("Callback verification passed")
PY

Callback URLs must be http or https and must not point at private, loopback or link-local addresses. Recent deliveries are under Settings → Callbacks and lgr callbacks; lgr callbacks retry <id> sends one again and lgr callbacks rotate replaces the signing secret.

Instances and fleets

Triggers can also message an instance or fleet instead of starting a fresh run of an agent: use --instance NAME or --fleet NAME in place of --agent. On an instance, the message continues the conversation stored there.