Repository navigation
Breaking: refuse RunConfig.model_provider in OpenAI Agents workflows - #204
Conversation
Model calls run in an Activity on the Worker's provider, so a provider set with `RunConfig(model_provider=...)` in Workflow code was silently ignored: the run's requests, with its prompt, went to the Worker's provider with the Worker's key, and the run completed. `Runner.run` and `Runner.run_streamed` in a Workflow now raise `ValueError` when `RunConfig.model_provider` is anything other than an unconfigured `MultiProvider`, as they already do for a model object on the agent. Breaking change: a Workflow that passes `RunConfig(model_provider=...)` now fails its Workflow Task. Set providers on the Worker instead, with `OpenAIAgentsPlugin(model_provider=...)` (for several providers, a `MultiProvider` with a prefix map), and choose one by model name. The check is behind the `openai_agents.refuse-run-model-provider` patch: runs that started on an earlier version keep using the Worker's provider and still replay. A run that records the patch marker cannot be replayed by an earlier version.
OpenAIProvider fills its client cache on first use, so an unconfigured MultiProvider that a native run had used looked configured and was refused in a Workflow. Ignore that cache when no client was passed. Also say in the README that a run started on an earlier version keeps the old behavior only for a run provider it already passed before the upgrade.
…hon-run-model-provider-ignored
|
This is an LGTM for me now @brianstrauch, could you also have a look? |
brianstrauch
left a comment
There was a problem hiding this comment.
A worker-side MultiProvider, configured through OpenAIAgentsPlugin(model_provider=...) with a prefix map, already lets workflows choose between providers using model-name prefixes. That covers the multiple-provider use case affected by this validation, so we don't need another provider registry to address it. A clear error for an unsupported per-run provider is appropriate: silently ignoring it can send prompts to a different provider and account than the caller intended.
The patch gate preserves replay compatibility for older histories. make lint and all 14 focused tests passed, covering provider refusal, replay, nested agents, and model overrides.
#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.
Replay is promised only within a major, so 2.0 doesn't need the three patches that only kept runs from before their fixes replaying: openai_agents.refuse-run-model-provider (#204), openai-agents-stateful-mcp-session-watch (#373) and openai_agents.run-caller-agents (#426). Every run now takes the new path: RunConfig.model_provider is refused, stateful MCP operations without a timeout watch their session, and runs use your agents, not copies. _convert_agent and the tests that only covered the agent copies go too. The three 2.x histories that had patch markers are recorded again without them, since a marker with no matching patched() call fails replay.
Replay is promised only within a major, so 2.0 doesn't need the three patches that only kept runs from before their fixes replaying: openai_agents.refuse-run-model-provider (#204), openai-agents-stateful-mcp-session-watch (#373) and openai_agents.run-caller-agents (#426). Every run now takes the new path: RunConfig.model_provider is refused, stateful MCP operations without a timeout watch their session, and runs use your agents, not copies. _convert_agent and the tests that only covered the agent copies go too. The three 2.x histories that had patch markers are recorded again without them, since a marker with no matching patched() call fails replay.
…replaying (#566) ## What was changed Three patches on `main` exist only to keep runs from before their fixes replaying. No release wrote their markers: PyPI has 1.0.0 and 1.1.0, and both shipped before these fixes. With replay promised only within a major (#565), 2.0.0 doesn't need them. So let's remove them before it ships: - `openai_agents.refuse-run-model-provider` (#204): `Runner.run` always refuses `RunConfig.model_provider`. - `openai-agents-stateful-mcp-session-watch` (#373): a stateful MCP operation with neither a schedule-to-start nor a schedule-to-close timeout always watches its session. - `openai_agents.run-caller-agents` (#426): runs always use your agents, not copies. `_convert_agent` goes, and so do `test_model_conversion_loops` and the four run-state tests that called it directly. The three 2.x histories that had markers are recorded again without them, as `caller-agent-workflow-history.json`, `stateful-mcp-cancel-wait-workflow-history.json` and `stateful-mcp-gather-wait-workflow-history.json`. Why? A history with a marker and no matching `patched()` call fails replay with `[TMPRL1100] Non-deprecated patch marker encountered`. The Python README drops the marker notes and says which 1.x runs don't replay. The TypeScript README keeps its note on `openai-agents-stateful-mcp-session-watch`: TypeScript has its own copy of that gate, and this PR doesn't touch it. This also takes `workflow.patched()` out of every `Runner.run`. That call is what exposed the sdk-core bug where a run whose first Update was rejected fails its own replay. ## What will you notice? (Breaking) These 1.x runs don't replay on 2.0. Let them finish on 1.x Workers before you upgrade, or keep them there with Worker Versioning. For the release notes: - A run that passed its own `RunConfig.model_provider` (#204). On 1.x it ran on the Worker's provider. On 2.0 its replay fails with the `ValueError` that refuses the provider. - A run in which a stateful MCP operation with `cancellation_type=WAIT_CANCELLATION_COMPLETED` and neither timeout finished in the same Workflow Task as another Activity (#373). On 2.0 the operation resolves one step later, so the run schedules its next Activities in another order (`[TMPRL1100]`). - A run whose next step depended on getting its own agents back, not copies, such as asking again for a permanent approval (#426) (`[TMPRL1100]`). A run on a `main` build that reached one of these gates recorded its marker, and it doesn't replay either. No release wrote those markers. Rolling back to 1.x isn't promised either: histories of 2.0 runs that hit the last two cases fail on 1.1.0 with `[TMPRL1100]`. ## 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. These three only protect runs from before their fixes, so they go before 2.0.0. ## Checklist 1. No issue. 2. How was this tested: - `make format`, `make lint` and `make test` for `python/openai_agents` on Python 3.12: 618 passed, 2 skipped. - Replay, across builds. I recorded finished runs on Workers with no Workflow cache (a hello agent, `CallerAgentWorkflow`, and the four stateful MCP replay shapes, with and without `WAIT_CANCELLATION_COMPLETED`), plus a `CallerAgentWorkflow` run still waiting on its model Activity. I recorded them on `main`, on this PR, and the stateful MCP ones on 1.1.0 too. Then I replayed each of them, and the committed histories, on every build. - On this PR, only these fail: - the three 1.x cases above: the committed 1.x `caller-agent` (`[TMPRL1100]`), `run-model-provider` (the plugin's `ValueError`) and `stateful-mcp-gather-wait` (`[TMPRL1100]`) histories, and the `WAIT_CANCELLATION_COMPLETED` gather recorded on 1.1.0 (`[TMPRL1100]`); - every history with a marker: the three committed on `main` and all seven recorded on `main` (every `main` agent run records `openai_agents.run-caller-agents`), each with `[TMPRL1100] Non-deprecated patch marker encountered`. The other nine committed 1.x histories replay, and so do the 1.1.0 cancel runs, with and without `WAIT_CANCELLATION_COMPLETED`, and the 1.1.0 gather run without it. Everything recorded on this PR replays on it. - Rollback: this PR's histories on `main` and on 1.1.0. The caller-agent and `WAIT_CANCELLATION_COMPLETED` gather histories fail with `[TMPRL1100]`; the rest replay, including the waiting run. I didn't carry a live run from one build to another. - Control: a history with a renamed Activity fails with `[TMPRL1100]` on every build. 3. Any docs updates needed? The README changes are here. The 2.0.0 release notes should list the replay cases above.
What was changed
The OpenAI Agents plugin now refuses a run's own model provider in Workflow code, instead of silently sending the run's model calls to the Worker's provider.
TemporalOpenAIRunner._prepare_workflow_run, whichRunner.runandRunner.run_streamedshare, raisesValueErrorwhenRunConfig.model_provideris anything other than an unconfiguredMultiProvider(whatRunConfig()creates) or the plugin's own provider (which a nested run, such as an agent used as a tool, inherits). A dictrun_configgoes through the same check.MultiProvidercounts as unconfigured when its settings equal a freshMultiProvider()'s. Caches filled on use don't count, including the OpenAI client it builds on first use when none was passed, so aRunConfig()used in a native run and then reused in a Workflow is not refused.OpenAIAgentsPlugin(model_provider=...)and aMultiProviderprefix map as the way to use several providers. The README's "Model Providers" section documents the rule.The model call runs in an Activity, which cannot receive a provider object from Workflow code, so the plugin cannot honor a run's provider without a provider registry on the Worker. It already refuses a model object on the agent or on
RunConfig.modelthe same way.Breaking change: a Workflow that passes
RunConfig(model_provider=...)completes today on the Worker's provider; with this change its Workflow Task fails with the refusal until provider selection moves to the Worker. Registering the providers on the Worker (for example aMultiProviderwith a prefix map) and choosing one by model name keeps working.Replay and rollback: the check is behind
workflow.patched("openai_agents.refuse-run-model-provider"), called only when a run sets its own provider, so Workflows that never do record no marker.The branch has two commits, a merge of
mainatc664a34and an import-order fix for that merge. Review the combined diff againstmain.Why?
See #203. The plugin replaces each agent's model with a stub that runs the model call in an Activity, and the Activity asks the Worker's provider, so the run's provider is never asked. The run's prompt goes to a provider and account the run did not choose, with the Worker's credentials, and the run completes with no error or warning. The framework's model guide uses
RunConfig(model_provider=...)for custom providers, websocket transport, OpenRouter-style model IDs and strict feature validation.Checklist
Closes [Bug] openai_agents:
RunConfig(model_provider=...)in a Workflow is silently ignored #203How was this tested:
test_run_model_provider_refusedintests/test_openai.py, for a custom provider and a configuredMultiProvider: the Workflow Task must fail with the refusal. Onmainboth cases fail withAssertionError: RunConfig.model_provider was not refused; they pass with the change.test_reused_default_model_provider_is_not_refused: aMultiProvider()whose client cache a native call filled still counts as the default, and a configured one does not.mainfrom a run that passed its own provider, added to the existingtest_replayintests/test_openai_replay.py. It passes onmainand with the change, and fails with the change minus the gate (checked on the first commit).main's 382, the two refusal cases, the cache test and the new replay case), andruff check --select I,ruff format --check,pyright,mypy,basedpyrightandpydocstylepass, on the branch tip. These ran with uv 0.13.1, outside the plugin'srequired-version, so not throughmake. CI coversmake lintandmake test.RunConfig(model_provider=...)in a Workflow is silently ignored #203's reproduction exits 1 on 1.1.0 and onmainatc664a34. With the change it exits 0: the Workflow Task fails with the refusal and no request is sent.kill -9between steps, on runs with the default provider, a custom provider, a configuredMultiProvider, and two two-turn cases (custom-twice,default-then-custom), each finished and waiting on a held Activity:mainreplay onmain, the change and a rollback build that keeps the gate (10 of 10 each);main, the seven with the marker fail with[TMPRL1100] ... Non-deprecated patch marker encountered, as expected for a gate;mainfinish on the change with no failed Workflow Task: those that already passed a provider keep the Worker's provider, anddefault-then-custom, whose first such call comes after the upgrade, is refused;[TMPRL1100].Any docs updates needed?
The README's "Model Providers" section is updated here.
Related: #167 and its draft fix #168 cover a separate case, the plugin's default provider ignoring
set_default_openai_clientandset_default_openai_key. Neither PR depends on the other. Both add a paragraph to the README's "Model Providers" section, so the second to merge may need a small rebase.Not covered:
temporalio1.34.x still bundles the old code astemporalio.contrib.openai_agents. No backport here.Runner.run_streamedgoes through the same check, but neither the tests nor the replay check run it.Open questions:
Runner.run, would keep every earlier run on the old path for all its turns, but would record a marker in every new Workflow on a plugin Worker (or every agent run), so every run started on the change could then roll back only to a gate-keeping build or under Worker Versioning. This change keeps the narrower guarantee above.ValueError, so the Workflow Task fails and is retried until the code changes, like the plugin's refusal of a model object, rather than failing the Workflow.temporalio1.34.x get a backport?Draft while the breaking change and these questions are open.