Agent protocol
An Epic.direct Agent is a worker that runs connector drivers outside the platform: for a system that needs a long-lived session, or one that can only be reached from inside a network the hospital has approved. The agent calls the platform; the platform never calls the agent.
Where this stands#
The protocol on this page is implemented and tested on the platform, and the worker in the repository speaks it. What an agent can do with it today is limited by the catalogue:
| Connector type that runs in an agent | State |
|---|---|
| Epic Hyperspace via Citrix | Preview |
| Epic Hyperspace via Omnissa Horizon | Preview |
| Epic Hyperspace training simulator | Available |
| Patient context: hospital EMR side | Preview |
| HL7 v2 feed (MLLP) | Preview |
| Patient context: Fujifilm Synapse side | Preview |
| Velox reading list | Preview |
Hosting#
| Hosted by Epic.direct | Hosted by the workspace | |
|---|---|---|
| Registered by | A platform administrator, in the admin console | A member with connections.manage, on the workspace’s Agents page |
| Runs | On Epic.direct's infrastructure | On a host inside a network the hospital has approved |
| Suited to | A system reachable from the internet, where the hospital has authorised that access | A system reachable only from the hospital's network, or where access must come from a known machine |
Either way the agent makes outbound HTTPS requests only and listens on no port. An agent sees work only for the connections assigned to it, and a workspace’s administrator makes that assignment on the connection.
Address and authentication#
Every operation is a POST with a JSON body to the platform’s HTTP address:
https://tame-oyster-517.convex.site/agent/v1/- Authenticate with the agent’s token:
Authorization: Bearer eda_…. It is shown once at registration and stored only as a SHA-256 hash. - Revoking an agent unassigns its connections and takes effect on its next request.
- A request body may be up to 4,000,000 characters.
| Status | Code | When |
|---|---|---|
| 401 | invalid_agent_token | The token is missing, unknown or revoked. |
| 400 | invalid_json | The body is not JSON. |
| 400 | invalid_request | A required field is missing. |
| 404 | not_found | No such operation, or no such connection for this agent. |
| 413 | too_large | The body is over the size limit. |
Operations#
| Operation | Purpose |
|---|---|
hello | Announce the agent and learn which connections are assigned to it. |
claim | Take the next queued job, if there is one. |
heartbeat | Keep the lease on a running job. |
finish | Report the outcome of a job. |
mfa/request | Ask a person for a sign-in code or approval. |
mfa/collect | Collect that person's answer. |
hello
Call it at start-up. It marks the agent as seen, and records the three optional fields so they can be shown on the Agents page.
{ "version": "0.1.0", "hostname": "reading-room-02", "drivers": ["selftest"] }{
"data": {
"agent": { "id": "…", "name": "Main campus on-site agent" },
"connections": [
{ "id": "…", "typeId": "epic-hyperspace-citrix", "name": "…", "status": "draft", "capabilities": ["connection.test"] }
]
}
}claim
Send an empty body. The answer is either { "data": { "job": null } } or one job. Claiming is a single transaction, so two workers sharing a token are never given the same job.
{
"data": {
"job": {
"id": "n17q3w5e7r9t1y3u5i7o9p2a4s",
"attempt": 1,
"lease_until": 1795787584000,
"kind": "protocols.submit",
"connection": {
"id": "kd72m4n6b8v0c1x3z5a7s9d2f4",
"typeId": "epic-hyperspace-citrix",
"config": { "portalUrl": "https://…" },
"capabilities": ["connection.test", "requisitions.list", "protocols.submit"]
},
"secrets": { "username": "…", "password": "…" },
"submission": {
"externalId": "…",
"protocolCode": "CT-AP-IV",
"notes": "…",
"approvedBy": "…"
}
}
}
}| Field | Meaning |
|---|---|
id | The job. Send it back as job_id. |
attempt | Which attempt this is. Send it back unchanged: it is how the platform knows a report belongs to the current claim. |
lease_until | When the lease runs out, in Unix milliseconds, unless a heartbeat extends it. |
kind | The job kind. |
connection | The connection's id, connector type, settings and capabilities. |
secrets | The connection's credentials, unsealed for this job. |
submission | For protocols.submit only: the order’s id in the source system, the approved protocol code, the radiologist’s notes and who approved it, with locator (the row to find first) and, where the hospital takes a form, form (the buttons to press, in order). See Protocol forms. Otherwise null. |
heartbeat
Call it while a job runs, well inside the lease. Each call extends the lease by the job kind’s lease time.
{ "job_id": "…", "attempt": 1 }{ "data": { "held": true } }held: false means the claim is no longer yours: the lease ran out and the platform has already retried or failed the job. Stop the work and report nothing.
A heartbeat renews the job, not the agent’s presence. Only hello and claim mark the agent as seen, and an agent not seen for three minutes is shown as offline. A worker on a long job should call hello about once a minute.
finish
Report success with the driver’s output, or failure with a kind.
{ "job_id": "…", "attempt": 1, "ok": true, "output": { "message": "Signed in" } }{
"job_id": "…", "attempt": 1, "ok": false,
"error": "The system did not answer",
"error_kind": "unreachable",
"retryable": true
}{ "data": { "settled": true } }error_kindis one ofauth,unreachable,rejected,unsupported,invalid,internal. Anything else is recorded asinternal.erroris kept to 500 characters, stored with the job and shown to operators. It must not contain patient details or a credential.retryableis taken as true only when it is exactlytrue.settled: falsemeans the report was not accepted, because the claim had already passed to someone else.
What the platform reads from a successful output:
| Job kind | Output | Effect |
|---|---|---|
connection.test | message, up to 300 characters | Recorded as the result of the test. |
protocols.options.sync | options: protocol options | Replaces what is known of the hospital's protocol list from this source. |
requisitions.sync | requisitions, and optionally options | Requisitions are created, updated or closed to match the source. |
protocols.submit | confirmed: true, and optionally reference | The requisition is marked submitted. Without confirmed: true the job is settled as rejected and not retried. |
studies.sync | studies: an array of study records | Studies are added to the reading worklist or updated in place, as they are for a connector the platform runs. |
- Records must have the shapes in
@epicdirect/core:RequisitionRecordandProtocolOptionRecord. Output that does not match is settled asinvalid, is not retried, and is not echoed back. confirmed: truemay only be sent after the protocol was written and read back as saved. This is the one rule the whole submission path rests on.
mfa/request and mfa/collect
Some sign-ins need a person: a code sent by text, a code read from an authenticator app, or an approval in one. A driver asks for it through the platform and waits.
{ "connection_id": "…", "kind": "sms_code" }{ "data": { "challenge_id": "…" } }kindissms_code(the default),authenticator_codeorauthenticator_number. Withauthenticator_codea person types the 6-digit code their authenticator app shows, andcollectreturns it like a texted code. Withauthenticator_numbernothing is typed:promptcan carry the number to choose, up to 20 characters.- The request appears in the workspace, and the workspace’s notification numbers are sent a text if it has any.
- A member with
credentials.manageanswers in the workspace, or a code is sent back by text reply. Either way the answer is written to the audit trail, without the code. - A new request replaces any earlier one still waiting for the same connection.
{ "challenge_id": "…" }{ "data": { "status": "answered", "code": "…" } }status is waiting, answered or expired. A request expires after five minutes. The code is handed over once and then erased, so a second collect returns answered without it.
The worker loop#
hello. If the platform cannot be reached, wait and try again, doubling the wait to a ceiling.claim. Onnull, wait a few seconds and claim again.- Run the job with the driver for
connection.typeId. With no driver for it, finish asunsupported, not retryable. heartbeaton an interval while it runs. Onheld: false, abandon the job.finish, then clear the credentials from memory.- On a stop signal, stop claiming. Give a running job a short time to complete, then finish it as a retryable failure so the queue does not wait out the lease.
- On
401, exit. The token was revoked and retrying cannot help.
The worker in the repository#
services/agent implements that loop on Node 22 with no dependencies. It reads EPICDIRECT_URL and EPICDIRECT_AGENT_TOKEN from the environment, writes structured logs that cannot hold a credential or patient data, and ships a container definition.
# Check the installation. Needs no network, no token and no clinical system.
node src/index.ts selftest
# Run the worker.
export EPICDIRECT_URL="https://tame-oyster-517.convex.site"
export EPICDIRECT_AGENT_TOKEN="eda_…"
node src/index.tsWith both variables set, selftest also calls hello, which proves the address, the token and the route out of the network. It never claims a job. To add a driver, see Adding a connector.