[X] I added a very descriptive title to this issue.
[X] I searched the LangChain.js documentation with the integrated search.
[X] I used the GitHub search to find a similar question and didn't find it.
[X] I am sure that this is a bug in LangChain.js rather than my code.
[X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
import { config } from 'dotenv';
import { BedrockChat } from "@langchain/community/chat_models/bedrock";
// import { BedrockChat } from "./custom-models/index"; // this is my upadted version of BedrockChat that I want to propose as a PR
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { z } from "zod";
import { createToolCallingAgent, AgentExecutor } from "langchain/agents";
import { DynamicStructuredTool } from "@langchain/core/tools";
config(); // load .env file
if (!process?.env?.AWSAccessKeyId || !process?.env?.AWSSecretAccessKey) {
console.error('AWSAccessKeyId or AWSSecretAccessKey not found in .env file');
process.exit(1);
}
const addTool = new DynamicStructuredTool({
name: "add",
description: "Add two integers together.",
schema: z.object({
firstInt: z.number(),
secondInt: z.number(),
}),
func: async ({ firstInt, secondInt }) => {
console.log('------ Function called with: -----------', { firstInt, secondInt });
return (firstInt + secondInt).toString();
},
});
async function test() {
const model = new BedrockChat({
model: "anthropic.claude-3-sonnet-20240229-v1:0",
temperature: 0.5,
region: "us-east-1",
credentials: {
accessKeyId: process.env.AWSAccessKeyId as string,
secretAccessKey: process.env.AWSSecretAccessKey as string,
},
});
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful assistant"],
["placeholder", "{chat_history}"],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
])
const agent = createToolCallingAgent({
llm: model,
tools: [addTool],
prompt: prompt,
streamRunnable: false // attempt to work around streaming issue with tools
});
const agentExecutor = new AgentExecutor({
agent,
tools: [addTool],
// verbose: true,
returnIntermediateSteps: true,
});
const r = await agentExecutor.invoke({ input: "Hi! Can you tell me what is 10 + 4?" });
console.log(r);
console.log(r.content);
}
test();
Error Message and Stack Trace (if applicable)
This agent requires that the "bind_tools()" method be implemented on the input model.
Description
I'm trying to use LangChain JS to create Tool Calling agent on Amazon Bedrock, using Claude 3 model with latest tools APi
I get above error because in community/Bedrock this is not implemented yet
I've finished this implementation on my own (mostly copying from Anthropic implementation) and would like to make a PR with it, and get support to finish it - as I don't have experience contributing to this project
On my local test the function call gets executed as follows:
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
This agent requires that the "bind_tools()" method be implemented on the input model.
Description
System Info
npm info langchain:
Windows 11 64bit Node v20.14.0 No yarn atm