Repository navigation
feat(extensions): let llm() call a model through a transport - #1004
Merged
Merged
Conversation
llm(transport=...) sends each ask request through the caller's own function, for a model that is not on Amazon Bedrock. The function gets an LlmRequest with the built system prompt, the user message with the input in <input> tags, and max_tokens, and returns an LlmReply with the text and a stop reason. ask maps the stop reason the same way for Bedrock and a transport: "end" returns the text, "max_tokens" raises LlmMaxTokensError, anything else raises LlmStoppedError. The Bedrock path now returns the same reply shape, so a later built-in transport needs no change to llm(). destination and transport cannot be combined. This matches the JavaScript SDK.
- Handle a missing stop reason once, in _answer, for Bedrock and a transport: stop_reason stays None and the message says there is none. - Keep the raw Bedrock stop reason. Only end_turn and stop_sequence are complete on Bedrock, and only "end" from a transport, so a raw "end" from Bedrock still fails as on main. - Raise TypeError for max_tokens without transport, as the JavaScript SDK does. - Pass a BedrockConfig on the transport path, so Llm needs no unused default. - Describe LlmStoppedError.stop_reason for both sources.
This comment has been minimized.
This comment has been minimized.
yaythomas
requested changes
Dec 1, 2026
llm() now has one code path: every request goes through a transport. bedrock_transport(BedrockConfig(...)) is the default transport. - llm(transport=None, *, max_tokens=1024, retry_strategy=None). - ask() takes max_tokens= per call. BedrockCallOptions is removed. - BedrockConfig no longer has max_tokens. - bedrock_transport maps Converse end_turn and stop_sequence to "end".
This comment has been minimized.
This comment has been minimized.
A custom transport needs no Bedrock permission.
This comment has been minimized.
This comment has been minimized.
A transport must map its host token-limit reason, such as length, to "max_tokens", so ask raises LlmMaxTokensError.
ParidelPooya
had a problem deploying
to
ai-pr-review-runtime
December 1, 2026 18:29 — with
GitHub Actions
Error
The custom transport example now maps length to "max_tokens", as the rule under it says.
This comment has been minimized.
This comment has been minimized.
Contributor
Codex AI reviewThree approach findings remain:
No SDK correctness regression confirmed. Static review only; tests were not executed. Reviewed commit |
yaythomas
approved these changes
Dec 1, 2026
ParidelPooya
added a commit
to aws/aws-durable-execution-sdk-js
that referenced
this pull request
Dec 2, 2026
## Why
`llm()` only calls Amazon Bedrock. Other hosts can run a large language
model too: SageMaker endpoints, vLLM or TGI on EKS or ECS, and services
outside AWS. They do not share one request format, so each needs its own
call. A `transport` option, like the one `decider()` has, lets a caller
reach any of them now, and lets later built-in transports land without
changing `llm()`.
## What changes
- `llm({ transport?, maxTokens?, retryStrategy? })` sends every `ask`
request through a transport: `(request, { abortSignal }) => Promise<{
text, stopReason }>`.
- `bedrockTransport(config?)` is the Bedrock transport, and the default.
It takes the former Bedrock settings: `modelId`, `client`,
`temperature`, `system`, `guardrail`.
- The request holds the built `system` prompt, the `prompt` (question,
and the input inside `<input>` tags with every `</input` escaped), and
`maxTokens`. So a transport does not repeat the prompt-injection
handling.
- `ask` treats only `stopReason: "end"` as complete. `"max_tokens"` is
`LlmMaxTokensError`. Any other reason is `LlmStoppedError`, and the text
is not checkpointed. `bedrockTransport` maps Converse `end_turn` and
`stop_sequence` to `"end"` and passes other reasons through.
- `maxTokens` in `llm()` sets the reply limit (default 1024). `ask(...,
{ name, maxTokens })` changes it for one call.
- Removed, since the API has not launched: the `destination: { bedrock
}` option, the per-call `bedrock` override, and
`BedrockConfig.maxTokens`.
- New exports: `bedrockTransport`, `LlmTransport`, `LlmRequest`,
`LlmReply`.
- `docs/ai.md`, the README, and a new example (`llm-custom-transport`)
describe the option.
No built-in OpenAI or SageMaker transport in this PR.
## Testing
- `npm test` in the extensions package: 652 passed, 1 skipped. `tsc
--noEmit`, `biome check` and the build pass.
- Examples package: the `ai` examples pass vitest, eslint and `tsc
--noEmit`.
- Tests cover: the built prompt and abort signal reach the transport,
`maxTokens` from `llm()` and from the call, stop reasons map to the
errors, a transport error fails the attempt, replay does not call the
transport again, `bedrockTransport` maps stop reasons, `llm()` without a
transport calls Bedrock, and a custom transport works without the
Bedrock package.
- Not run against a live model.
### Edited test expectations
Each one changed because its option was removed.
| Test on main | Now | Why |
|---|---|---|
| "applies per-call overrides, a custom step name, and the system
suffix" | "applies the transport settings, a per-call maxTokens, a
custom step name, and the system suffix" | The per-call `bedrock`
override is removed. Only `maxTokens` stays per call. |
| "uses the default model when the config sets no modelId" | "uses the
default model when the transport sets no modelId" | `modelId` moved to
`bedrockTransport()`. |
| "keeps a config value when a per-call override is undefined" | "uses
the config's maxTokens when the call sets none" | Same reason. |
| "rejects a destination that is not valid", "rejects a single
unsupported destination when the factory runs" | Removed | `destination`
is removed. |
The Python SDK gets the same change in
aws/aws-durable-execution-sdk-python#1004.
## Design note
1. **Problem.** `llm()` can only call a model on Amazon Bedrock. A
durable function whose model runs on a SageMaker endpoint, on vLLM or
TGI in EKS or ECS, or outside AWS cannot use `ask`.
2. **Cause.** `ask` builds the prompt, calls Converse, and checks the
stop reason in one Bedrock-only method. There is no point where a caller
can swap the call.
3. **Options considered.**
1. *Add `transport` next to `destination`:* two code paths and a config
union. Rejected: it keeps a Bedrock-only branch and a per-call override
that a generic transport cannot use.
2. *More `destination` keys* (`openai`, `sagemaker`): each host needs
its own call and format, so `llm()` gains a branch per host.
3. *Built-in transports now:* no host other than Bedrock has been tested
live.
4. *Make Bedrock one transport and give `llm()` only `transport`:*
chosen.
4. **Chosen option and reason.** Option 4 has one code path. `llm()`
builds the prompt, calls the transport, and checks the stop reason.
Bedrock is just the default transport. A later built-in transport is one
more function, with no change to `llm()`.
5. **What the change removes or merges.** The Bedrock-only `ask` method,
the `destination` option, and the per-call `bedrock` override are
removed. Prompt building and the stop-reason check move into `llm()`,
shared by every transport.
**Decisions the task did not cover** (for a maintainer to accept or
reject):
- This changes the experimental `llm()` signature. It has not launched,
so callers in this repo are updated and no CHANGELOG entry is added.
- The per-call override is now only `maxTokens`. Another model means
another `llm()` with its own transport.
- On Bedrock, a reply with no stop reason gives `"missing"`, as on main.
- `bedrockTransport` maps only `end_turn` and `stop_sequence` to
`"end"`, and passes other reasons through. Converse never sends `"end"`
itself: it is not in the Converse `StopReason` enum. So no guard is
added for a raw `"end"`.
**Unverified:** no live model was called through a custom transport.
**Maintainer agreement:** @ParidelPooya agreed to this note on
2026-12-01, per CONTRIBUTING "Write a design note before the code".
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
llm()only calls Amazon Bedrock. Other hosts can run a large language model too: SageMaker endpoints, vLLM or TGI on EKS or ECS, and services outside AWS. They do not share one request format, so each needs its own call. Atransportargument, like the onedecider()has, lets a caller reach any of them now, and lets later built-in transports land without changingllm().The JavaScript SDK gets the same change in aws/aws-durable-execution-sdk-js#1311.
What changes
llm(transport=None, *, max_tokens=1024, retry_strategy=None)sends everyaskrequest through a transport:Callable[[LlmRequest], LlmReply].bedrock_transport(config=None)is the Bedrock transport, and the default.BedrockConfigkeepsmodel_id,client,temperature,system, andguardrail.LlmRequestholds the builtsystemprompt, theprompt(question, and the input inside<input>tags with every</inputescaped), andmax_tokens. So a transport does not repeat the prompt-injection handling.asktreats onlystop_reason="end"as complete."max_tokens"raisesLlmMaxTokensError. Any other reason, orNone, raisesLlmStoppedError, and the text is not checkpointed.bedrock_transportmaps Converseend_turnandstop_sequenceto"end"and passes other reasons through.max_tokens=onllm()sets the reply limit.ask(..., max_tokens=)changes it for one call.BedrockConfigdestination argument ofllm(),BedrockCallOptions, andBedrockConfig.max_tokens.bedrock_transport,LlmTransport,LlmRequest,LlmReply.docs/ai.mdand the README describe the option, with an example.No built-in OpenAI or SageMaker transport in this PR.
Testing
hatch run test:all packages/aws-durable-execution-sdk-python-extensions/tests/ai: 114 passed.hatch run types:check,ruff check, andruff formatpass.max_tokensfromllm()and from the call, stop reasons map to the errors, a transport error fails the step, replay does not call the transport again,bedrock_transportmaps stop reasons and matches the boto3 request shape, andllm()without a transport calls Bedrock.tests/e2e/suite: the extensions package has none. Thetests/ai/tests run each handler throughDurableFunctionTestRunner, including replay, which is the same harness that the other packages' e2e tests use.Edited test expectations
Each one changed because its option was removed.
test_ask_uses_the_config_and_the_call_overridestest_ask_uses_the_bedrock_config_and_the_call_max_tokensBedrockCallOptionsoverride is removed. The second call now uses the configured model, with onlymax_tokensset per call.test_destination_must_be_a_bedrock_configBedrockConfigdestination argument is removed.test_matches_the_boto3_request_shapebedrock_transport(config)and expectsLlmReply(text="ok", stop_reason="end")Llm._converseis removed. The transport returns anLlmReply.Design note
llm()can only call a model on Amazon Bedrock. A durable function whose model runs on a SageMaker endpoint, on vLLM or TGI in EKS or ECS, or outside AWS cannot useask.askbuilds the prompt, calls Converse, and checks the stop reason in one Bedrock-only method (Llm._converse). There is no point where a caller can swap the call.transportnext to theBedrockConfigdestination: two code paths. Rejected: it keeps a Bedrock-only branch and a per-call override that a generic transport cannot use.llm()gains a branch per host.llm()onlytransport: chosen.askbuilds the prompt, calls the transport, and checks the stop reason. Bedrock is just the default transport. A later built-in transport is one more function, with no change tollm().Llm._converse, the destination argument, andBedrockCallOptionsare removed. Prompt building and the stop-reason check stay inask, shared by every transport.Decisions the task did not cover (for a maintainer to accept or reject):
llm()signature. It has not launched, so callers in this repo are updated and no breaking-change note is added.max_tokens. Another model means anotherllm()with its own transport.bedrock_transportmaps onlyend_turnandstop_sequenceto"end", and passes other reasons through. Converse never sends"end"itself: it is not in the ConverseStopReasonenum. So no guard is added for a raw"end".DeciderTransport. No Python ai examples exist yet, so this PR adds none.Unverified: no live model was called through a custom transport.
Maintainer agreement: @ParidelPooya agreed to this note on 2026-12-01, per CONTRIBUTING "Write a design note before the code".