-
Checked other resources
Commit to Help
Example Codereturn new DynamicStructuredTool({
name: definition.agentActionId,
description: definition.fullDescription!,
schema: (definition.inputs?.properties as Record<string, any>) ?? {},
func: async (
args: Record<string, unknown>
): Promise<AssistantActionInvocation> => {
// Just return the invocation for now.
return {
invocationId: uuidv4(),
agentActionId: definition.agentActionId,
inputs: args,
};
},
}); DescriptionI'm trying to start using an existing OpenAI tool-calling API over to Langchain. We have our tools defined as JSON schema only.
It seems like the schema is completely thrown away by the following code in tools/index.ts
Perhaps there's some other way the schema gets passed to the LLM that I'm missing? The tutorials all seem to use Zod. System InfoMac / Node 18 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hey @dwabyick! I'm here to help you with any bugs, questions, or contributions while you're waiting for a human maintainer. Let's get to work! JSON Schema tool descriptions are indeed supported in LangChain. The documentation specifies that the schema for tools can be provided as either Zod or JSON schema. However, it's important to note that if you pass a JSON schema, tool inputs will not be validated [1]. In your example, it seems like the schema might be getting overridden by a default Zod schema. This could be due to the To ensure your JSON schema is used correctly, you might need to verify how the schema is being passed and utilized in your specific implementation. If the tutorials primarily use Zod, it might be beneficial to adapt your JSON schema to Zod for validation purposes, or ensure that your JSON schema is correctly integrated into the tool setup without being overridden. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
Ok, it seems like I was on the wrong track with The following doesn't really provide a Langchain "tool" with a function to invoke, but it does at least expose the functions to the LLM, which is what I was trying to achieve. const tools = [{
type: "function",
function: {
name: "myFunctionName",
description: "myFunctionDescription"
parameters: {
type: "object",
properties: {
propName: {...}
}
}
}
}];
const modelWithTools = this.model.bindTools(tools);
const response = await modelWithTools.invoke([
{ role: "system", content: systemPrompt },
{ role: "user", content: userMessage },
]); |
Beta Was this translation helpful? Give feedback.
This seems to be incorrect. Passing in
schema
toDynamicStructuredTool
will get overridden asisZodSchema
will return false in the constructor.