Search and contents

The order narrative route: a drafted summary of an order's trail, on request

An MES Node can write a plain-language narrative of one order's trail or genealogy when a caller asks for it. The model call needs the Node's own inference configuration, and the management API has none and is given no model client, so the request is answered by a small listener in the Node process itself. It is off unless you turn it on, and it needs nothing in the Node's config file.

What it returns is a draft for a person to review. It is a summary of what this Node and its peers recorded, never a determination, and every answer says so.

Turning it on

Set these in the Node's environment (or its .env), then restart the Node:

SettingMeaningDefault
ORDER_NARRATIVE_PORT The port to listen on. Unset, the listener is off. unset
ORDER_NARRATIVE_LISTEN_HOST A literal IP address. Loopback serves plain HTTP; a private-network address serves TLS from the Node's own certificate and is refused if that certificate is missing or invalid. A hostname, a public address or 0.0.0.0 is refused. 127.0.0.1
ORDER_NARRATIVE_TOKEN_FILE The token file callers are held to. MANAGEMENT_TOKEN_FILE
ORDER_NARRATIVE_MIN_INTERVAL_SECONDS The least time between one token's requests (more than 0, at most 3600). 30
ORDER_NARRATIVE_DAILY_CAP The most requests one token may make in a UTC day (1 to 10000). 50

A setting that is not valid stops the Node before it starts, and the message names the setting, never its value. The Node also stops, with one line in its log and before it announces itself, when the port is set and its config has no inference section (there would be no narrative to draft), or when the bind or the certificate is refused.

The Node's certificate is found the way the management API finds it: KINDRED_NODE_PKI_DIR, else the certificate scripts' default directory. A client with no certificate is served; the token is what authenticates.

Who may ask

The tokens are the management API's: the same file, minted the same way. The route needs the correlation scope, because it carries what the trail and genealogy routes carry (peers' Activity Log entries and identity attributes), and no other scope opens it.

deployment/mint_management_token.sh --id plant-lead --scope correlation --expires-in 90d

A missing, unknown, revoked or expired token is one 401 whatever it was, and a valid token without the scope is a 403. Failures are logged to the Node's own log with the token's id when it can be named, never to the Activity Log. Every request the listener can read is authenticated first, an unknown path or method included, so a caller with no token learns nothing of which routes exist.

Asking

curl -s -H "Authorization: Bearer $TOKEN" \
  http://127.0.0.1:8480/v1/orders/MO-1001/trail/narrative

curl -s -H "Authorization: Bearer $TOKEN" \
  http://127.0.0.1:8480/v1/orders/MO-1001/genealogy/narrative

The Node assembles the order's trail or genealogy as itself (asking its declared peers, as a trail read does) and hands it to the narrative task. A Node with no communication_interface asks no one, and its narrative says so.

{
  "order_id": "MO-1001",
  "subject": "trail",
  "status": "drafted_for_review",
  "label": "Drafted for a person to review. It is a summary of what this Node and its peers recorded, not a determination.",
  "narrative": "**Order Narrative: MO-1001** ...",
  "source": "model",
  "fallback": false,
  "fallback_reason": null,
  "complete": true,
  "prompt": { "name": "order-trail-narrative", "version": "0.5.0" }
}
FieldMeaning
status, label Always a draft for review.
narrative The text. Never empty.
source model (a model wrote it), cache (a model wrote it earlier for byte-identical input under the same prompt) or fallback (see below).
fallback, fallback_reason true when this Node declares inference_enabled: false: the answer is the fixed fact listing the narrative task writes with no model, and fallback_reason says so.
complete Whether the trail or genealogy held every Node's part.
prompt The name and version of the prompt that wrote the text, so a draft can be traced to its wording. null for a fallback: code wrote it, no prompt did.

The narrative prompt is an open asset, not a licensed one, so there is no unlicensed state: the only way to get the fallback is to declare inference off.

An incomplete trail

A trail that does not hold every Node's part is narrated as incomplete, in a section written by code from the trail and not by the model, so the narrative cannot present part of an order as the whole whatever the model made of its prompt. A peer that did not contribute is named only there, as missing and why (- ERP: unreachable), never in the story as having taken part. A Node that asked no peers says that no peers were asked.

What the answers are

StatusMeaning
200 A draft.
401 No token, or one that is unknown, revoked, expired or replaced by a rotation.
403 A valid token without the correlation scope.
404 No such route, or no identity record on file for the order.
405 Any method but GET.
409 The order's identity record, on this Node or on a peer, is not resolved.
422 The order id is empty, over 256 characters, or holds a control character.
429 A limit (below), with a Retry-After header in seconds.
502 The model did not answer, or answered with nothing. No narrative is returned: a text the model did not write is never made up.
503 The Activity Log or the identity store could not be reached.

The limits

Every request runs a model, so three limits stop one token, or a script, from running up the GPU. Each is a 429 with Retry-After, and none writes an Activity Log entry: a refusal is not an event of the order, and refusals must not be a way to fill the log.

  • Interval. One token waits ORDER_NARRATIVE_MIN_INTERVAL_SECONDS between requests. Each token has its own.
  • Daily cap. One token makes at most ORDER_NARRATIVE_DAILY_CAP requests per UTC day. It is reported before the interval, so a token that has used its day is told to come back tomorrow, not in 30 seconds.
  • One at a time. A second request while a narrative is being drafted is refused, from any token.

A request is counted when it is let in, before any peer is asked, whatever it comes to (a 404 for an order that is not on file counts), except that a 500 or 503, which are the Node's own failures, give the day's count back (the interval stays, which paces a retry). A request refused for an order id that cannot be one, or turned away for being busy, is not counted. The limits are kept in memory: a restart clears them.

Stopping the Node waits up to 60 seconds for a narrative being drafted, so a request mid-run is not cut off under the stores and the model client it is using.

What it writes

The narrative task writes one Activity Log entry per run, on the Node, under the order:

  • the prompt's name and version (prompt_name, prompt_version), none for a fallback;
  • draft_status: for_review, which labels the entry a draft and not a determination;
  • token_id, the id of the token that asked (never the token);
  • the outcome narrated, or narrated_cached when the cache answered.

A run that fails (a 502) writes the entry the task always writes for a failure. A request refused before a run (any other status than 200) writes no narrative entry; the peers a trail read asked, if it got that far, are logged as for any trail read.

What it does not do

  • It is not on the management API, which gains no model client: a test pins that no module under engine/management/ imports one.
  • It needs the Node running. The management API's trail and genealogy routes, which stay up with the Node stopped, return the structured answer; this route is for the written summary.
  • It does not page a genealogy. The narrative covers every material the order links, but looks up at most 50 of them on peers, and for at most 20 seconds; materials not looked up in that time or number are named as such in the narrative's incomplete section. The structured genealogy route pages, and has controls for both.

Release: v0.11.0