Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shiny-beers-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openai/agents-openai': patch
---

Add input_fidelity parameter support to image generation tool
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
strategy:
matrix:
# https://nodejs.org/en/about/previous-releases
node-version: [20, 22, 24]
# Using 24.3.x due to https://github.com/pnpm/pnpm/issues/9743
Copy link
Member Author

Choose a reason for hiding this comment

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

Spent time to identify the cause of pnpm i errors... this is necessary for now

node-version: ['20', '22', '24.3.x']
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion examples/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@openai/agents-extensions": "workspace:*",
"@ai-sdk/openai": "^1.0.0",
"server-only": "^0.0.1",
"openai": "^5.0.1",
"openai": "^5.10.1",
"zod": "3.25.40 - 3.25.67"
},
"scripts": {
Expand Down
31 changes: 30 additions & 1 deletion examples/tools/image-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function main() {
const agent = new Agent({
name: 'Image generator',
instructions: 'You are a helpful agent.',
tools: [imageGenerationTool({ quality: 'low' })],
tools: [imageGenerationTool({ quality: 'low', inputFidelity: 'high' })],
});

await withTrace('Image generation example', async () => {
Expand All @@ -40,6 +40,35 @@ async function main() {
fs.writeFileSync(tmpPath, buffer);
// console.log(`Image saved to ${tmpPath}`);
openFile(tmpPath);

const revisedResult = await run(agent, [
{
role: 'user',
content: [
{
type: 'input_text',
text: 'Change only the background of the given image to Japanese style.',
},
{
type: 'input_image',
image: 'data:image/png;base64,' + item.rawItem.output,
},
],
},
]);
for (const revisedItem of revisedResult.newItems) {
if (
revisedItem.type === 'tool_call_item' &&
revisedItem.rawItem.type === 'hosted_tool_call' &&
revisedItem.rawItem.output
) {
const buffer = Buffer.from(revisedItem.rawItem.output, 'base64');
const tmpPath = path.join(os.tmpdir(), `image-${Date.now()}.png`);
fs.writeFileSync(tmpPath, buffer);
// console.log(`Image saved to ${tmpPath}`);
openFile(tmpPath);
}
}
}
}
// or using result.output works too
Expand Down
2 changes: 1 addition & 1 deletion packages/agents-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"dependencies": {
"@openai/zod": "npm:[email protected] - 3.25.67",
"debug": "^4.4.0",
"openai": "^5.0.1"
"openai": "^5.10.1"
},
"peerDependencies": {
"zod": "3.25.40 - 3.25.67"
Expand Down
4 changes: 2 additions & 2 deletions packages/agents-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
},
"dependencies": {
"@openai/agents-core": "workspace:*",
"@openai/zod": "npm:[email protected] - 3.25.67",
"debug": "^4.4.0",
"openai": "^5.0.1",
"@openai/zod": "npm:[email protected] - 3.25.67"
"openai": "^5.10.1"
},
"scripts": {
"prebuild": "tsx ../../scripts/embedMeta.ts",
Expand Down
6 changes: 5 additions & 1 deletion packages/agents-openai/src/openaiResponsesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function converTool<_TContext = unknown>(
tool: {
type: 'image_generation',
background: tool.providerData.background,
input_fidelity: tool.providerData.input_fidelity,
input_image_mask: tool.providerData.input_image_mask,
model: tool.providerData.model,
moderation: tool.providerData.moderation,
Expand Down Expand Up @@ -525,7 +526,10 @@ function getInputItems(
type: 'code_interpreter_call',
id: item.id!,
code: item.providerData?.code ?? '',
results: item.providerData?.results ?? [],
// This property used to be results, so keeping both for backward compatibility
// That said, this property cannot be passed from a user, so it's just API's internal data.
outputs:
item.providerData?.outputs ?? item.providerData?.results ?? [],
status: CodeInterpreterStatus.parse(item.status ?? 'failed'),
container_id: item.providerData?.containerId,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/agents-openai/src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export type ImageGenerationTool = {
type: 'image_generation';
name?: 'image_generation' | string;
background?: 'transparent' | 'opaque' | 'auto' | string;
inputFidelity?: 'high' | 'low' | null;
inputImageMask?: OpenAI.Responses.Tool.ImageGeneration.InputImageMask;
model?: 'gpt-image-1' | string;
moderation?: 'auto' | 'low' | string;
Expand All @@ -178,6 +179,7 @@ export function imageGenerationTool(
type: 'image_generation',
name: options.name ?? 'image_generation',
background: options.background,
input_fidelity: options.inputFidelity,
input_image_mask: options.inputImageMask,
model: options.model,
moderation: options.moderation,
Expand Down
2 changes: 1 addition & 1 deletion packages/agents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@openai/agents-core": "workspace:*",
"@openai/agents-openai": "workspace:*",
"@openai/agents-realtime": "workspace:*",
"openai": "^5.0.1",
"openai": "^5.10.1",
"debug": "^4.4.0"
},
"keywords": [
Expand Down
22 changes: 11 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.