Skip to content

fix(strands): give Strands the worker model's id and context window (breaking) - #158

Merged
campoy merged 3 commits into
mainfrom
fix/strands-typescript-model-context-window-hidden
Oct 28, 2026
Merged

campoy merged 3 commits into
mainfrom
fix/strands-typescript-model-context-window-hidden

Conversation

@campoy

@campoy campoy commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

  • TemporalAgent.initialize() reads the Worker model's modelId and contextWindowLimit through a new strandsGetModelConfig Activity, with the agent's Activity options, before Strands initializes the agent. TemporalModel.getConfig() returns them, so Strands' proactive compression and its agent and model spans see the real values.
  • The Activity returns only those two fields, so provider settings such as API keys stay out of History.
  • New public TemporalModel.loadConfig() runs the read once per model. It returns undefined when the config was already read, and initialize() then returns Strands' own initialize() promise.
  • README: what the agent reads, the compressionThreshold scaling to undo, and the upgrade note below.

Why?

TemporalModel.getConfig() returned {}, so Strands' conversation manager in Workflow code used a 200,000-token window for every model (#157). A model with a larger window lost turns a native agent keeps; a smaller one kept turns it drops.

Breaking change

  • Compression now uses the model's real window. Applications that scaled compressionThreshold by window / 200,000 to work around the missing limit must remove that scaling, or they compress too early. The plugin cannot tell that scaling from a chosen low threshold.
  • Each TemporalAgent schedules one more Activity before its first model call, also agents without compression, because the spans read the model id from the same config.
  • The read has no version gate. A run whose agent ran before this version schedules strandsGetModelConfig on replay where its History has the agent's first command (invokeModel, or an Activity from an InitializedEvent hook), so it fails with [TMPRL1100]. Open runs fail their Workflow Tasks; finished runs fail when they are replayed. Runs that create their first agent after the upgrade, and runs without a TemporalAgent, are not affected.

The commit messages state the breaking change. The PR title says it too, because release notes come from the squash commit subject.

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.

Checklist

  1. Closes [Bug] strands-agents (TypeScript): proactive compression ignores the model's context window #157

  2. How was this tested:

    • New test TemporalAgent gives Strands the worker model id and context window in test-strands.ts. On main it fails on both parts (config {}, and the second model call still carries turn 1). With this change it passes.
    • The reproduction from [Bug] strands-agents (TypeScript): proactive compression ignores the model's context window #157 fails on 1.24.0 and on main, and passes with this change, with the locked @strands-agents/sdk 1.19.0 and with 1.6.0.
    • Replay check against a local dev server, on Workers with a Workflow cache of 0, run on the earlier, gated version of this change and not rerun since:
      • Every main history starts its agent's turn with invokeModel, or with an InitializedEvent hook's Activity, and every history recorded with the read starts it with strandsGetModelConfig. Without the gate, a main history therefore meets the new Activity as its first new command; the check's control, one extra Activity first, fails with [TMPRL1100].
      • No saved history contains the fake model's API key.
    • Local, in a Linux container with Node 24.22.0 and pnpm 10.27.0, on this change: make sync, make lint, make test (34 tests), make build, the npm package check, the smoke install and check_conventions.py pass, and Prettier with the SDK settings reports the files clean. The Node 22, macOS and Windows cells did not run locally.
    • Not run against a real model provider.
  3. Any docs updates needed?
    The plugin README has two new paragraphs. Release notes must carry the compressionThreshold migration note and say that runs whose agents ran before this version, or after it on a rollback, do not replay across the change.

Not covered

  • TemporalModel.countTokens still uses Strands' estimate, not the Worker model's native token count.
  • TemporalModel.stateful is still false. The same Activity could return the Worker model's stateful flag in a later change.
  • A TemporalModel used with a plain Strands Agent does not read the config.
  • The Python plugin has the same gap and needs its own change.
  • Replay of main histories on this change, and of its histories on main, was not rerun after the gate was removed.

Open questions

  • Activity name: strandsGetModelConfig cannot take over a caller's Activity. getModelConfig would match invokeModel, but it is a common name.
  • Should TemporalModel.loadConfig() be public or internal?

`TemporalModel.getConfig()` returned `{}` because the real model lives on
the worker. Strands reads `contextWindowLimit` from it in workflow code for
proactive compression, so every `TemporalAgent` compressed at 70% of the
200,000-token fallback, whatever its model: a model with a larger window
lost turns a native agent keeps, and a smaller one kept turns it drops.
Agent and model spans also had no model id.

