@abgov/adsp-sdk-mcp-server 1.24.0 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +24 -12
  2. package/assets/docs/getting-started.md +6 -5
  3. package/assets/docs/platform/deployment.md +1 -1
  4. package/assets/docs/platform/getting-started.md +3 -18
  5. package/assets/docs/platform/platform-flask-sdk.md +44 -0
  6. package/assets/docs/platform/platform-node-sdk.md +6 -5
  7. package/assets/docs/services/access-service.md +10 -12
  8. package/assets/docs/services/agent-service.md +49 -8
  9. package/assets/docs/services/audit-service.md +252 -133
  10. package/assets/docs/services/configuration-service.md +163 -59
  11. package/assets/docs/services/event-service.md +138 -33
  12. package/assets/docs/services/form-service.md +152 -12
  13. package/assets/docs/services/notification-service.md +2 -0
  14. package/assets/docs/services/pdf-service.md +7 -7
  15. package/assets/docs/services/pii-service.md +16 -0
  16. package/assets/docs/services/project-planner-service.md +11 -11
  17. package/assets/docs/services/push-service.md +3 -3
  18. package/assets/docs/services/services.md +44 -0
  19. package/assets/docs/services/status-service.md +162 -6
  20. package/assets/docs/services/token-handler.md +68 -10
  21. package/assets/docs/services/value-service.md +95 -9
  22. package/assets/docs/services/verify-service.md +20 -1
  23. package/assets/docs/tutorials/access-service/themes.md +1 -1
  24. package/assets/docs/tutorials/form-service/ai-agent.md +1 -1
  25. package/assets/docs/tutorials/form-service/building-forms.md +1 -1
  26. package/assets/docs/tutorials/form-service/cheat-sheet.md +1 -1
  27. package/assets/docs/tutorials/form-service/form-app.md +1 -1
  28. package/assets/docs/tutorials/form-service/form-submissions.md +1 -1
  29. package/assets/docs/tutorials/form-service/introduction.md +1 -1
  30. package/assets/docs/tutorials/form-service/security.md +1 -1
  31. package/assets/docs/tutorials/status-service/health.md +1 -1
  32. package/assets/docs/tutorials/status-service/status.md +2 -2
  33. package/package.json +1 -1
  34. package/src/docs/docsRepository.js +1 -5
  35. package/src/docs/docsRepository.js.map +1 -1
  36. package/src/metrics.js +2 -11
  37. package/src/metrics.js.map +1 -1
  38. package/src/sdk-reference/search.js +1 -1
  39. package/src/sdk-reference/search.js.map +1 -1
  40. package/src/search/aliases.d.ts +6 -0
  41. package/src/search/aliases.js +20 -0
  42. package/src/search/aliases.js.map +1 -0
  43. package/src/search/textSearch.d.ts +5 -0
  44. package/src/search/textSearch.js +15 -0
  45. package/src/search/textSearch.js.map +1 -1
  46. package/src/server.js +2 -1
  47. package/src/server.js.map +1 -1
  48. package/src/tools/registerDocsTools.js +63 -3
  49. package/src/tools/registerDocsTools.js.map +1 -1
  50. package/src/version.d.ts +7 -0
  51. package/src/version.js +20 -0
  52. package/src/version.js.map +1 -0
package/README.md CHANGED
@@ -5,20 +5,27 @@ An MCP (Model Context Protocol) server that gives an AI coding assistant grounde
5
5
  (`@abgov/adsp-service-sdk`), instead of guessing.
6
6
 
7
7
  It bundles the ADSP documentation site content and a curated reference of every `@abgov/adsp-service-sdk` export,
8
- and exposes them over stdio via five tools:
8
+ and exposes them over stdio via seven tools:
9
9
 
10
10
  - `search_adsp_docs` — keyword search across ADSP platform docs (getting started, architecture, service concepts,
11
- tutorials).
12
- - `read_adsp_doc` — read the full content of a doc page found via search.
11
+ tutorials). Common words people use that the docs don't, such as `websocket` or `auth`, also search for the
12
+ docs' own terms (`src/search/aliases.ts`).
13
+ - `list_adsp_docs` — list the path and title of every bundled doc page, optionally under a path prefix such as
14
+ `services/`, for browsing when keyword search misses.
15
+ - `read_adsp_doc` — read the full content of a doc page found via search or the list.
13
16
  - `search_sdk_reference` — search `@abgov/adsp-service-sdk` by symbol name, module, or keyword; returns full symbol
