Repository navigation
Add per-turn model selection to Runner #6207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
markstuart-oai
merged 3 commits into
feat/simple-codex
from
markstuart/sdk-controls-01-model-selection
Nov 24, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """Switch models after an SDK tool reports a failed test. | ||
|
|
||
| Run with --base-model NAME --review-model NAME. Add --codex to use an installed | ||
| Codex wheel. Both names must be available through the same provider. | ||
| """ | ||
|
|
||
| import argparse | ||
| import asyncio | ||
| from dataclasses import dataclass | ||
|
|
||
| from agents import Agent, ModelSelectionData, RunConfig, RunContextWrapper, Runner | ||
| from agents.decorators import tool | ||
| from agents.models.codex import CodexProvider | ||
|
|
||
|
|
||
| @dataclass | ||
| class TestJob: | ||
| failed: bool = False | ||
|
|
||
|
|
||
| @tool | ||
| def run_tests(ctx: RunContextWrapper[TestJob]) -> str: | ||
| """Return a simulated test result for this example.""" | ||
| ctx.context.failed = True | ||
| return "FAILED test_total: expected 42, got 41" | ||
|
|
||
|
|
||
| async def main(base_model: str, review_model: str, use_codex: bool) -> None: | ||
| def select_model(turn: ModelSelectionData[TestJob]) -> str | None: | ||
| if turn.context is not None and turn.context.failed: | ||
| return review_model | ||
| return None | ||
|
|
||
| agent = Agent[TestJob]( | ||
| name="Test reviewer", | ||
| model=base_model, | ||
| instructions="Call run_tests once. Then explain the reported failure without editing files.", | ||
| tools=[run_tests], | ||
| ) | ||
| config = ( | ||
| RunConfig(model_provider=CodexProvider(), model_selector=select_model) | ||
| if use_codex | ||
| else RunConfig(model_selector=select_model) | ||
| ) | ||
| try: | ||
| result = await Runner.run(agent, "Check the tests.", context=TestJob(), run_config=config) | ||
| print(result.final_output) | ||
| finally: | ||
| await config.model_provider.aclose() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--base-model", required=True) | ||
| parser.add_argument("--review-model", required=True) | ||
| parser.add_argument("--codex", action="store_true") | ||
| args = parser.parse_args() | ||
| asyncio.run(main(args.base_model, args.review_model, args.codex)) |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.