You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c25ba35
Browse filesBrowse the repository at this point in the historyBrowse files
The app listens on port 8086 (`rest.server.port` in `resources/application.yml`). Map its routes
27
36
from the engine's `event-over-http.yaml`, as the Java and Rust MiniGraph Playgrounds do:
28
37
@@ -45,7 +54,7 @@ token batches as they are produced.
45
54
| `prompt` or `messages` | A single user turn, or conversation turns `[{role: user\|assistant, content}]`. `messages` wins when both are given. Content is plain text. |
46
55
| `system` | Optional system prompt (text). |
47
56
| `schema` | `llm.chat` only. A JSON schema; the reply is then structured output, returned parsed as `data`. `additionalProperties` defaults to `false`. A schema on `llm.stream` is a 400. |
48
-
| `params.model` | The model. Default `claude-opus-5-5` (`llm.model`). |
57
+
| `params.model` | The model. Default `claude-opus-5-5` (`llm.model`). On Bedrock a bare id is sent with the `anthropic.` prefix; an id already spelled for Bedrock is sent as written. |
| `params.timeout_ms` | `llm.chat`: a deadline for the whole call, SDK retries included. `llm.stream`: the idle allowance between events. Default 60000 (`llm.timeout.ms`). |
51
60
| `params.effort` | `low`, `medium`, `high`, `xhigh` or `max`. Sent only when set; otherwise the model's own default applies. A model that takes no effort parameter answers 400. |
@@ -93,7 +102,7 @@ the envelope into a graph's error context or an HTTP edge.
93
102
| 408 | The deadline or the SDK's timeout | `LLM request timed out after {n} ms` |
94
103
| 422 | The reply carries nothing usable | `LLM refused the request …`, `LLM reply is empty …`, `LLM reply is not valid JSON for the requested schema …` |
| 503 | No credential, or the API is unreachable | `LLM provider credential missing - set ANTHROPIC_API_KEY in the environment`, `LLM provider unreachable - …` |
105
+
| 503 | No credential, no region, or the API is unreachable | `LLM provider credential missing - set ANTHROPIC_API_KEY in the environment`, `AWS credential missing - …`, `AWS region missing - …`, `LLM provider unreachable - …` |
97
106
98
107
**A reply that carries nothing usable is an error, never an empty success.** A refusal with no
99
108
text, an empty reply, or a structured reply cut off before it is valid JSON is a 422 that says why
@@ -110,20 +119,22 @@ the 422 above, not an empty stream. Raise `params.max_tokens` or lower `params.e
110
119
111
120
| Key | Default | Meaning |
112
121
|---|---|---|
113
-
| `llm.backend` | `anthropic` | The route to the models; see Backends. |
122
+
| `llm.backend` | `anthropic` | The route to the models: `anthropic`(the Claude API) or `bedrock` (AWS Bedrock); see Backends. |
123
+
| `llm.aws.region` | unset | The AWS region a Bedrock call is signed for. Unset, the SDK reads `AWS_REGION` / `AWS_DEFAULT_REGION`. |
114
124
| `llm.model` | `claude-opus-5-5` | The default model. |
115
125
| `llm.max.tokens` | `16000` | The default output cap. |
116
126
| `llm.timeout.ms` | `60000` | The default deadline (chat) or idle allowance (stream). |
117
127
| `llm.max.retries` | `2` | SDK retries for connection errors, 408, 409, 429 and 5xx. |
118
-
| `llm.fallbacks` | `default` | `default` or `off`. Server-side refusal fallbacks (`fallbacks: "default"`) on the models that support them (the Opus 5, Fable 5 and Sonnet 5.5 families). The reply's `model` names the model that answered. |
128
+
| `llm.fallbacks` | `default` | `default` or `off`. Server-side refusal fallbacks (`fallbacks: "default"`) on the models that support them (the Opus 5, Fable 5 and Sonnet 5.5 families). The reply's `model` names the model that answered. The Claude API only: Bedrock offers none, so the switch has no effect there. |
119
129
| `llm.effort` | unset | The default effort. |
120
130
| `llm.log.batches` | `false` | Log each streamed batch's number, size and arrival time (never its text). |
121
131
| `llm.provider` | `anthropic` | Only `anthropic`; any other value is a 400. |
122
132
123
133
The credential is never configured here. `ANTHROPIC_API_KEY` (or whatever the SDK resolves: an
124
-
auth token, or a profile) comes from the environment. `llm.health` reports whether a call could
125
-
be sent (a credential is present) with no network traffic, so a health probe never spends a token.
126
-
`/health`includes it through `mandatory.health.dependencies`.
134
+
auth token, or a profile) comes from the environment for the Claude API; the AWS credential chain,
135
+
or a Bedrock API key in `AWS_BEARER_TOKEN_BEDROCK`, for Bedrock. `llm.health` reports whether a call
136
+
could be sent (a credential is present) without reaching the model, so a health probe never spends a
137
+
token. `/health` includes it through `mandatory.health.dependencies`.
`get_backend()`builds the one client the app uses, and a `Backend` says what that route to the
151
-
models supports. Today there is one, `anthropic` (the Claude API).
152
-
153
-
**Planned: AWS Bedrock through IAM.** It is additive. Build the SDK's Bedrock client in
154
-
`get_backend()`(it authenticates with the AWS credentials of the default chain instead of an API
155
-
key, and takes a region), give the `Backend` a `provider_model` that prefixes the model id (`anthropic.claude-opus-5-5`),
156
-
report `supports_fallbacks=False` (server-side fallbacks are not offered on Bedrock), and describe a
157
-
missing AWS credential in `credential_problem()`. Select it with `llm.backend: 'bedrock'`. The routes,
158
-
the contract and the vector file stay as they are, because nothing outside `Backend` knows which
159
-
route answered.
162
+
models supports: how it spells a model id, whether server-side fallbacks exist, and what a missing
163
+
credential looks like. Nothing else in the module knows which route answered, so the routes, the
164
+
contract and the vector file are the same on every backend.
165
+
166
+
| `llm.backend` | Client | Credential | Model id | Server-side fallbacks |
167
+
|---|---|---|---|---|
168
+
| `anthropic` (default) | the Claude API, `AsyncAnthropic` | `ANTHROPIC_API_KEY`, or whatever the SDK resolves | as written | on the models that support them |
169
+
| `bedrock` | AWS Bedrock, the SDK's `AsyncAnthropicBedrockMantle` | the AWS credential chain through IAM (`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`, a profile, a role), or a Bedrock API key in `AWS_BEARER_TOKEN_BEDROCK` | a bare id gets the `anthropic.` prefix; an id already spelled for Bedrock is sent as written | none - the request never carries them |
170
+
171
+
**AWS Bedrock.** Install the extra (`pip install 'mercury-composable[llm,bedrock]'` - it adds boto3,
172
+
which signs each call), set `llm.backend: 'bedrock'` and a region (`llm.aws.region`, or `AWS_REGION`
173
+
in the environment; without one the helper answers `503 AWS region missing` instead of starting a
174
+
call), and give the process AWS credentials the way any AWS client gets them. The model must be
175
+
enabled for the account in that region. `llm.health` reports `region` beside `backend` and `model`,
176
+
and its health check resolves the credential chain the way a call would - on an EC2 or ECS host that
177
+
includes the instance metadata service - so a probe tells a missing credential from a present one
178
+
without spending a token; a call whose chain turns out empty is a `503 AWS credential missing`.
179
+
Effort, structured output and streaming work as on the Claude API. The SDK's client-side refusal
180
+
fallback middleware is not wired in; a refusal on Bedrock is the 422 or the `stop_details` of the
181
+
contract, like a refusal on the Claude API with `llm.fallbacks: off`.
160
182
161
183
## What it does not do
162
184
@@ -167,10 +189,11 @@ deliberate: the helper is the bounded AI node of a graph, not an agent runtime.
167
189
## Tests
168
190
169
191
`tests/test_llm_helper.py`runs the shared `tests/vectors/llm-helper-vectors.json` against a fake of
170
-
the SDK (63 cases: request validation, the exact SDK call, replies, the error contract, streaming),
171
-
plus the tests a vector cannot express (token batches are never held back, no prompt text in a
172
-
log, the deadline cancels the call, trace annotations, health, the backend seam). No token is
173
-
spent and no credential is needed.
192
+
the SDK (66 cases: request validation, the exact SDK call, replies, the error contract, streaming,
193
+
the shape of a Bedrock call), plus the tests a vector cannot express (token batches are never held
194
+
back, no prompt text in a log, the deadline cancels the call, trace annotations, health, the backend
195
+
seam, the Bedrock client with its region and credential checks). No token is spent and no credential
0 commit comments