14
17
  details (kind, description, option/return shape, example, deprecated flag).
15
18
  - `get_platform_quickstart` — the canonical `initializeService` usage pattern (the common case for a tenant service
16
19
  built on top of ADSP) and a capabilities summary, for the most common question: how to start using ADSP from a
17
20
  Node service.
18
- - `list_service_roles` — **the one tool that talks to a real ADSP environment**, not bundled/offline data. Reads
19
- every platform service's registered RBAC role live from tenant-service configuration, so an agent can pick a
20
- least-privileged role instead of defaulting to an admin role. Requires logging in first (see below) — everything
21
- else in this package works fully offline with no setup.
21
+ - `list_service_roles` — **live: talks to a real ADSP environment**, not bundled/offline data. Reads every platform
22
+ service's registered RBAC role from tenant-service configuration, so an agent can pick a least-privileged role
23
+ instead of defaulting to an admin role.
24
+ - `get_service_configuration_schema` — **live.** Reads platform services' configuration schemas from
25
+ configuration-service, for the shape of `serviceConfigurations` entries in `initializeService`.
26
+
27
+ The two live tools require logging in first (see below). Everything else in this package works fully offline with no
28
+ setup.
22
29
 
23
30
  This package covers the Node SDK only. Other language SDKs (`.NET`, Django, Flask, Spring) are out of scope for now.
24
31
 
@@ -105,7 +112,7 @@ Things to know when sizing and tuning these:
105
112
  | Client | Over the cap for longer than `MCP_IN_FLIGHT_WAIT_MS` | Over the cap briefly (`MCP_IN_FLIGHT_WAIT_MS=3000`, slots freed after 0.5 s) |
106
113
  |---|---|---|
107
114
  | `@modelcontextprotocol/sdk` 1.32.1 | `connect()` throws `StreamableHTTPError` (code 503) after the wait. One request, no retry, `Retry-After` ignored | Connects and calls the tool after about 0.5 s |
108
- | `@mastra/mcp` 1.8.1 | Logs `MCP_CLIENT_GET_TOOLS_FAILED` and `listTools()` returns no tools from this server, without throwing. One request, no retry | Lists all six tools and calls one after about 0.5 s |
115
+ | `@mastra/mcp` 1.8.1 | Logs `MCP_CLIENT_GET_TOOLS_FAILED` and `listTools()` returns no tools from this server, without throwing. One request, no retry | Lists all tools and calls one after about 0.5 s |
109
116
 
110
117
  So a `503` becomes a failed tool call, or an agent turn with no ADSP tools at all. Size `MCP_MAX_IN_FLIGHT` and
111
118
  the replica count so it stays rare, and watch `mcp.requests.rejected`.
@@ -130,7 +137,7 @@ OpenTelemetry SDK isn't loaded. Stdio mode never exports metrics.
130
137
 
131
138
  Every label takes a value from a fixed set:
132
139
 
133
- - `mcp.tool.name`: one of the six tool names, or `unknown` for any name the server doesn't have.
140
+ - `mcp.tool.name`: one of the seven tool names, or `unknown` for any name the server doesn't have.
134
141
  - `mcp.method.name`: an MCP method such as `initialize`, `tools/list` or `tools/call`; `other` for any other method;
135
142
  `batch` for a JSON-RPC batch; `unparsed` when the body wasn't valid JSON-RPC or was too large.
136
143
  - `error.type` on `mcp.request.duration`: `aborted` when the client disconnected before the response was written; the
@@ -142,9 +149,9 @@ Every label takes a value from a fixed set:
142
149
  request, which `adsp-cli` reports the same way.
143
150
  - `reason` on `mcp.requests.rejected`: `in_flight_cap`, `rate_limit`, `origin` or `live_tool_cap`.
