@devries-cameron20 / composio-1 / commits / 9692db5c0
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(openai-agents): honor the strict option

OpenAIAgentsProvider accepted { strict } but always registered tools with strict: false and additionalProperties: true. Strict mode now registers tools with strict: true and a schema normalized by toStrictJsonSchema (optional parameters required-nullable), drops null arguments the tool schema rejects before execution, and registers tools strict mode cannot express without strict mode with a warning. Co-authored-by: AseemPrasad <aseemprasad0520@gmail.com> Claude-Session: https://claude.ai/code/session_01TDrxCHn2hg51HmxVstSUgs

jkomyno committed Aug 26, 2026 at 17:31 UTC 9692db5c0ab6fb3cb15338edd8f71c32f67696e8
4 files changed +149 -9
.changeset/openai-agents-honor-strict.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/openai-agents': patch
3 +---
4 +
5 +`OpenAIAgentsProvider({ strict: true })` now takes effect: tools are registered with `strict: true` and a schema normalized for OpenAI structured outputs (every property required, optional ones accept `null`), a `null` argument the tool's own schema does not accept is dropped before execution, and tools whose schema strict mode cannot express are registered without strict mode with a warning. The option was previously ignored.
ts/packages/providers/openai-agents/README.md
+1 -1
@@ -43,7 +43,7 @@ For multi-turn conversations, store `session.sessionId` and reuse it with `compo
43
44 ## Strict mode
45
46 -Pass `strict: true` to enable strict JSON schema validation for tool parameters (see the [Agents SDK options reference](https://openai.github.io/openai-agents-js/guides/tools/#options-reference)):
46 +Pass `strict: true` to register tools with strict JSON schema validation (see the [Agents SDK options reference](https://openai.github.io/openai-agents-js/guides/tools/#options-reference)). Each tool's input schema is normalized for OpenAI structured outputs: every object lists all of its properties in `required` and is closed, and optional properties stay available but accept `null`; a `null` the model sends for an optional parameter is dropped before the tool runs. Tools whose schema cannot be expressed in strict mode (objects that accept arbitrary keys, `allOf`, `prefixItems`) are registered without strict mode and log a warning:
47
48 ```typescript
49 const provider = new OpenAIAgentsProvider({ strict: true });
ts/packages/providers/openai-agents/src/index.ts
+52 -7
@@ -18,11 +18,28 @@ import {
18 McpServerGetResponse,
19 normalizeToolArguments,
20 deduplicateJsonSchemaRequiredArrays,
21 + logger,
22 + omitNullToolArguments,
23 + toStrictJsonSchema,
24 } from '@composio/core';
25 import type { Tool as OpenAIAgentTool } from '@openai/agents';
26 import { tool as createOpenAIAgentTool } from '@openai/agents';
27
28 type OpenAIAgentsToolCollection = Array<OpenAIAgentTool>;
29 +
30 +/** The strict JSON Schema parameter shape the Agents SDK accepts. */
31 +type StrictToolParameters = Extract<
32 + Parameters<typeof createOpenAIAgentTool>[0]['parameters'],
33 + { additionalProperties: false }
34 +>;
35 +
36 +/** Parameters registered for a tool without input parameters under strict mode. */
37 +const EMPTY_OBJECT_SCHEMA = {
38 + type: 'object',
39 + properties: {},
40 + required: [],
41 + additionalProperties: false,
42 +} as const;
43 export class OpenAIAgentsProvider extends BaseAgenticProvider<
44 OpenAIAgentsToolCollection,
45 OpenAIAgentTool,
@@ -125,6 +142,40 @@ export class OpenAIAgentsProvider extends BaseAgenticProvider<
142 wrapTool(composioTool: ComposioTool, executeTool: ExecuteToolFn): OpenAIAgentTool {
143 const inputParameters = deduplicateJsonSchemaRequiredArrays(composioTool.inputParameters);
144
145 + // Strict mode applies OpenAI's structured-output contract at every
146 + // depth: all properties required, closed objects, optional properties
147 + // widened to accept null instead of being dropped. Tools whose schema
148 + // strict mode cannot express are registered without strict mode.
149 + const execute = async (params: unknown, strictSource?: Record<string, unknown>) => {
150 + // Models occasionally emit tool input as a JSON string rather than an object (issue #2406).
151 + const normalized = normalizeToolArguments(params, composioTool.slug);
152 + // Under strict mode optional parameters are emitted as required-nullable,
153 + // so a null the tool's own schema does not accept means "omitted".
154 + return await executeTool(
155 + composioTool.slug,
156 + strictSource ? omitNullToolArguments(normalized, strictSource) : normalized
157 + );
158 + };
159 +
160 + if (this.strict) {
161 + const strict = toStrictJsonSchema(composioTool.inputParameters ?? EMPTY_OBJECT_SCHEMA);
162 + if (strict.unsupported.length === 0) {
163 + return createOpenAIAgentTool({
164 + name: composioTool.slug,
165 + description: composioTool.description ?? '',
166 + parameters: strict.schema as StrictToolParameters,
167 + strict: true,
168 + execute: params => execute(params, strict.source),
169 + });
170 + }
171 + const reasons = strict.unsupported
172 + .map(entry => `${entry.path || '<root>'}: ${entry.keyword} (${entry.detail})`)
173 + .join('; ');
174 + logger.warn(
175 + `OpenAIAgentsProvider: tool "${composioTool.slug}" is registered without strict mode because its schema cannot be expressed as strict structured outputs: ${reasons}`
176 + );
177 + }
178 +
179 return createOpenAIAgentTool({
180 name: composioTool.slug,
181 description: composioTool.description ?? '',
@@ -135,13 +186,7 @@ export class OpenAIAgentsProvider extends BaseAgenticProvider<
186 additionalProperties: true,
187 },
188 strict: false,
138 - execute: async params => {
139 - // Models occasionally emit tool input as a JSON string rather than an object (issue #2406).
140 - return await executeTool(
141 - composioTool.slug,
142 - normalizeToolArguments(params, composioTool.slug)
143 - );
144 - },
189 + execute: params => execute(params),
190 });
191 }
192
ts/packages/providers/openai-agents/test/openai-agents.test.ts
+91 -1
@@ -1,6 +1,6 @@
1 import { describe, it, expect, vi, beforeEach } from 'vitest';
2 import { OpenAIAgentsProvider } from '../src';
3 -import { Tool } from '@composio/core';
3 +import { Tool, ExecuteToolFn } from '@composio/core';
4 import { tool as createOpenAIAgentTool } from '@openai/agents';
5
6 // Define an interface for our mocked OpenAI Agent tool
@@ -157,6 +157,96 @@ describe('OpenAIAgentsProvider', () => {
157 });
158 });
159
160 + describe('strict mode', () => {
161 + it('registers a strict schema with optional parameters kept as required-nullable', () => {
162 + const strictProvider = new OpenAIAgentsProvider({ strict: true });
163 + strictProvider._setExecuteToolFn(mockExecuteToolFn);
164 + const wrapped = strictProvider.wrapTool(
165 + {
166 + ...mockTool,
167 + inputParameters: {
168 + type: 'object',
169 + properties: {
170 + input: { type: 'string' },
171 + cfg: {
172 + type: 'object',
173 + properties: { url: { type: 'string' }, note: { type: 'string' } },
174 + required: ['url'],
175 + },
176 + },
177 + required: ['input'],
178 + },
179 + },
180 + mockExecuteToolFn as ExecuteToolFn
181 + ) as unknown as MockedOpenAIAgentTool;
182 +
183 + expect(wrapped.strict).toBe(true);
184 + expect(wrapped.parameters).toEqual({
185 + type: 'object',
186 + properties: {
187 + input: { type: 'string' },
188 + cfg: {
189 + type: ['object', 'null'],
190 + properties: { url: { type: 'string' }, note: { type: ['string', 'null'] } },
191 + required: ['url', 'note'],
192 + additionalProperties: false,
193 + },
194 + },
195 + required: ['input', 'cfg'],
196 + additionalProperties: false,
197 + });
198 + });
199 +
200 + it('registers tools strict mode cannot express without strict', () => {
201 + const strictProvider = new OpenAIAgentsProvider({ strict: true });
202 + const wrapped = strictProvider.wrapTool(
203 + {
204 + ...mockTool,
205 + inputParameters: {
206 + type: 'object',
207 + properties: { headers: { type: 'object', additionalProperties: { type: 'string' } } },
208 + required: ['headers'],
209 + },
210 + },
211 + mockExecuteToolFn as ExecuteToolFn
212 + ) as unknown as MockedOpenAIAgentTool;
213 +
214 + expect(wrapped.strict).toBe(false);
215 + expect(wrapped.parameters).toEqual({
216 + type: 'object',
217 + properties: { headers: { type: 'object', additionalProperties: { type: 'string' } } },
218 + required: ['headers'],
219 + additionalProperties: true,
220 + });
221 + });
222 +
223 + it('omits null arguments the tool schema rejects before executing under strict mode', async () => {
224 + const strictProvider = new OpenAIAgentsProvider({ strict: true });
225 + const wrapped = strictProvider.wrapTool(
226 + {
227 + ...mockTool,
228 + inputParameters: {
229 + type: 'object',
230 + properties: {
231 + input: { type: 'string' },
232 + label: { type: 'string' },
233 + clearable: { type: ['string', 'null'] },
234 + },
235 + required: ['input'],
236 + },
237 + },
238 + mockExecuteToolFn as ExecuteToolFn
239 + ) as unknown as MockedOpenAIAgentTool;
240 +
241 + await wrapped.execute({ input: 'x', label: null, clearable: null });
242 +
243 + expect(mockExecuteToolFn).toHaveBeenCalledWith(mockTool.slug, {
244 + input: 'x',
245 + clearable: null,
246 + });
247 + });
248 + });
249 +
250 describe('wrapTools', () => {
251 it('should wrap multiple tools', () => {
252 const anotherTool: Tool = {