Skip to content

Commit 22bb4c4

Browse files
authored
Merge pull request #134 from Accenture/feat/ask-person-and-agent-question-twins
feat(extensions): the Node twins of ask-person and agent-question - RFC-0014 step 4
2 parents 59b45aa + b143b25 commit 22bb4c4

22 files changed

Lines changed: 6285 additions & 15 deletions

‎CHANGELOG.md‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,43 @@
7575
through the binding's own client and compares the digests (GitHub's when `GITHUB_MCP_TOKEN` is set, in both modes),
7676
so a recipe that rots fails by name.
7777

78+
4. **Ask a person, the main flow (RFC-0014 in mercury-composable, build plan step 1), in lockstep with the Python
79+
pack.** `extensions/ask-person/ask-person.mjs` serves `person.ask`, the composable function a graph's hold path calls
80+
before it suspends for a person: the message names the graph (`graph_id`, `description`, `node`), the transaction
81+
(`correlation_id`, `turn`), the waiting `calls` as the loop returned them and the suspension's `ttl`; the function
82+
issues a signed, stateless ticket (`v1.<payload>.<mac>`, the canonical payload and its HMAC-SHA256 under
83+
`ask.ticket.key`, a previous key verifying after a rotation), builds the resume link and sends the whole message as
84+
one event to every route in `ask.channels` - the agent-question app's intake, a chat poster, a mail sender, a topic
85+
publisher - knowing nothing of what a route does with it; a channel that fails is logged by type and never fails the
86+
hold. `kind: advice` travels with no ticket and no link. The resume link opens the wait on the process's reply page,
87+
`GET /ask/{ticket}`, read from the engine by the reference graph's re-advice and never resuming; `POST /ask/reply`
88+
with `{ticket, decisions}` verifies the ticket, maps the graph id to the engine's entry through the `ask.graphs`
89+
allowlist, prefixes who decided and when to each tool call's note, sends the resume and returns the engine's outcome;
90+
an expired ticket is a 410 without a call to the engine. Who may answer is `ask.reply.auth`: `none` (development),
91+
`proxy` (the gateway's trusted header) or `oauth2` (an access token validated against the issuer's keys with `jose`,
92+
imported on first use), and a channel app's bearer with `decided_by`. The host gains `Platform.addRoutes` and
93+
`EventApiServer.createServer(routes)`: an extension mounts its own pages and streams after the host's paths and
94+
before the catch-all. Pinned by `test/vectors/ask-person-vectors.json` (72 cases, byte-identical with the Python pack
95+
- the ticket's HMAC reproduced from the file alone) and `test/ask-person.test.mjs` (97 tests). **Upgrade note:** none
96+
- `addRoutes` is additive.
97+
98+
5. **The agent-question app: a store-and-forward inbox for the person an agent asks (RFC-0014, build plan step 3), in
99+
lockstep with the Python pack.** `extensions/agent-question/agent-question.mjs` is a standalone application on the
100+
package and the first channel of the design; the main flow knows nothing of it. `agent.question.inbox` is the intake:
101+
a wait is upserted on `(graph_id, correlation_id, turn)` and an advice appended, the row committed before any push.
102+
The person's side runs under the host: `GET /questions/app` (the page), `GET /questions?since=<seq>` (the replay a
103+
reconnecting device calls first, with the cursor to continue from), `GET /questions/events` (the stream,
104+
`Last-Event-ID` the same cursor), `POST /questions/{id}/decide` (the automated click: `{ticket, decisions,
105+
decided_by}` to the link's own base under the app's bearer, the outcome recorded and broadcast; accepted →
106+
`answered`, nothing waiting → `expired`, refused or unreachable → `open`) and `POST /questions/{id}/seen`. A sweeper
107+
and every replay expire open waits past their expiry. The inbox is memory (development) or PostgreSQL
108+
(`question.inbox: postgres`, the `pg` driver, `schema/postgres.sql` and `purge.sql` byte-identical with the Python
109+
pack, `dev/schema-apply.sh` for the helper's development database). Who may use the page is `question.auth`: `none`,
110+
`proxy` or `oauth2`. Pinned by `test/vectors/agent-question-vectors.json` (30 cases, byte-identical - the reference
111+
inbox replayed on the scripted sequence lands on the same rows, ids and change sequence) and
112+
`test/agent-question.test.mjs` (48 tests; a live PostgreSQL gated on `AGENT_QUESTION_TEST_URL`). **Upgrade note:**
113+
none - a new application.
114+
78115
### Changed
79116

80117
1. **`web.crawl` accepts a relative `include`**, in lockstep with the Python pack: a prefix that does not start with `/` matches

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ This package is a deliberately **lightweight wrapper of the Event-over-HTTP prot
2828
in its catalog — files inside one workspace, the web inside an allowlist of sites, the agent's knowledge
2929
graph inside one database, a clock — each a composable function whose sandbox is deployment
3030
configuration, never an argument of a call, with its catalog row published.
31+
- the **ask-a-person main flow** extension (`extensions/ask-person`): `person.ask`, the function a graph's hold path
32+
calls before it suspends for a person - a signed, stateless ticket, the resume link and one message event to the
33+
installation's channels; the reply page and endpoint that bring the decision back (RFC-0014, step 1);
34+
- the **agent-question app** (`extensions/agent-question`): the first channel of that design, a store-and-forward
35+
inbox for a person whose device is not always connected - the intake, the replay, the stream and the automated click
36+
(RFC-0014, step 3).
3137

3238
Orchestration deliberately stays in the engines. Functions written here are addressed by
3339
route name through the engines' declarative `yaml.event.over.http` map, so a flow or a
@@ -225,6 +231,10 @@ a loop names in its catalog, each a composable function inside a sandbox the dep
225231
(the npm package does not ship it). Its `llm.chat` is configurable: a stateless chat, or one
226232
turn of a multi-turn tool-use loop whose transcript lives in the store the helper is configured
227233
with.
234+
The ask-a-person main flow in `extensions/ask-person/` carries such a loop's wait for a person to the installation's
235+
channels and brings the decision back through a resume link, knowing no channel and keeping no store; the
236+
agent-question app in `extensions/agent-question/` is one of those channels, a store-and-forward inbox for an
237+
occasionally connected device, a separate application on the same package.
228238

229239
## License
230240

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# The agent-question app (Node.js)
2+
3+
The first channel of RFC-0014 (mercury-composable, `draft-design-specs/ask-a-person-channel.md`, Part II): a
4+
**store-and-forward inbox** for a person whose device is not always connected, standing beside a chat, a mail server
5+
or a topic as one channel among equals. The main flow - `person.ask` in [`extensions/ask-person`](../ask-person/README.md)
6+
- knows nothing of it: it sends one message event with the resume link to the routes it is configured with, and this
7+
application is one of those routes. It is a standalone application on the package, run in its own process.
8+
9+
- **Intake.** `agent.question.inbox` is a composable function reached over Event-over-HTTP like any peer function. A
10+
wait (`kind` `approval` or `question`) is **upserted** on `(graph_id, correlation_id, turn)` - a re-advice for the same
11+
turn updates the card rather than adding one - and an **advice** (a status update, an acknowledgement, an outcome) is
12+
**appended**, since those accumulate. Write first: the row is committed before any push to a browser.
13+
- **The person's side**, under the pack's host: `GET /questions/app` is the page; `GET /questions?since=<seq>` the
14+
**replay** a reconnecting device calls first - every row that changed since its cursor, waits and advices alike, with
15+
the cursor to continue from; `GET /questions/events` the **stream** a connected device holds, each event carrying a
16+
changed row, `Last-Event-ID` the same cursor, so a browser's reconnect misses nothing. The person selects which card
17+
to answer, in any order; the card's button **automates the click**: `POST /questions/{id}/decide` posts
18+
`{ticket, decisions, decided_by}` to the main flow's reply endpoint - the link's own base, under this app's bearer -
19+
records the outcome on the row and tells every connected device. `POST /questions/{id}/seen` marks an advice read.
20+
- **States.** A wait is `open` until the engine accepts the decision (`answered`) or finds nothing waiting
21+
(`expired`); a refused decision or an endpoint that did not answer leaves it `open` with the outcome shown. An
22+
advice is `open` until the person marks it `seen`. Open waits past their expiry are marked `expired` by a sweeper
23+
and before every replay. The engine stays the authority: a second device on the same card gets `nothing waiting`,
24+
and the row records the first. Rows are never deleted here; `schema/purge.sql` is the installation's.
25+
26+
The Python twin (mercury-python `extensions/agent-question`) serves the same route, the same page and the same schema,
27+
pinned by the same vector file (`test/vectors/agent-question-vectors.json`, byte-identical in both packs).
28+
29+
## Run
30+
31+
```bash
32+
node dist/src/cli.js extensions/agent-question/agent-question.mjs # the inbox in memory, no sign-in: development
33+
open http://127.0.0.1:8092/questions/app
34+
```
35+
36+
Point the main flow at it: in the ask-person extension, `ask.channels: [agent.question.inbox]` and
37+
`ask.channel.endpoints: [{route: agent.question.inbox, url: http://127.0.0.1:8092/api/event}]`. For a deployment:
38+
39+
```bash
40+
npm install pg
41+
POSTGRES_PASSWORD=... extensions/llm-helper/dev/postgres-up.sh # the development database the helper also uses
42+
extensions/agent-question/dev/schema-apply.sh # schema/postgres.sql, safe to repeat
43+
node dist/src/cli.js extensions/agent-question/agent-question.mjs -Dquestion.inbox=postgres -Dquestion.inbox.postgres.ssl=false
44+
```
45+
46+
The extension reads `resources/application.yml` next to `agent-question.mjs`, whichever directory the command runs
47+
from; `-Dkey=value` overrides any key. It listens on port 8092 by default. The boot stops the application by name when
48+
the inbox is `postgres` without the driver, when the database does not answer, or when the auth mode is unknown; with
49+
the inbox in memory it warns that a restart forgets every card.
50+
51+
## The row
52+
53+
What a message event becomes (the replay and the stream carry rows in this shape):
54+
55+
| Field | Meaning |
56+
| --- | --- |
57+
| `id`, `seq` | the row, and the change sequence a replay reads from (bumped on every write) |
58+
| `kind`, `graph_id`, `correlation_id`, `turn` | from the message; a wait upserts on the last three |
59+
| `ticket`, `link`, `expires_at` | a wait's, from the message; null for an advice |
60+
| `description`, `summary`, `details`, `calls` | what the card shows; `calls` is the approval block as the loop returned it |
61+
| `state` | `open`, `answered`, `expired` (a wait) or `seen` (an advice) |
62+
| `requested_at`, `updated_at` | the message's time and the row's last change |
63+
| `answered_at`, `answered_by`, `decisions`, `outcome` | the click: who, when, what, and the reply endpoint's answer |
64+
65+
## Identity
66+
67+
`question.auth`: `none` in development - no sign-in, the page offers a name field the decision carries as
68+
`decided_by`; `proxy` - the installation's SSO, a trusted header set by the gateway (`question.auth.header`,
69+
`x-forwarded-user`) names the person; `oauth2` - a bearer access token validated against the issuer's published keys
70+
(`question.auth.oauth2.issuer`, `.audience`, or `.jwks-url`; the `jose` library). The app passes the person to the
71+
main flow as `decided_by` under its own bearer (`question.reply.token`, the reply endpoint's `ask.reply.auth.token`).
72+
73+
## Configuration
74+
75+
| Key | Default | Meaning |
76+
| --- | --- | --- |
77+
| `question.inbox` | `memory` | `memory` or `postgres` |
78+
| `question.inbox.postgres.host` / `.port` / `.database` / `.username` / `.password` / `.ssl` / `.timeout.ms` | the helper's audit store's defaults | the connection; the password a `${POSTGRES_PASSWORD}` reference |
79+
| `question.sweep` | `30s` | how often open waits past their expiry are marked expired |
80+
| `question.auth` | `none` | `none`, `proxy` or `oauth2` |
81+
| `question.auth.header` | `x-forwarded-user` | with `proxy` |
82+
| `question.auth.oauth2.issuer` / `.audience` / `.jwks-url` | - | with `oauth2` |
83+
| `question.reply.token` | - | the bearer presented to the reply endpoint |
84+
| `question.reply.timeout` | `10s` | how long the reply endpoint may take |
85+
| `question.page.title` | `Agent questions` | the page's title |
86+
87+
## Tests
88+
89+
`test/agent-question.test.mjs` runs the shared vectors (`test/vectors/agent-question-vectors.json`: the row a message
90+
becomes, the state an outcome leaves, the request the click sends, the inbox's transitions on a scripted sequence) and
91+
drives the app in-process: the intake on the bus, the replay and the stream, a decision forwarded to a fake reply
92+
endpoint with the outcome recorded and broadcast, an advice marked seen, the proxy mode, the PostgreSQL inbox's
93+
statements on a recording fake of the pool, and - gated on `AGENT_QUESTION_TEST_URL` - the schema and the rows on a live
94+
PostgreSQL.

0 commit comments

Comments
 (0)