`TemporalAgent.initialize()` now reads the worker model's `modelId` and
`contextWindowLimit` through a new `strandsGetModelConfig` activity, with
the agent's activity options, before Strands initializes the agent.
`TemporalModel.getConfig()` returns them. Only these two fields are
returned, so provider settings such as API keys stay out of history.

The read is behind the `strands-agents.model-config` patch. Agents that an
open run initialized before this version keep the empty config, and
`initialize()` returns Strands' own promise without awaiting anything
first, so the run schedules its commands in the same order and replays; agents it creates afterwards read the config. Runs that read
the config cannot be replayed by an earlier version. To roll back, keep
this version and decline the patch with the worker's
`patchActivationCallback`.

Breaking change: each `TemporalAgent` schedules one more activity, and
compression now uses the model's real window. Applications that scaled
`compressionThreshold` by window / 200,000 to work around the missing
limit must remove that scaling, or they compress too early.
Fixes add no version gates for now, so remove the
`strands-agents.model-config` patch. Every `TemporalAgent` now reads the
worker model's config before its first model call, in every run.

Breaking change: the read is a new activity. A run whose agent ran
before this version schedules `strandsGetModelConfig` on replay where
its history has `invokeModel`, and fails with a nondeterminism error.
Let those runs finish before you upgrade, or use Worker Versioning.
@campoy
campoy marked this pull request as ready for review October 28, 2026 21:39
@campoy
campoy requested a review from a team as a code owner October 28, 2026 21:39

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Optional follow-up to round out test coverage across this PR and #194:

  • In #158, add automated checks for credential exclusion, retrying after a failed config read, and the documented replay mismatch with a pre-change history.
  • In #194, add a compression regression like this PR's two-turn test, asserting which messages reach the second model call.

These suggestions are non-blocking and can be handled in a follow-up.

@campoy
campoy merged commit b29bf4d into main Oct 28, 2026
15 checks passed
@campoy
campoy deleted the fix/strands-typescript-model-context-window-hidden branch October 28, 2026 22:06
campoy added a commit that referenced this pull request Oct 28, 2026
Follow-up to #158:

- The test model's config holds an API key, and the workflow sees only
  the model id and context window.
- After a failed config read, the agent's next turn reads it again.
- A history recorded before the read (helloAgent on 73deca0) fails to
  replay with [TMPRL1100], as the README says.
campoy added a commit that referenced this pull request Oct 28, 2026
Follow-up to #194: a two-turn test like #158's. The first reply reports
800 of the model's 1,000 tokens, so proactive compression drops the
first turn before the second model call. Before #194 the plugin used
Strands' 200,000-token fallback and the second call still got turn 1.
campoy added a commit that referenced this pull request Oct 28, 2026
Follow-up to #194: a two-turn test like #158's. The first reply reports
800 of the model's 1,000 tokens, so proactive compression drops the
first turn before the second model call. Before #194 the plugin used
Strands' 200,000-token fallback and the second call still got turn 1.
campoy added a commit that referenced this pull request Nov 16, 2026
npm already has @temporalio/strands-agents 1.24.0 from the SDK repo, so
its next release is 2.0.0, not 1.0.0. The four histories recorded after
#158 move to 2.x/. The one recorded before #158 has 1.24.0's behavior,
so it stays in 1.x/ and no longer replays, and the test that checked it
fails goes away.
campoy added a commit that referenced this pull request Nov 16, 2026
#565)

## What was changed

Replay is promised only within a major version now. A history recorded
on a 1.x release must replay on every later 1.x release, and nothing is
promised from 1.x to 2.x. So why does CI still replay 1.x histories on
code that's heading to 2.0? It shouldn't, and this PR stops it.

