Repository navigation
Breaking: give TemporalAgent the worker model's context window and model id - #194
Merged
Merged
Conversation
…del id
TemporalModel.get_config() returned {}, so Strands code that runs in the
workflow could not see the worker model's settings. Proactive compression
and context_manager="auto" divided by the 200,000-token fallback for every
model, so an agent on a larger model dropped turns a native agent keeps,
and on a smaller one kept turns a native agent drops. Strands' agent and
model spans had no gen_ai.request.model.
Before its first invocation, TemporalAgent now reads the worker model's
model_id and context_window_limit with a new strands_get_model_config
activity, using the agent's activity options. TemporalModel.get_config()
and a new config property return them. Only those two fields go to
History.
Breaking change: proactive compression now uses the model's own window.
Code that scaled compression_threshold by window / 200,000 to work around
the old limit must remove that scaling, or it compresses too early. Every
TemporalAgent run schedules one more activity before its first model call,
and workers that run the model activities must have this version.
Runs whose agents first ran before this change keep an empty config and
schedule no new activity (patch "strands-model-config"); code without
this patch cannot replay runs that recorded it.
Move the strands_get_model_config read inside Strands' invocation guard, after the idempotency token is registered and before the agent span starts, so Strands still rejects, deduplicates or aborts overlapping invocations as it does natively, including when the first is cancelled during the read. Callers that do overlap (reentrant mode, or a call after a cancelled first one) share one read; a failed read is retried by the next invocation.
This was referenced Oct 26, 2026
Closed
Fixes add no version gates for now, so remove the `strands-model-config` patch. Every `TemporalAgent` now reads the worker model's config before its first invocation, in every run. Breaking change: the read is a new activity. A run whose agent ran before this version schedules `strands_get_model_config` on replay where its history has `invoke_model`, and fails with a nondeterminism error. Let those runs finish before you upgrade, or use Worker Versioning. The checked-in history of an agent turn recorded on 5e91c26, which tested the old path of the overflow translation, fails that way, so its test and fixture go. The other legacy history has no agent turn and still replays.
campoy
marked this pull request as ready for review
October 28, 2026 21:00
Contributor
Author
|
Ready for review, @brianstrauch |
brianstrauch
approved these changes
Oct 28, 2026
This was referenced Oct 30, 2026
campoy
added a commit
that referenced
this pull request
Nov 17, 2026
…gate before 1.0 (#575) ## What was changed Strands Python ships 1.0 next, so its current major is 1, and replay is promised only within a major (the rule #565 adds to AGENTS.md). The `strands-agents.context-window-overflow-recovery` patch from #146 only keeps runs without its marker on the old path. Those are 0.x runs, so let's remove it before 1.0. A model Activity that fails with a context window overflow now always raises `ContextWindowOverflowException` in the Workflow, so Strands reduces the conversation and calls the model again. The overflow test no longer checks for the marker. This PR doesn't need #565: no committed history reaches this gate. ## What will you notice? (Breaking) A 0.x run whose Workflow got a model overflow as an `ActivityError` fails replay on 1.0 with `[TMPRL1100]`. In practice that adds nothing new: every 0.x agent run already fails replay on 1.0, at the model config read from #194 (`invoke_model` where 1.0 schedules `strands_get_model_config`). A run on a `main` build since #146 that hit an overflow recorded the marker, so it doesn't replay either. No release wrote that marker. It breaks the other way too. A run that hits an overflow on this version doesn't record the marker, so it fails replay with `[TMPRL1100]` on a `main` build that has the gate. Runs that never hit an overflow replay on both. ### What should you do? The README now says this next to the other upgrade notes: - Let runs that hit an overflow before you upgrade finish on their original workers, or keep them there with Worker Versioning. - Don't roll workers back to an earlier version while runs that hit an overflow on this version are open. Use Worker Versioning if you need to roll back. - Runs that never hit an overflow need nothing new. ## Why? We decided that replay is promised only within a major, and that a gate that only protects an older major's runs is removed before the next major ships. Strands' next release is 1.0, so this gate goes before it. ## Checklist 1. No issue. 2. How was this tested: - `make format`, `make lint` and `make test` for `python/strands_agents` on Python 3.12: 282 passed, 1 skipped. After the README change, `make sync`, `make lint` and `make test` on Python 3.13: 282 passed, 1 skipped. - Replay, across builds. On Workers with no Workflow cache, I recorded a run that recovers from an overflow, a run whose model always overflows inside a Workflow that catches `ActivityError` and runs a fallback Activity, and a plain run. I recorded them on `main` and on this PR. On `main` I also recorded both overflow runs with `workflow.patched()` returning `False` for this gate, which is what a Workflow without the gate (0.x) does. Then I replayed every one on both builds, along with #146's fallback history (recorded on 0.1.0's code) and a history with a renamed Activity. - On this PR, only these fail, each with `[TMPRL1100]`: the two old-path runs, the two overflow runs from `main` (`Non-deprecated patch marker encountered`), #146's 0.x history (at the model config read, as on `main`), and the renamed Activity. Everything recorded on this PR replays, and so does the plain run from `main`. - Rollback to `main`: this PR's two overflow histories fail with `[TMPRL1100]`; the plain one replays. 3. Any docs updates needed? Yes, and they're in this PR. The Strands README now says what happens to runs that hit an overflow, and how to upgrade and roll back with them open.
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.
What was changed
TemporalAgentnow gives Strands the worker model'smodel_idandcontext_window_limitinWorkflow code. Before,
TemporalModel.get_config()returned{}, so proactive compression andcontext_manager="auto"divided by Strands' 200,000-token fallback for every model, and Strands'spans had no
gen_ai.request.model.strands_get_model_configonModelActivity. It returns only the model'smodel_idandcontext_window_limit. Nothing else from the provider config reaches History,since a config can hold credentials or clients.
TemporalAgentreads them once per agent, with the agent's Activity options, in an override ofStrands'
Agent._convert_prompt_to_messages.stream_asyncawaits that method after it takesthe invocation lock and registers the idempotency token, and before it starts the agent span.
So Strands still rejects, deduplicates or aborts overlapping invocations as it does natively,
also when the first one is cancelled during the read.
TemporalModel.get_config()and a newconfigproperty, which Strands' tracing reads, returnthem. Callers that overlap the read share it; a failed read is retried by the next invocation.
workflow.wait_condition, keeping Strands' token and lockbookkeeping. Its
asyncio.wrap_futurepath calls methods the Workflow loop does not implementon Python before 3.13 and leaves the duplicate waiting forever.
tests/test_model.py. Existing Activity lists include the config read.The pre-bytes histories now assert the documented replay mismatch at the config read.
test_model_context_overflow_legacy_replay.pyloses the test that replays an agent turn recordedbefore Let Strands recover from model context window overflow in TemporalAgent #146, with its fixture: that history fails on the new Activity (see below). The file's
other test, whose history has no agent turn, stays.
Breaking change: proactive compression now uses the model's own window. Code that scaled
compression_thresholdby window / 200,000 to work around the old behavior must remove thatscaling, or it compresses too early. Every agent run schedules one more Activity before its first
model call, and Workers that run the model Activities need this version. The title starts with
Breaking:because release notes come from commit subjects.The read has no version gate. A run whose agent ran before this version schedules
strands_get_model_configon replay where its History hasinvoke_model, and fails with[TMPRL1100]. Open runs fail their Workflow Tasks; finished runs fail when they are replayed. Runswithout a
TemporalAgentare not affected.Upgrade: let runs whose agents already ran finish on the earlier version before you upgrade, or
keep them there with Worker Versioning. The same applies to rolling back: an earlier version does not
read the config, so runs that read it are not expected to replay there.
Why?
See #193.
Checklist
Closes [Bug] strands_agents: TemporalAgent hides the worker model's context window and model id from Strands #193
How was this tested:
test_model_config_reaches_workflowintests/test_model.pyruns a Workflow on a model whoseconfig has a
model_id, acontext_window_limitand an API key. It checks that Workflow codegets only the first two; that two overlapping first invocations end as natively (the second
raises
ConcurrencyException); that successful duplicates share one model call and result;that a duplicate of a first invocation cancelled during the read is aborted
(
IdempotencyAbortedError) and never runs its prompt; the Activity list; and replay. It fails onmainand passes with the change.make lintand the full suite pass locally (132 tests, Python 3.12.13). The extended modeltest also passes with successful and aborted duplicates and replay. Local uv 0.11.21 is
outside the plugin's required range, so these targets used a temporary uv config with the
same dependency settings and no version check. CI uses the required uv version.
mainand none with the change: the agent keeps anddrops turns as the native agent does, with no fallback warning.
idempotency token and with a delayed, failed or cancelled read, end as on a native agent, with
one config read per successful load.
test_model_context_overflow_legacy_replay.pyfails on this change with
[TMPRL1100] ... scheduled event 'invoke_model' does not match ... 'strands_get_model_config'. A replay check on a Worker against a dev server, run on theearlier, gated version of this change and not rerun since, recorded
mainhistories that startwith
invoke_model; its control, an extra first Activity, fails with[TMPRL1100].Any docs updates needed?
The README section on model selection now says what the agent reads, how to upgrade, and how to
migrate a scaled
compression_threshold.Not covered:
TemporalModel, so a Bedrock model'suse_native_token_countis not used.context_manager="auto"or"agentic", exportedspans, a mixed rollout with old and new Workers on one Task Queue, and replay of this change's
histories on
main.strands-agents.context-window-overflow-recoverypatch keeps an old path that aTemporalAgentno longer reaches in histories recorded before Let Strands recover from model context window overflow in TemporalAgent #146, since they fail on the newActivity first. Deprecating that patch is a separate change.
temporalio1.34.x still bundles the old code astemporalio.contrib.strands. No backport here.Open questions:
strands_get_model_config(the TypeScript fix in fix(strands): give Strands the worker model's id and context window (breaking) #158 usesstrandsGetModelConfig), or a plainget_model_config, likeinvoke_model?reads the model id too. Is one more Activity per agent run acceptable?
Agent._convert_prompt_to_messages, the only await insidethe invocation guard before the agent span. Is that acceptable, or should Strands get a public
hook there?
Draft while these questions are open.