144
151
 
145
- ### Using `list_service_roles`
152
+ ### Using the live tools
146
153
 
147
- That one tool needs a real ADSP environment and a logged-in session (via `@abgov/adsp-cli`, a separate package this
154
+ `list_service_roles` and `get_service_configuration_schema` need a real ADSP environment and a logged-in session (via `@abgov/adsp-cli`, a separate package this
148
155
  one depends on). One-time setup — no MCP client config changes needed:
149
156
 
150
157
  ```bash
@@ -158,7 +165,7 @@ client config. `ADSP_TENANT_REALM` remains available as an optional override (e.
158
165
  The same role data is also available directly from a terminal, without an MCP client at all: `npx @abgov/adsp-cli
159
166
  service-roles`.
160
167
 
161
- If `list_service_roles` is called without a valid login, it returns a clear, actionable error (telling you to run
168
+ If either live tool is called without a valid login, it returns a clear, actionable error (telling you to run
162
169
  `npx @abgov/adsp-cli login`) rather than failing silently or hanging — it never opens a browser or blocks waiting for
163
170
  one itself.
164
171
 
@@ -170,6 +177,11 @@ nx test adsp-sdk-mcp-server
170
177
  nx lint adsp-sdk-mcp-server
171
178
  ```
172
179
 
180
+ `src/sdk-reference/reference.ts` is maintained by hand. `reference.spec.ts` reads the root exports of
181
+ `libs/adsp-service-sdk/src/index.ts` with the TypeScript compiler and fails when the reference drifts: a missing or
182
+ stale name, or a different kind, module or deprecated flag, or a `seeAlso` with no entry. When you change what the SDK
183
+ exports, update `reference.ts` in the same PR.
184
+
173
185
  `src/fixtures/tool-contract.golden.json` is maintained by hand. It pins only the docs tools' and the unknown tool's
174
186
  output over the fixture docs in `src/fixtures/docs`; the other tools are checked for equal output across transports
175
187
  instead, so SDK reference and quickstart edits don't touch it. If you change docs search or the docs tools' output on
@@ -35,7 +35,7 @@ The tenant administration app allows you to configure platform services for your
35
35
 
36
36
  After your tenant is created, you will have access to the tenant administration application. As the original creator of a tenant, you can login from the landing page of ADSP to access tenant administration.
37
37
 
38
- For other team members, note the instructions and tenant specific login LRN shown in the aside on the _Dashboard_ view (either on the right or the bottom). Team members can login via this url to provision their user in the tenant realm; they will start with no access to tenant administration.
38
+ For other team members, note the instructions and tenant specific login URL shown in the aside on the _Dashboard_ view (either on the right or the bottom). Team members can login via this url to provision their user in the tenant realm; they will start with no access to tenant administration.
39
39
 
40
40
  **To grant administration access to team members**
41
41
 
@@ -65,7 +65,7 @@ Once you have an event definition configured, you can use the event service API
65
65
  **To create a service account**
66
66
 
67
67
  1. In Keycloak realm administration, from _Clients_, click _Create client_ to create a client to use with a service account.
68
- 2. Set the _Client Type_ to "Confidential", enter a _Client ID_ (e.g., `urn:ads:platform:event-service` for event service).
68
+ 2. Set the _Client Type_ to "Confidential", enter a _Client ID_ for your application (e.g., `my-event-sender`).
69
69
  3. Under _Client authentication_, toggle _Client authentication_ to **On**.
70
70
  4. Under _Authentication flow_, toggle _Service accounts_ to **On**.
71
71
  5. Set _Valid redirect URIs_ to https://api.adsp.alberta.ca and _Web origins_ to +.
@@ -79,14 +79,14 @@ Once you have an event definition configured, you can use the event service API
79
79
  1. In tenant administration, from the _Services_ -> _Events_ view, click the _Read the API docs_ link in the aside (either on the right or the bottom).
80
80
  2. In API documentation, click _Authorize_, and login using `client_credentials` grant with the client created above.
81
81
  3. Expand the _POST /event​/v1​/events_ endpoint, click _Try it out_.
82
- 4. In the _Request body_ text field, set the namespace and name of the event to match your definition and the timestamp to an ISO2601 timestamp (e.g. 2021-10-02T12:00:00Z).
82
+ 4. In the _Request body_ text field, set the namespace and name of the event to match your definition and the timestamp to an ISO 8601 timestamp (e.g. 2021-10-02T12:00:00Z).
83
83
  5. Click _Execute_ to send the request.
84
84
 
85
85
  **To send an event from your application**
86
86
 
87
87
  1. Get an access token with the event-sender role.
88
88
  ```typescript
89
- const { access_token } = await fetch(`${keycloakRealmTokenUrl}`, {
89
+ const tokenResponse = await fetch(`https://access.alberta.ca/auth/realms/${realm}/protocol/openid-connect/token`, {
90
90
  method: 'POST',
91
91
  headers: {
92
92
  'Content-Type': 'application/x-www-form-urlencoded',
@@ -97,10 +97,11 @@ Once you have an event definition configured, you can use the event service API
97
97
  grant_type: 'client_credentials',
98
98
  }),