- Each plugin's committed histories move into a folder per major,
`histories/<major>.x/`.
- Each replay test gets a `REPLAY_MAJOR` constant (`ReplayMajor` in C#)
and loads only that folder. Older majors' folders stay in the repo, but
they don't replay.
- AGENTS.md gets the rule, next to the one about gating history changes.

A plugin's current major is the major of its next release. Here's what I
used:

| Plugin | Latest release | Current major | Replays | Kept, not replayed
|
| --- | --- | --- | --- | --- |
| `python/openai_agents` | 1.1.0, then `Breaking:` commits | 2 | 4
histories in `2.x/` | 12 in `1.x/` |
| `typescript/openai-agents` | 1.24.0 on npm (published from the SDK
repo), then `Breaking:` commits | 2 | 1 in `2.x/` | 4 in `1.x/` |
| `typescript/vercel-ai-sdk` | 1.0.0, then `Breaking:` commits | 2 |
none | 3 in `1.x/` |
| `python/google_genai` | 1.0.0rc1 | 1 | 1 in `1.x/` | 1 in `0.x/` |
| `typescript/strands-agents` | none from this repo (npm has 1.21.0 to
1.24.0 from the SDK repo); 2.0.0 next | 2 | 4 in `2.x/` | 1 in `1.x/` |
| `typescript/google-adk` | 0.1.0; 1.0.0 next | 1 | 2 re-recorded in
`1.x/` | 2 in `0.x/` |
| `python/google_adk` | 0.0.1; 1.0.0 next | 1 | none | 7 in `0.x/` |
| `python/strands_agents` | 0.1.0; 1.0.0 next | 1 | 4 in `1.x/` | 5 in
`0.x/` |
| `python/deepagents` | 0.0.3; 1.0.0 next | 1 | none | 3 in `0.x/` |
| `java/google-adk`, `dotnet/microsoft-agent-framework`,
`python/microsoft_agent_framework` | below 1.0, not 1.0 next | 0 | all,
in `0.x/` | none |

A history recorded on `main` before a breaking fix goes with the release
whose behavior it recorded. So the five OpenAI Agents Python histories
from before #204, #373 and #426, and the four TypeScript ones from
before #373, are 1.x histories. Strands Python's four MCP histories were
recorded after #190 moved its MCP Activities to `temporalio-mcp`, code
that 0.1.0 never had, so they're 1.x histories too. Strands TypeScript's
`hello-agent-before-model-config` was recorded before #158, so it has
1.24.0's behavior and is a 1.x history. Its other four were recorded
after #158, so they're 2.x.

Tests that replayed only older-major histories go: Vercel AI SDK's three
committed-history tests, Google GenAI's `legacy_ascii_files` replay,
Google ADK Python's two replay tests with their workflows, Strands
Python's `test_legacy_history_replay.py` and
`test_model_context_overflow_legacy_replay.py`, Deep Agents'
`test_legacy_cache_replay.py`, and Strands TypeScript's test that its
history from before #158 fails to replay. The OpenAI Agents lists keep
only the current major's files. Google ADK TypeScript's replay test
checks a live run against a checked-in fixture, so I recorded its two
fixtures again into `1.x/` with its own `UPDATE_ADK_HISTORIES=1`.

`go/googleadk` doesn't change: it has no committed histories, and its
replayer tests replay runs the same test just recorded.

## Why?

We decided that replay is promised only within a major. But CI still
replayed 1.x histories, so a fix for 2.0 had to keep 1.x runs replaying
behind a patch, even though we don't promise that. With this PR, the
next one can remove those patches from OpenAI Agents Python before 2.0.0
ships.

## Checklist

1. No issue.

2. How was this tested:
- Python, for each of the six plugins: `make sync`, `make format`, `make
lint`, and the tests that read committed histories (3, 7, 43, 11, 4 and
42 passed).
- TypeScript, for each of the four plugins, in Docker with Node 24:
`make sync`, `make lint`, and the test files that read committed
histories.
- `check_conventions.py` passes, and `detect_changes.py` selects the 12
plugins.
- After moving the 1.0-next plugins to major 1: Google ADK Python `make
format`, `make lint` and `make test` (321 passed, 6 skipped); Google ADK
and Strands TypeScript `make lint` and their replay tests, in Docker
with Node 24.
- After moving Strands Python and Deep Agents to major 1 and merging
`main`: `make lint` and `make test` for both (277 and 261 passed).
- After moving Strands TypeScript to major 2: `make lint` and its two
replay test files, in Docker with Node 24 (8 passed).
- Java and .NET didn't run locally (no JDK or .NET SDK on this machine).
CI runs them.

3. Any docs updates needed? AGENTS.md has the rule. The Microsoft Agent
Framework Python histories README says where recordings go now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] strands-agents (TypeScript): proactive compression ignores the model's context window

2 participants