Skip to content
9 changes: 7 additions & 2 deletions libs/langchain/src/agents/nodes/AgentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,18 @@ export class AgentNode<
* check if the user requests a native schema output
*/
if (structuredResponseFormat?.type === "native") {
const resolvedStrict =
preparedOptions?.modelSettings?.strict ??
structuredResponseFormat?.strategy?.strict ??
true;

const jsonSchemaParams = {
name: structuredResponseFormat.strategy.schema?.name ?? "extract",
description: getSchemaDescription(
structuredResponseFormat.strategy.schema
),
schema: structuredResponseFormat.strategy.schema,
strict: true,
strict: resolvedStrict,
};

Object.assign(options, {
Expand All @@ -860,7 +865,7 @@ export class AgentNode<
kwargs: { method: "json_schema" },
schema: structuredResponseFormat.strategy.schema,
},
strict: true,
strict: resolvedStrict,
});
}

Expand Down
3 changes: 2 additions & 1 deletion libs/providers/langchain-openai/src/chat_models/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export class ChatOpenAIResponses<
let strict: boolean | undefined;
if (options?.strict !== undefined) {
strict = options.strict;
} else if (this.supportsStrictToolCalling !== undefined) {
}
if (strict === undefined && this.supportsStrictToolCalling !== undefined) {

Choose a reason for hiding this comment

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

Did you try to run the tests? I would be interested to know if this is a breaking change

strict = this.supportsStrictToolCalling;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, it, expect } from "vitest";
import { ChatOpenAIResponses } from "../responses.js";

describe("strict tool-calling configuration", () => {
it("falls back to supportsStrictToolCalling when strict is undefined", () => {
const model = new ChatOpenAIResponses({
model: "gpt-4o",
supportsStrictToolCalling: true,
});

const params = model.invocationParams({
tools: [
{
type: "function",
function: {
name: "test_func",
description: "testing",
parameters: { type: "object", properties: {} },
},
},
],
});

expect("strict" in params).toBe(false);

expect((params.tools as Array<{ strict?: boolean }>)[0].strict).toBe(true);
});

it("respects user-provided strict option", () => {
const model = new ChatOpenAIResponses({
model: "gpt-4o",
supportsStrictToolCalling: true,
});

const params = model.invocationParams({
strict: false,
tools: [
{
type: "function",
function: {
name: "test_func",
description: "testing",
parameters: { type: "object", properties: {} },
},
},
],
});

expect("strict" in params).toBe(false);

expect((params.tools as Array<{ strict?: boolean }>)[0].strict).toBe(false);
});
});
Loading