Skip to content

Commit cdf9827

Browse files
committed
fix(agent): make responseFormat.strict configurable to allow optional tool params
1 parent a4542a6 commit cdf9827

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

libs/langchain/src/agents/nodes/AgentNode.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,6 @@ export class AgentNode<
794794
(remainingSteps < 2 && hasToolCalls(state.messages.at(-1))))
795795
);
796796
}
797-
798797
async #bindTools(
799798
model: LanguageModelLike,
800799
preparedOptions: ModelRequest | undefined,
@@ -823,6 +822,15 @@ export class AgentNode<
823822
preparedOptions?.toolChoice ||
824823
(structuredTools.length > 0 ? "any" : undefined);
825824

825+
/**
826+
* Allow configuring the strict flag via responseFormat.
827+
* If not provided, default to true (existing behavior).
828+
*/
829+
const responseFormatStrict =
830+
(this.#options.responseFormat as any)?.strict;
831+
const strict =
832+
typeof responseFormatStrict === "boolean" ? responseFormatStrict : true;
833+
826834
/**
827835
* check if the user requests a native schema output
828836
*/
@@ -833,7 +841,8 @@ export class AgentNode<
833841
structuredResponseFormat.strategy.schema
834842
),
835843
schema: structuredResponseFormat.strategy.schema,
836-
strict: true,
844+
// This controls JSON schema strictness
845+
strict,
837846
};
838847

839848
Object.assign(options, {
@@ -845,7 +854,8 @@ export class AgentNode<
845854
kwargs: { method: "json_schema" },
846855
schema: structuredResponseFormat.strategy.schema,
847856
},
848-
strict: true,
857+
// This controls provider-level strict mode (e.g. OpenAI)
858+
strict,
849859
});
850860
}
851861

@@ -869,16 +879,4 @@ export class AgentNode<
869879

870880
return modelRunnable;
871881
}
872-
873-
getState(): {
874-
messages: BaseMessage[];
875-
} {
876-
const state = super.getState();
877-
const origState = state && !(state instanceof Command) ? state : {};
878-
879-
return {
880-
messages: [],
881-
...origState,
882-
};
883-
}
884-
}
882+
}

0 commit comments

Comments
 (0)