-
Notifications
You must be signed in to change notification settings - Fork 497
Add typed reasoning / text options to ModelSettings #513
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@openai/agents-openai': patch | ||
| '@openai/agents-core': patch | ||
| --- | ||
|
|
||
| Add typed reasoning / text options to ModelSettings |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { Agent, run, tool } from '@openai/agents'; | ||
| import { aisdk } from '@openai/agents-extensions'; | ||
| import { z } from 'zod'; | ||
| import { openai } from '@ai-sdk/openai'; | ||
|
|
||
| export async function main() { | ||
| const getWeatherTool = tool({ | ||
| name: 'get_weather', | ||
| description: 'Get the weather for a given city', | ||
| parameters: z.object({ city: z.string() }), | ||
| execute: async ({ city }) => `The weather in ${city} is sunny`, | ||
| }); | ||
| const agent = new Agent({ | ||
| name: 'Helpful Assistant', | ||
| instructions: | ||
| 'You are a helpful assistant. When you need to get the weather, you must use tools.', | ||
| tools: [getWeatherTool], | ||
| model: aisdk(openai('gpt-5-mini')), | ||
| modelSettings: { | ||
| providerData: { | ||
| providerOptions: { | ||
| openai: { | ||
| reasoningEffort: 'minimal', | ||
| textVerbosity: 'low', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const result = await run( | ||
| agent, | ||
| 'Hello what is the weather in San Francisco?', | ||
| ); | ||
| console.log(result.finalOutput); | ||
| } | ||
|
|
||
| main().catch(console.error); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,8 @@ export class OpenAIChatCompletionsModel implements Model { | |
| top_p: request.modelSettings.topP, | ||
| frequency_penalty: request.modelSettings.frequencyPenalty, | ||
| presence_penalty: request.modelSettings.presencePenalty, | ||
| reasoning_effort: request.modelSettings.reasoning?.effort, | ||
| verbosity: request.modelSettings.text?.verbosity, | ||
| } | ||
| : { base_url: this.#client.baseURL }; | ||
| const response = await this.#fetchResponse(request, span, false); | ||
|
|
@@ -296,6 +298,19 @@ export class OpenAIChatCompletionsModel implements Model { | |
| span.spanData.input = messages; | ||
| } | ||
|
|
||
| const providerData = request.modelSettings.providerData ?? {}; | ||
| if ( | ||
| request.modelSettings.reasoning && | ||
| request.modelSettings.reasoning.effort | ||
| ) { | ||
| // merge the top-level reasoning.effort into provider data | ||
| providerData.reasoning_effort = request.modelSettings.reasoning.effort; | ||
| } | ||
| if (request.modelSettings.text && request.modelSettings.text.verbosity) { | ||
| // merge the top-level text.verbosity into provider data | ||
| providerData.verbosity = request.modelSettings.text.verbosity; | ||
| } | ||
|
Comment on lines
+301
to
+312
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @codex can you suggest potential improvements for it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Summary
Testing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, this is helpful. i will make the non-gpt-5 filter more robust |
||
|
|
||
| const requestData = { | ||
| model: this.#model, | ||
| messages, | ||
|
|
@@ -310,7 +325,7 @@ export class OpenAIChatCompletionsModel implements Model { | |
| parallel_tool_calls: parallelToolCalls, | ||
| stream, | ||
| store: request.modelSettings.store, | ||
| ...request.modelSettings.providerData, | ||
| ...providerData, | ||
| }; | ||
|
|
||
| if (logger.dontLogModelData) { | ||
|
|
||
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.
Just to clarify: I didn't make any changes to ai-sdk integration; Passing these options is the standard way for ai-sdk provider for OAI, so I added example code.