-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Add model parameter to RealtimeAgent class #1908
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
Conversation
- Add optional model parameter to RealtimeAgent allowing agent-specific model configuration - Update session to use agent's model when specified, overriding defaults - Add comprehensive tests covering model parameter functionality - Update documentation to reflect model parameter support This enables different RealtimeAgents to use different models based on their specific requirements (e.g., using a smarter model for complex tasks while using a lighter model for simple interactions). Addresses issue openai#1888
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR.
src/agents/realtime/session.py
Outdated
| updated_settings = self._base_model_settings.copy() | ||
|
|
||
| # Use agent-specific model if specified | ||
| if agent.model is not None: | ||
| updated_settings["model_name"] = agent.model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agent-specific model ignored when session starts
The new block assigns updated_settings["model_name"] = agent.model, but a few lines later the method calls updated_settings.update(starting_settings) when __aenter__ builds the initial model_config. Because starting_settings typically contains the default model name, the assignment here is overwritten and the initial session still uses the runner’s default model. The new model parameter therefore only takes effect after an explicit update_agent() call and fails for the very first agent—the main scenario called out in the summary. Consider applying starting_settings before writing the agent override or omitting the extra update to preserve the intended precedence of agent > run config > defaults.
Useful? React with 👍 / 👎.
|
Hi @pxkundu, thanks for sending this PR, but I didn't mean we'd immediately add this option to realtime agents. We may not accept the suggested changes at this moment. |
- Move agent model assignment after starting_settings update - This fixes P1 bug where agent's model was overridden - Ensures proper precedence: agent model > starting_settings > run config - Add test to verify fix for initial session scenario Addresses feedback from chatgpt-codex-connector bot review
|
Thank you @chatgpt-codex-connector for catching that P1 bug! You're absolutely right - the agent's model was being overridden by Fixed in commit 0c8c00a:
The fix ensures the agent's model is respected from the very first session start, not just after @seratch - Thank you for the feedback. I apologize if I misunderstood the intent of your comment in #1888. When you said "please go ahead with it," I interpreted that as approval to implement the feature. I understand now that you may have meant to explore the idea further before committing to it. Questions for clarification:
I'm happy to:
Thank you for your guidance! |
|
Note To use Codex here, create a Codex account and connect to github. |
I meant the author of the issue can pass a model name to the runner for now. Regarding your suggestion here, we actually don't need the change in the short term. So, let us close this PR now. If you're looking for anything to contribute to this project, fixing practical bugs rather than nice-to-have changes would be helpful to us. Thanks again for your interest. |
|
Thank you for the clarification @seratch! I misunderstood the initial comment - I see now that you meant the issue author could pass the model name to the runner (which already exists), not to add it to the agent level. I appreciate your guidance about focusing on practical bugs rather than nice-to-have features. That's very helpful feedback for future contributions. Thanks for your time and patience! |
Summary
This PR adds a
modelparameter to theRealtimeAgentclass, enabling different agents to use different models based on their specific requirements. This addresses issue #1888 which requested the ability to set up smarter models for agents with specific tasks.Key changes:
modelparameter toRealtimeAgentclassRealtimeRunnermodelparameter work as beforeUse case example:
Test plan
Unit tests (
tests/realtime/test_agent.py):clone()methodIntegration tests (
tests/realtime/test_agent_model.py):Quality checks:
make format- all files formattedmake lint- no linting errorsmypy- type checking passesIssue number
Closes #1888
Checks
RealtimeAgentclassmake lintandmake format- All checks passImplementation Details
Files Changed:
src/agents/realtime/agent.py:model: str | None = Noneparametersrc/agents/realtime/session.py:_get_updated_model_settings_from_agent()to use agent's modelmodel_namefield of session settingstests/realtime/test_agent.py:test_agent_model_parameter()- tests basic parameter functionalitytest_agent_model_clone()- tests model preservation in cloningtests/realtime/test_agent_model.py(new file):Backward Compatibility
✅ Fully backward compatible
modelparameter work exactly as beforeRelated Discussion
This feature was requested in issue #1888 and approved by maintainer @seratch who said:
The implementation follows the approved approach while maintaining consistency with the existing architecture.