99
99
  });
100
+ const { access_token } = await tokenResponse.json();
100
101
  ```
101
102
  2. Send the event via the event service.
102
103
  ```typescript
103
- await fetch(`${eventServiceUrl}`, {
104
+ await fetch('https://event-service.adsp.alberta.ca/event/v1/events', {
104
105
  method: 'POST',
105
106
  headers: {
106
107
  'Content-Type': 'application/json',
@@ -72,7 +72,7 @@ Additional services can be modified to use RabbitMQ for configuration cache inva
72
72
 
73
73
  ## OpenShift configuration
74
74
 
75
- References for configuration in the form of ConfigMaps and Secrets are included in the `/.openshift/configuration` directory. These resources need to be manually created within the environment with configuration values. Other deployment resources are contained in templates under the `/.openshift/managed` directory and are automatically applied by the `deliver-ci` workflow.
75
+ References for configuration in the form of ConfigMaps and Secrets are included in the `/.openshift/configuration` directory. These resources need to be manually created within the environment with configuration values. Other deployment resources are contained in templates under the `/.openshift/managed` directory and are automatically applied by the Delivery CI workflow (`.github/workflows/delivery-ci.yml`).
76
76
 
77
77
  1. Create projects for 'build', 'dev', 'uat', and 'prod' environments in OpenShift.
78
78
  2. Set appropriate values in the ConfigMaps and Secrets and apply to environments.
@@ -12,7 +12,6 @@ ADSP repository is a monorepo using [Nx](https://github.com/nrwl/nx).
12
12
 
13
13
  ```
14
14
  adsp-monorepo
15
- ├── .compose
16
15
  ├── .openshift
17
16
  └── apps
18
17
  ├── api-docs-app
@@ -25,13 +24,13 @@ adsp-monorepo
25
24
  └── tools
26
25
  ```
27
26
 
28
- Specific deployable frontend applications and backend services can be found under the `apps` folder and libraries of common modules can be found under the `libs` folder. The `.compose` and `.openshift` folders contain deployment manifests for docker compose and OpenShift. The `tests` folder contains artillery load test scenarios, the `tools` folder contains workspace templates, and the `docs` folder contains GitHub Pages content including this guide.
27
+ Specific deployable frontend applications and backend services can be found under the `apps` folder and libraries of common modules can be found under the `libs` folder. The `.openshift` folder contains OpenShift deployment manifests. The `tests` folder contains artillery load test scenarios, the `tools` folder contains workspace templates, and the `docs` folder contains GitHub Pages content including this guide.
29
28
 
30
29
  ## Building sub-projects
31
- The monorepo uses a common `package.json` across all sub-projects. Start by installing the dependencies including development dependencies.
30
+ The monorepo uses a common `package.json` across all sub-projects. Start by installing the dependencies, including development dependencies, from the lock file.
32
31
 
33
32
  ```bash
34
- npm i -D
33
+ npm ci
35
34
  ```
36
35
 
37
36
  Build (or run other targets) against specific sub-projects using:
@@ -49,17 +48,3 @@ npx nx affected --target build
49
48
  Backend services make use of the `dotenv` library and local environment can be configured by creating a `.env` file under the sub-project root folder.
50
49
 
51
50
  Frontend applications retrieve configuration as a json document from the server. Locally this can be handled via the webpack development server proxy configuration. Refer to the `proxy.conf.json` file under the sub-project.
52
-
53
- ## Running in Docker compose
54
- Manifests for running the services in docker compose can be found under the `.compose` folder. They are split across multiple files so that a subset of services can be run.
55
-
56
- The backend services use a common base docker container image that includes npm dependencies to streamline local workflow. Build the base service in `.compose/docker-compose.infra.yml` to create this base image.
57
-
58
- ```base
59
- docker-compose build base -f .compose/docker-compose.infra.yml
60
- ```
61
-
62
- Run a set of components using:
63
- ```bash
64
- docker-compose up -f .compose/docker-compose.infra.yml -f .compose/docker-compose.value.yml -f .compose/docker-compose.event.yml
65
- ```
@@ -34,6 +34,7 @@ In order to create the service account.
34
34
  1. Client `urn:ads:platform:tenant-service ` role `platform-service` is required.
35
35
  2. Client `urn:ads:platform:configuration-service` role `configured-service` is needed for registration and accessing service specific configuration
36
36
  3. Client `urn:ads:platform:event-service` role `event-sender` is needed for sending domain events.
37
+ 4. Client `urn:ads:platform:audit-service` role `audit-writer` is needed for recording audit events.
37
38
  4. Additional audiences in the service account access token are required for some capabilities:
38
39
  1. Client `urn:ads:platform:push-service` needs to be include via an audience mapper for socket based configuration cache invalidation.
39
40
 
@@ -346,6 +347,49 @@ Domain events can be sent using the event service.
346
347
  ...
347
348
  ```
348
349
 
350
+ ## Recording audit events
351
+ Audit events can be recorded using the audit service. Define the audit actions of the service in `audit_actions`; the SDK registers them as the service's action catalog on startup. Recording an action that is not in the catalog raises a `ValueError`.
352
+
353
+ `record` is non-blocking: it sends the event in the background, retries transient failures, and returns a `Future` of an `AuditRecordOutcome` (`recorded`, `rejected`, or `failed`). It does not raise for delivery failures. `audit_details_from_request` uses the current request user as the actor and the request tenant as the tenant. Core services must have a tenant for each record. Records without one are rejected with code `invalid_event`.
354
+
355
+ ```python
356
+ from adsp_service_flask_sdk import AuditAction, audit_details_from_request
357
+
358
+ HELLO_WORLD_ACTION = AuditAction(
359
+ "hello-world-requested",
360
+ "security",
361
+ "info",
362
+ description="Recorded when a hello world message is posted to the API.",
363
+ )
364
+
365
+ adsp = extension.init_app(
366
+ app,
367
+ AdspRegistration(
368
+ display_name="My platform service",
369
+ description="Hello world platform service.",
370
+ audit_actions=[HELLO_WORLD_ACTION],
371
+ )
372
+ )
373
+
374
+ # Send records still pending when the process exits.
375
+ atexit.register(adsp.audit_service.flush)
376
+
377
+ @app.route("hello-world/v1/hello")
378
+ @require_user()
379
+ def hello_world() -> str:
380
+ ...
381
+ adsp.audit_service.record(
382
+ HELLO_WORLD_ACTION,
383
+ audit_details_from_request(
384
+ resource={"type": "hello-world-message", "id": message_id},
385
+ metadata={"length": len(message)},
386
+ ),
387
+ )
388
+ ...
389
+ ```
390
+
391
+ Set the `ADSP_AUDIT_ENABLED` configuration value to `false` to disable recording. Records are then returned with a `rejected` outcome and code `disabled`.
392
+
349
393
  ## Additional utilities
350
394
  The SDK provides several other useful utilities.
351
395
 
@@ -23,14 +23,14 @@ npm i @abgov/adsp-service-sdk
23
23
  ```
24
24
 
25
25
  ## Generating service
26
- The ADSP project includes a [workspace generator](https://nx.dev/l/r/generators/workspace-generators) for creating new express based backend services. The base template includes usages of SDK capabilities and is a good starting point for understanding the SDK.
26
+ The ADSP project includes a workspace generator (in `tools/workspace-plugin`) for creating new express based backend services. The base template includes usages of SDK capabilities and is a good starting point for understanding the SDK.
27
27
 
28
28
  Generate a new service by running:
29
29
  ```bash
30
- npx nx workspace-generator adsp-service
30
+ npx nx g workspace-plugin:adsp-service
31
31
  ```
32
32
 
33
- The generate output includes sub-project structure and initial files under `/apps` as well as deployment manifests under `.openshift/managed` and `.compose`.
33
+ The generate output includes sub-project structure and initial files under `/apps` as well as deployment manifests under `.openshift/managed` and `.openshift/configuration`.
34
34
 
35
35
  ## Setting up a service account
36
36
  <!-- tags: [keycloak] -->
@@ -103,7 +103,7 @@ Core requests are used by platform services making requests to other platform se
103
103
 
104
104
  ### Service specific user roles
105
105
  <!-- tags: [keycloak] -->
106
- Keycloak issued tokens contain client roles nested under `realm_access`. Both tenant and core strategies flatten service specific roles from the token and qualifies roles related to other service clients with the client ID..
106
+ Keycloak issued tokens contain realm roles under `realm_access` and client roles nested under `resource_access`. Both tenant and core strategies flatten service specific roles from the token and qualifies roles related to other service clients with the client ID..
107
107
 
108
108
  For example:
109
109
  ```json
@@ -119,6 +119,7 @@ For example:
119
119
  For my-service, the roles are mapped to roles:
120
120
  - user
121
121
  - my-user
122
+ - my-service:my-user
122
123
  - other-service:other-user
123
124
 
124
125
  ## Determining tenancy
@@ -297,7 +298,7 @@ Defining configuration for other platform services:
297
298
  ...sdkCapabilities,
298
299
  } = await initializePlatform({
299
300
  roles: [{
300
- name: 'my-service-admin',
301
+ role: 'my-service-admin',
301
302
  description: 'Administrator role for my-service.',
302
303
  inTenantAdmin: true,
303
304
  }],
@@ -22,23 +22,21 @@ Security-sensitive changes in a tenant realm and failed logins are recorded in t
22
22
 
23
23
  | action | severity | resource type | recorded when |
24
24
  |:-|:-|:-|:-|
25
- | access.user.created | info | user | A user is created. |
26
- | access.user.updated | info | user | A user is updated. |
27
- | access.user.deleted | critical | user | A user is deleted. |
28
- | access.user.role-assigned | warning | user | Client roles are assigned to a user. |
29
- | access.user.role-removed | warning | user | Client roles are removed from a user. |
30
- | access.service-account.created | warning | service-account | A client is created. |
31
- | access.service-account.credential-rotated | critical | service-account | The secret of a client is regenerated. |
32
- | access.service-account.deleted | critical | service-account | A client is deleted. |
33
- | access.realm.configuration-changed | critical | realm | The realm settings, including its event settings, are updated. |
34
- | access.user.login-failed | warning | user, when known | A login attempt fails (`LOGIN_ERROR`). Recorded with `failure` status. |
25
+ | user.created | info | user | A user is created. |
26
+ | user.updated | info | user | A user is updated. |
27
+ | user.deleted | critical | user | A user is deleted. |
28
+ | user.role-assigned | warning | user | Client roles are assigned to a user. |
29
+ | user.role-removed | warning | user | Client roles are removed from a user. |
30
+ | service-account.created | warning | service-account | A client is created. |
31
+ | service-account.credential-rotated | critical | service-account | The secret of a client is regenerated. |
32
+ | service-account.deleted | critical | service-account | A client is deleted. |
33
+ | realm.configuration-changed | critical | realm | The realm settings, including its event settings, are updated. |
34
+ | user.login-failed | warning | user, when known | A login attempt fails (`LOGIN_ERROR`). Recorded with `failure` status. |
35
35
 
36
36
  Every client is recorded as a `service-account` resource, since a deleted client cannot be told apart from other clients. Resources are identified by their Keycloak ID: users are named by username and created clients by client ID when available. Realm resources use the realm ID of the event.
37
37
 
38
38
  The actor of an admin action is the administrator's Keycloak user ID. Its metadata includes `realm`, `operationType`, `resourcePath` and `actorRealm` (the administrator's realm); role changes add the `roles` names and the `clientId` (Keycloak client ID) of the roles. The actor of a failed login is the user. When Keycloak does not know the user, the actor ID is `unknown` and the attempted username, truncated to 255 characters, is the actor name. Its metadata includes `realm`, `clientId` (also truncated to 255 characters) and the Keycloak error as `reason`.
39
39
 
40
- Action names start with `access.` so they do not take generic names such as `user.created` from tenant catalogs. Audit Service rejects a tenant action whose name matches any Core action.
41
-
42
40
  Records never include the Keycloak representation itself, regenerated client secrets, IP addresses, or login details other than the username.
43
41
 
44
42
  ### Prerequisites
@@ -278,18 +278,18 @@ socket.on('session-expired', () => {
278
278
 
279
279
  When the provider reports token usage, the done event also includes `usage`:
280
280
 
281
- | Field | Meaning |
282
- | --------------------- | ---------------------------------------------------------------------------------------------------- |
283
- | `contextTokens` | Input tokens of the agent's last model call: how much of the context window the conversation takes up |
284
- | `contextWindowTokens` | The model's context window, from `AGENT_MODEL_CONTEXT_TOKENS` (default 256,000) |
285
- | `totalTokens` | Every token the reply used across its model calls, including calls tools make, such as form generation |
286
- | `outputTokens` | Tokens the model wrote |
287
- | `modelCalls` | Number of model calls the reply made |
281
+ | Field | Meaning |
282
+ | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
283
+ | `contextTokens` | Input tokens of the agent's last model call: how much of the context window the conversation takes up |
284
+ | `contextWindowTokens` | The model's context window, from `AGENT_MODEL_CONTEXT_TOKENS` (default 256,000) |
285
+ | `totalTokens` | Every token the reply used across its model calls, including calls tools make, such as form generation, and the prompt injection check |
286
+ | `outputTokens` | Tokens the model wrote |
287
+ | `modelCalls` | Number of model calls the reply made |
288
288
 
289
289
  After each reply, a `conversation-status` event says how the conversation stands. `state` is one of:
290
290
 
291
291
  - `ok`: nothing to tell the user.
292
- - `notice`: memory has started keeping the conversation short, which is normal but means early details may be missed. `reason` is `summarised` (observational memory has replaced older messages with notes) or `older-messages-dropped` (an agent without observational memory now reads only its most recent `messageLimit` messages).
292
+ - `notice`: memory has started keeping the conversation short, which is normal but means early details may be missed. `reason` is `summarised` (observational memory has replaced older messages with notes) or `older-messages-dropped` (an agent without observational memory now reads only its most recent `messageLimit` messages). For the Access Service agent, `reason` can also be `long-conversation`: the conversation takes up at least `AGENT_ACCESS_LONG_CONVERSATION_TOKENS` tokens (default 6,000), so a new chat would answer more cheaply.
293
293
  - `warning`: the conversation is close to what the assistant can handle well. `reason` is `near-context-limit` (it takes up at least 70% of the context window) or `notes-condensed` (observational memory has condensed its notes, which takes a very long conversation).
294
294
 
295
295
  ```typescript
@@ -302,6 +302,47 @@ socket.on('conversation-status', ({ threadId, contextTokens, contextWindowTokens
302
302
 
303
303
  Observational memory summarises older messages at `AGENT_OM_MESSAGE_TOKENS` unobserved tokens (default 30,000) and condenses its notes at `AGENT_OM_OBSERVATION_TOKENS` (default 40,000).
304
304
 
305
+ #### Shared token budget
306
+
307
+ Every agent uses the same model key, so the service can hold agents to a token budget for that key. Before a message reaches the model, the service estimates the reply from the agent's recent replies; when the estimate does not fit, the model is not called and the client gets a final stream event (`done: true`) with an error chunk with code `RATE_LIMITED` and a message saying how many seconds to wait. A rate-limit failure (HTTP 429) from the model provider during a reply is sent as an error chunk with the same code.
308
+
309
+ | Variable | Default | Meaning |
310
+ | ----------------------------------- | ------- | ---------------------------------------------------------------------------------------------- |
311
+ | `AGENT_TOKEN_LIMIT_PER_MINUTE` | `0` | Tokens per minute across all agents; `0` is off |
312
+ | `AGENT_TOKEN_LIMIT_PER_5_MINUTES` | `0` | Tokens per 5 minutes across all agents; `0` is off |
313
+ | `AGENT_TOKEN_AGENT_SHARES` | `''` | Share of each limit an agent may use, such as `AccessServiceAgent=0.3,formGenerationAgent=0.5` |
314
+ | `AGENT_USER_TOKEN_LIMIT_PER_MINUTE` | `0` | Tokens per minute for one user; `0` is off |
315
+ | `AGENT_TOKEN_WARN_RATIO` | `0.7` | Share of a limit at which a warning is logged, once each time usage crosses it |
316
+
317
+ Shares are clamped to 0..1, and malformed entries are logged and ignored. Agents without a share, or with a share of 0, are held only to the overall limits. A message holds its estimate against the budget from the moment it is allowed until its reply's usage is known, so messages sent at the same time cannot overshoot a limit; a reply that fails keeps its estimate counted until it leaves the window. Each pod enforces its own budget, so with several pods set the limits to the key's limit divided by the number of pods.
318
+
319
+ ```typescript
320
+ socket.on('stream', ({ chunk }) => {
321
+ if (chunk?.type === 'error' && chunk.payload?.code === 'RATE_LIMITED') {
322
+ console.log(chunk.payload.message); // The AI service is busy right now. Please try again in about 40 seconds.
323
+ }
324
+ });
325
+ ```
326
+
327
+ #### Access Service agent
328
+
329
+ `AccessServiceAgent` answers Access Service and Keycloak questions with read-only live tools and documented guidance. To keep each model call small:
330
+
331
+ - Each call gets only the tools and instruction sections its question needs: environment and realm tools, client and app tools, or people and role tools, picked from the predefined question hint, the question's words (an ADSP ID such as `urn:ads:platform:form-service` brings the client and app tools) and the tools used in the last few messages. A question that matches none gets every tool.
332
+ - How-to and concept questions are answered from the `getAccessGuide` tool, which returns one documented topic. The same topics are available without a model call at `GET /agent/v1/access/guide/:topic`, which returns `{ topic, title, markdown }`; the tenant admin app uses it to answer predefined questions about documented topics.
333
+ - Tool results are shown to the user as cards, so the model gets a compact summary of each result, and results from turns before the previous one are replaced with a short note in later requests (the thread keeps them). After a tool whose card fully answers a request to list or show something, the reply ends without a written answer.
334
+ - It keeps its own short history without observational memory.
335
+
336
+ | Variable | Default | Meaning |
337
+ | --------------------------------------- | ------- | --------------------------------------------------------- |
338
+ | `AGENT_ACCESS_LAST_MESSAGES` | `8` | Messages of the thread the agent reads |
339
+ | `AGENT_ACCESS_MAX_OUTPUT_TOKENS` | `1000` | Longest reply the model may write in one call |
340
+ | `AGENT_ACCESS_LONG_CONVERSATION_TOKENS` | `6000` | Context tokens at which to suggest a new chat; `0` is off |
341
+
342
+ ```bash
343
+ curl -H "Authorization: Bearer $TOKEN" "$AGENT_SERVICE_URL/agent/v1/access/guide/token-expiry"
344
+ ```
345
+
305
346
  ### Delete a thread
306
347
 
307
348
  Delete one of your own threads, with its stored messages, context, and workspace, for example when the user starts a new chat. The response is `{ "deleted": false }` when you have no thread with that ID, so repeating the request is harmless. The thread ID is the `threadId` used on socket.io.