Background work and webhooks
This guide shows how to make work happen later or without waiting for it: send an agent a message on a schedule, run a tool on an entity at a given time, manage the scheduled jobs you created, collect the results of long-running requests, have Hilus call your endpoint when a request finishes instead of polling, and retry background work that stopped after failing. Everything here lives in jobs and is scoped to your organization.
Choose a mechanism
- Something should happen at a time, once or repeatedly (a reminder, a weekly check, a follow-up): schedule a job. A job runs one tool on one entity; the most common tool is a message to an agent.
- You made a request that takes a while (a simulation, a diagnosis, a
test run): it answers
202 Acceptedwith an async id. Poll the execution, or subscribe a webhook. - Your system should react when requests finish without polling:
subscribe a webhook. It delivers signed
request.completedandrequest.failedevents to your HTTPS endpoint.
Schedule a message to an agent
Send an agent a message delivers text to an agent, which takes a turn on it as if it had arrived through a channel. With when it becomes a scheduled job:
curl -X POST "https://api.hilus.ai/Platform/jobs/invoke-agent" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "agt_123",
"message": "Check today'\''s unconfirmed appointments and send each contact a reminder.",
"when": "2026-09-15T08:00:00-07:00"
}'
Response:
{
"id": "job_777",
"scheduled": true
}
when accepts an ISO datetime or natural language, one-off ("tomorrow
9am") or recurring ("every monday 8am", "every 30 minutes"):
curl -X POST "https://api.hilus.ai/Platform/jobs/invoke-agent" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "agt_123",
"message": "Summarize last week'\''s escalations for the team.",
"when": "every monday 8am"
}'
[!WARNING] Natural language is parsed by a model, and a relative phrase can resolve to a moment in the past, in which case the job runs at once. Scripts and integrations should always pass an ISO datetime with its offset.
The agent runs with its real tools on main: a reminder it sends reaches
a real contact, and a document it edits changes on main at once, also
where main is protected. That is how a recurring job keeps data current
for other agents (open appointment days precomputed twice a day, say):
the job's agent rewrites a document it has among its integrations, and
the agents that need the data read the same document. Adding the
document to those agents is a configuration change that goes through a
changeset once; the job's later edits do not. Test-run the job before it
fires, as shown under Manage scheduled jobs below.
Several jobs from an agent. An agent that decides on several separate
pieces of work at once (a query picks 20 households to call today)
schedules them with one call of its schedule_self tool, which takes a
list of jobs, rather than one call per job. Every job of the call is
created, or none is, and they share a batch id. A job continues the
conversation it was scheduled from, as a follow-up on the same case
should; a job marked as a new conversation runs in a fresh one of its
own, with everything it needs in its message, which is right for
separate pieces of work such as one household each. The
agent can space the jobs a fixed number of seconds apart, which protects
the systems the turns call: a practice-management system can refuse more
than a few requests at once, and turns that take longer than the spacing
overlap. An agent schedules only itself this way, never another agent.
Job state. A job can carry a short note for its runs, such as a cursor
or the households already reached. Set it with
state when you schedule the job (or
when an agent schedules it). Each run of the job shows the agent its
message followed by the note, and the agent replaces the note from that
run with its update_job_state tool, so the next run starts where this
one stopped. Every version stays in the job's history.
Run a tool on an entity later
Run a tool is the general form: any tool, on
any entity in your organization, now or at a time. Sending an agent a
message is this route with the agent's invoke tool:
curl -X POST "https://api.hilus.ai/Platform/jobs/execute-tool" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"target_type": "Agent",
"target_id": "agt_123",
"tool": "Agent.invoke",
"arguments": {
"message": "Close out any conversation that has waited on the contact for more than a week."
},
"when": "every day at 18:00"
}'
Find the tools an entity type offers, and their arguments, with
list tools. Without when the tool runs
now and you get back the execution's id, not the tool's result; to run a
tool and read what it returns, use
execute tool instead.
The ChatGPT app does not offer these general tool runners, because ChatGPT lists every operation as its own tool; Claude, other MCP clients, the CLI and the API do.
Manage scheduled jobs
List pending jobs to see what will run and
when. Jobs an agent scheduled in one call carry the same batch_id.
Filter by the conversation they were scheduled from with
source_conversation_id:
curl -X GET "https://api.hilus.ai/Platform/jobs?source_conversation_id=conv_987" \
-H "Authorization: Bearer $HILUS_API_KEY"
Response:
[
{
"id": "job_777",
"next_run_at": "2026-09-15T15:00:00+00:00",
"status": "pending",
"active": true,
"description": "Morning appointment reminders",
"reference_id": null,
"source_conversation_id": "conv_987",
"batch_id": null
}
]
Test-run a job now. Simulate a job runs its stored invocation immediately without consuming an occurrence: the schedule, status and active flag stay as they were. It is always a dry run: irreversible tools (sending, charging, writing) return a mocked success while read-only tools run for real, so the agent sees true data and takes a true path.
curl -X POST "https://api.hilus.ai/Platform/jobs/simulate" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"job_id": "job_777"
}'
Response:
{
"status": "ran",
"job_id": "job_777",
"mocked": true,
"tool": "Agent.invoke",
"target": "Agent:agt_123",
"mock_applied_to_entities": 12,
"result": "conv_2468",
"conversation_id": "conv_2468",
"schedule_unchanged": true,
"next_run_at": "2026-09-15T15:00:00+00:00"
}
For an agent job, the turn runs in the background; read the conversation
named by conversation_id to see what the agent did. A failing tool is
reported as "status": "failed" with its message, not as a request error.
Run a job now. Run a job now runs it for real, as the scheduler would, and changes the schedule the way a scheduled run does: a job that runs once is used up and does not run again on its date; a recurring job runs one extra time and keeps its next occurrence; a job whose tool manages its own timing lets the tool decide. A paused job is refused until it is resumed. A long run answers with an async id to poll.
curl -X POST "https://api.hilus.ai/Platform/jobs/run-now" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"job_id": "job_777"
}'
Response:
{
"status": "ran",
"job_id": "job_777",
"tool": "Agent.invoke",
"result": "conv_2468",
"failure": null,
"job_status": "done",
"next_run_at": null
}
Pause, resume or cancel. Pausing keeps the job but skips its occurrences; the schedule keeps advancing, so resuming does not fire a backlog. Cancelling marks the job done and cannot be undone.
curl -X POST "https://api.hilus.ai/Platform/jobs/set-active" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"job_id": "job_777",
"active": false
}'
curl -X POST "https://api.hilus.ai/Platform/jobs/cancel" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"job_id": "job_777"
}'
Collect the result of a long-running request
Some routes finish in seconds; others run for minutes. A long-running
route answers 202 Accepted with an async id instead of holding the
connection, and the same id is in the X-Hilus-Async-Id response header.
The protocol (the pending body, the headers, how to force either mode) is
the same for every Hilus service and is described under Async operations
in the API reference introduction. Here you retrieve the outcome:
curl -X GET "https://api.hilus.ai/Platform/jobs/async/async_2f9c" \
-H "Authorization: Bearer $HILUS_API_KEY"
Response:
{
"async_id": "async_2f9c",
"status": "pending",
"path": "/lab/simulate",
"request_path": "/Platform/lab/simulate",
"mode": "async",
"created_at": 1789470000.0,
"poll_url": "/Platform/jobs/async/async_2f9c"
}
Keep polling, with a pause between attempts, until status is
completed or failed:
Response:
{
"async_id": "async_2f9c",
"status": "completed",
"path": "/lab/simulate",
"request_path": "/Platform/lab/simulate",
"mode": "async",
"created_at": 1789470000.0,
"result": "{\"agent_id\": \"agt_123\", \"n\": 1, \"goal_met_count\": 1}",
"latency_ms": 41250.0,
"completed_at": 1789470041.3
}
resultis the route's whole serialized response. A response too large to keep on the execution record is stored as a value:result_refis its handle, andresultis still the complete response read through it.- A
failedrecord carriesfailurewith acode(timeout,worker_shutdown,serialization_failed,handler_error,cancelled,streaming_result_not_async_capable) and a message safe to show. - A pending record past its deadline turns into
failedwithtimeout, so you never poll a dead id forever. Unknown or expired ids return 404. - Polling re-checks your current credentials against the original route: a revoked scope or membership gets 403 even if you made the request.
Get notified with webhooks
A webhook subscription delivers an event to your HTTPS endpoint whenever a
request in your organization completes or fails, synchronous or
asynchronous. Managing subscriptions requires the admin:webhooks scope.
1. Subscribe. Subscribe an endpoint with the routes you care about, as lowercase globs over route templates, and optionally a match predicate on the result:
curl -X POST "https://api.hilus.ai/Platform/jobs/webhooks" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://hooks.example.com/hilus",
"paths": [
"/lab/*"
],
"events": [
"request.completed",
"request.failed"
],
"payload_mode": "thin"
}'
Response:
{
"id": "whk_555",
"secret": "whsec_example_shown_once",
"verification": "pending"
}
[!WARNING] The signing secret is shown once, in this response, and never again. Store it now. If you lose it, rotate it.
payload_mode full
delivers the stored result inline; thin delivers only the async id,
path, status and event, and your receiver fetches the result by polling
with its own credentials. Use thin for endpoints you trust less than the
API itself. The URL must be HTTPS and publicly routable; private and
loopback addresses are refused at subscription and again at every
delivery.
2. Verify the endpoint. Nothing is delivered until the endpoint
passes a handshake. Make your receiver answer a POST of
{"type": "webhook.verification", "challenge": "<token>"} with any 2xx
response whose body contains the token, then
verify the endpoint:
curl -X POST "https://api.hilus.ai/Platform/jobs/webhooks/whk_555/verify" \
-H "Authorization: Bearer $HILUS_API_KEY"
Response:
{
"status": "verified"
}
3. Receive and check deliveries. Every delivery carries these headers:
X-Hilus-Webhook-Signature: HMAC-SHA256, hex, over"<timestamp>.<raw body>"with your secret.X-Hilus-Webhook-Timestamp: Unix seconds. Reject deliveries more than five minutes old.X-Hilus-Event-Id: stable for one event across all retries. Delivery is at least once and attempts can overlap, so deduplicate on it.X-Hilus-Attempt: increments with every attempt.
import hashlib
import hmac
import time
def verify(secret: str, headers, body: bytes) -> bool:
ts = headers["X-Hilus-Webhook-Timestamp"]
if abs(time.time() - int(ts)) > 300:
return False
expected = hmac.new(secret.encode(), f"{ts}.".encode() + body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, headers["X-Hilus-Webhook-Signature"])
A full payload holds event, event_id, async_id, path,
request_path, mode, status, result, failure, latency_ms and
completed_at. Answer 2xx quickly and do the work afterwards; a slow
answer counts as a failed attempt.
4. Operate it. A failed attempt is retried with exponential backoff up
to max_retries attempts.
After a long run of consecutive failed deliveries the subscription
disables itself; list subscriptions to see
consecutive_failures and disabled_reason, fix the endpoint, then set
the subscription's enabled field back to true through
entities.
To send one event again, for example after an outage on your side, redeliver it by its async id while the execution record still exists. It carries the same event id, so a deduplicating receiver treats it as the same event:
curl -X POST "https://api.hilus.ai/Platform/jobs/webhooks/whk_555/redeliver" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"async_id": "async_2f9c",
"event": "request.completed"
}'
Rotate the secret without downtime. Rotating issues a new secret and keeps the previous one valid. Deliveries are signed with the new secret; accept either in your receiver, switch to the new one, then rotate again to retire the old one.
curl -X POST "https://api.hilus.ai/Platform/jobs/webhooks/whk_555/rotate-secret" \
-H "Authorization: Bearer $HILUS_API_KEY"
Delete a subscription to stop deliveries.
When background work stops retrying
Some work Hilus does for you runs after your request has answered: analysing a conversation or call once it is over, filling in a new ticket, reading the text of a stored document or recording, sending a webhook again. A task that fails is retried with growing delays. A task that fails 10 attempts in a row stops retrying, because its cause is usually one a retry cannot fix: an agent or record it needs is not shared with the person it runs for, or an entity it names was deleted. Its work then waits for you.
List failed tasks to see what stopped. Each task says what it does, when it last failed, the first line of its error, and the ids it was working on, so you can open the conversation, call or ticket it concerns:
curl -X GET "https://api.hilus.ai/Platform/jobs/failed-tasks" \
-H "Authorization: Bearer $HILUS_API_KEY"
Response:
[
{
"id": "Platform:message-episode:conv_987",
"description": "Analyse an email or text conversation once it has gone quiet.",
"failed_at": "2026-09-15T16:02:00Z",
"first_scheduled_at": "2026-09-15T15:00:00Z",
"attempts": 10,
"last_error": "Agent agt_123 is not accessible to this principal",
"references": [
{
"name": "conversation_id",
"value": "conv_987"
}
]
}
]
Fix the cause the error names first: share the agent or record, restore what was deleted, or wait for a provider that was down. Then retry the task by its id:
curl -X POST "https://api.hilus.ai/Platform/jobs/failed-tasks/retry" \
-H "Authorization: Bearer $HILUS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"task_id": "Platform:message-episode:conv_987"
}'
Response:
{
"status": "retrying",
"id": "Platform:message-episode:conv_987"
}
A retry runs the task again shortly, as it was first asked: the same
inputs, on behalf of the same person or request, with a fresh set of
attempts. It does its real work, so it may message a contact or call a
model, and anything it did before it failed can happen again. If the
cause is not fixed it fails the same way and stops again. New activity
on the same conversation or ticket also starts its task afresh, so a
task can leave the list without a retry. not_found means the id is not
a failed task of your organization, or it already left the list.
Next steps
- Testing and debugging agents: the long-running lab calls you will most often poll.
- The jobs reference, including every field of a scheduled job, a subscription and a failed task.
- Entities, to find tools and run them with their results.