mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-18 11:02:26 -05:00
address comments
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
import { ToolboxClient } from "@toolbox-sdk/core";
|
||||
import { ChatVertexAI } from "@langchain/google-vertexai";
|
||||
import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
|
||||
import { createAgent, createMiddleware, ToolMessage } from "langchain";
|
||||
import { tool } from "@langchain/core/tools";
|
||||
import { fileURLToPath } from "url";
|
||||
import process from "process";
|
||||
|
||||
const systemPrompt = `
|
||||
You're a helpful hotel assistant. You handle hotel searching, booking and
|
||||
cancellations. When the user searches for a hotel, mention it's name, id,
|
||||
location and price tier. Always mention hotel ids while performing any
|
||||
searches. This is very important for any operations. For any bookings or
|
||||
cancellations, please provide the appropriate confirmation. Be sure to
|
||||
update checkin or checkout dates if mentioned by the user.
|
||||
Don't ask for confirmations from the user.
|
||||
You're a helpful hotel assistant. You handle hotel searching, booking and
|
||||
cancellations. When the user searches for a hotel, mention it's name, id,
|
||||
location and price tier. Always mention hotel ids while performing any
|
||||
searches. This is very important for any operations. For any bookings or
|
||||
cancellations, please provide the appropriate confirmation. Be sure to
|
||||
update checkin or checkout dates if mentioned by the user.
|
||||
Don't ask for confirmations from the user.
|
||||
`;
|
||||
|
||||
const GOOGLE_API_KEY = process.env.GOOGLE_API_KEY || 'your-api-key'; // Replace it with your API key
|
||||
|
||||
const businessRulesMiddleware = createMiddleware({
|
||||
name: "BusinessRules",
|
||||
wrapToolCall: async (request, handler) => {
|
||||
@@ -77,9 +79,8 @@ async function main() {
|
||||
schema: t.getParamSchema()
|
||||
}));
|
||||
|
||||
const model = new ChatVertexAI({
|
||||
const model = new ChatGoogleGenerativeAI({
|
||||
model: "gemini-2.5-flash",
|
||||
temperature: 0,
|
||||
});
|
||||
|
||||
const agent = createAgent({
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@langchain/core": "^1.1.19",
|
||||
"@langchain/google-vertexai": "^2.1.15",
|
||||
"@langchain/core": "^1.1.26",
|
||||
"@langchain/google-genai": "^2.1.19",
|
||||
"@langchain/google-vertexai": "^2.1.19",
|
||||
"@toolbox-sdk/core": "^0.2.1",
|
||||
"langchain": "^1.2.17",
|
||||
"langchain": "^1.2.25",
|
||||
"zod": "^3.23.8"
|
||||
}
|
||||
},
|
||||
@@ -22,6 +23,15 @@
|
||||
"integrity": "sha512-gAmrUZSGtKc3AiBL71iNWxDsyUC5uMaKKGdvzYsBoTW/xi42JQHl7eKV2OYzCUqvc+D2RCcf7EXY2iCyFIk6og==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@google/generative-ai": {
|
||||
"version": "0.24.1",
|
||||
"resolved": "https://registry.npmjs.org/@google/generative-ai/-/generative-ai-0.24.1.tgz",
|
||||
"integrity": "sha512-MqO+MLfM6kjxcKoy0p1wRzG3b4ZZXtPI+z2IE26UogS2Cm/XHO+7gGRBh6gcJsOiIVoH93UwKvW4HdgiOZCy9Q==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui": {
|
||||
"version": "8.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
|
||||
@@ -40,17 +50,17 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@langchain/core": {
|
||||
"version": "1.1.19",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/core/-/core-1.1.19.tgz",
|
||||
"integrity": "sha512-hmNAcgeLLqNLnu8UK+HVTfB8170eCmAfsy4gFLBYeE+kdsnyO0Hd/Kd42pZi8Cgfux4OMX3yxl+g+/a1ktGe0A==",
|
||||
"version": "1.1.26",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/core/-/core-1.1.26.tgz",
|
||||
"integrity": "sha512-Xnwi4xEKEtZcGwjW5xpZVP/Dc+WckFxULMShETuCpD6TxNFS6yRM+FhNUO1DDCkRkGn9b1fuzVZrNYb9W7F32A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cfworker/json-schema": "^4.0.2",
|
||||
"ansi-styles": "^5.0.0",
|
||||
"ansi-styles": "^6.2.3",
|
||||
"camelcase": "6",
|
||||
"decamelize": "1.2.0",
|
||||
"js-tiktoken": "^1.0.12",
|
||||
"langsmith": ">=0.4.0 <1.0.0",
|
||||
"langsmith": ">=0.5.0 <1.0.0",
|
||||
"mustache": "^4.2.0",
|
||||
"p-queue": "^6.6.2",
|
||||
"uuid": "^10.0.0",
|
||||
@@ -61,9 +71,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@langchain/google-common": {
|
||||
"version": "2.1.15",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/google-common/-/google-common-2.1.15.tgz",
|
||||
"integrity": "sha512-6cBA8wXMFLCjXhkowofq58GDHRygY5SpJi4ZP+cX+XumMY6M5d76bP4KhWqoPBy2e2augh08vZVUAg67z/8LXA==",
|
||||
"version": "2.1.19",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/google-common/-/google-common-2.1.19.tgz",
|
||||
"integrity": "sha512-siVJeb1o3QNPdhBgHd+rNj04pvG6iRN/da4G6CTISj00NRlWQDZRxIyI2Z+BUWLmv/4fijXRQN/YiAwCJWtKgQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"uuid": "^10.0.0"
|
||||
@@ -72,29 +82,58 @@
|
||||
"node": ">=20"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@langchain/core": "1.1.19"
|
||||
"@langchain/core": "^1.1.25"
|
||||
}
|
||||
},
|
||||
"node_modules/@langchain/google-gauth": {
|
||||
"version": "2.1.15",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/google-gauth/-/google-gauth-2.1.15.tgz",
|
||||
"integrity": "sha512-QnT11K3YredmdtoOZwdJZB6atnsL23fBRsI8O+I6v+STEL/chq1fidHaiocjRPhVUYK+RrqL+BH+CTvBxWnZzQ==",
|
||||
"version": "2.1.19",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/google-gauth/-/google-gauth-2.1.19.tgz",
|
||||
"integrity": "sha512-guEPA6jCKETReCTrWrJlQGENlMlGKWfDZd0ooJoMJD3+N9Y4IPsMOqWaswfkZrxMmBTSQsBWMsd/0ZWwvU+nSA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@langchain/google-common": "2.1.15",
|
||||
"@langchain/google-common": "2.1.19",
|
||||
"google-auth-library": "^10.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
}
|
||||
},
|
||||
"node_modules/@langchain/google-vertexai": {
|
||||
"version": "2.1.15",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/google-vertexai/-/google-vertexai-2.1.15.tgz",
|
||||
"integrity": "sha512-p3klocNvePVnSytM9bcbnHIfUjOK42nQ4wvgdMOCI2FsUsHLg4He7pVGqGsIMfh6krKmiPcN8yadkomK+zh3NQ==",
|
||||
"node_modules/@langchain/google-genai": {
|
||||
"version": "2.1.19",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/google-genai/-/google-genai-2.1.19.tgz",
|
||||
"integrity": "sha512-41u+a81BIr8UcGcptJ57Pc7IyEXP75LERzheyS5X+iNSQu5U4vaIMwSNnyJ0hzAlTjSp552XCsa8D2Ifq7icuA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@langchain/google-gauth": "2.1.15"
|
||||
"@google/generative-ai": "^0.24.0",
|
||||
"uuid": "^11.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@langchain/core": "^1.1.25"
|
||||
}
|
||||
},
|
||||
"node_modules/@langchain/google-genai/node_modules/uuid": {
|
||||
"version": "11.1.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz",
|
||||
"integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==",
|
||||
"funding": [
|
||||
"https://github.com/sponsors/broofa",
|
||||
"https://github.com/sponsors/ctavan"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "dist/esm/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/@langchain/google-vertexai": {
|
||||
"version": "2.1.19",
|
||||
"resolved": "https://registry.npmjs.org/@langchain/google-vertexai/-/google-vertexai-2.1.19.tgz",
|
||||
"integrity": "sha512-VbqlLwe8MUj8VHq3QNiorfSDMaJiZ4pWmI6PS1xLN8MopM/7/KtdtfLpMeVa297fJ9UXQPV/lnJ27qo7g5xiHw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@langchain/google-gauth": "2.1.19"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
@@ -160,12 +199,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-styles": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
|
||||
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
|
||||
"version": "6.2.3",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
|
||||
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||
@@ -861,14 +900,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/langchain": {
|
||||
"version": "1.2.17",
|
||||
"resolved": "https://registry.npmjs.org/langchain/-/langchain-1.2.17.tgz",
|
||||
"integrity": "sha512-qiBvupKnPa/eKyv4Kzd1KeanSV7vfPuLZcaW/2upXQ9nesxrNp3sZNEpf9auQPg+XZgItwxaFi5euWqjXXnakA==",
|
||||
"version": "1.2.25",
|
||||
"resolved": "https://registry.npmjs.org/langchain/-/langchain-1.2.25.tgz",
|
||||
"integrity": "sha512-29qay7nZxkmkH3PRp8cjBpZmGCmA3EW8JwEYqZa0a5CW38nvO2Tr1rbFd26cnlLcxtA5hBRH57/XSPoWLjHJSw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@langchain/langgraph": "^1.1.2",
|
||||
"@langchain/langgraph-checkpoint": "^1.0.0",
|
||||
"langsmith": ">=0.4.0 <1.0.0",
|
||||
"langsmith": ">=0.5.0 <1.0.0",
|
||||
"uuid": "^10.0.0",
|
||||
"zod": "^3.25.76 || ^4"
|
||||
},
|
||||
@@ -876,7 +915,7 @@
|
||||
"node": ">=20"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@langchain/core": "1.1.19"
|
||||
"@langchain/core": "^1.1.26"
|
||||
}
|
||||
},
|
||||
"node_modules/langchain/node_modules/@langchain/langgraph": {
|
||||
@@ -1009,9 +1048,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/langsmith": {
|
||||
"version": "0.4.12",
|
||||
"resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.4.12.tgz",
|
||||
"integrity": "sha512-YWt0jcGvKqjUgIvd78rd4QcdMss0lUkeUaqp0UpVRq7H2yNDx8H5jOUO/laWUmaPtWGgcip0qturykXe1g9Gqw==",
|
||||
"version": "0.5.4",
|
||||
"resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.5.4.tgz",
|
||||
"integrity": "sha512-qYkNIoKpf0ZYt+cYzrDV+XI3FCexApmZmp8EMs3eDTMv0OvrHMLoxJ9IpkeoXJSX24+GPk0/jXjKx2hWerpy9w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/uuid": "^10.0.0",
|
||||
@@ -1155,29 +1194,6 @@
|
||||
"url": "https://opencollective.com/node-fetch"
|
||||
}
|
||||
},
|
||||
"node_modules/openai": {
|
||||
"version": "5.12.2",
|
||||
"resolved": "https://registry.npmjs.org/openai/-/openai-5.12.2.tgz",
|
||||
"integrity": "sha512-xqzHHQch5Tws5PcKR2xsZGX9xtch+JQFz5zb14dGqlshmmDAFBFEWmeIpf7wVqWV+w7Emj7jRgkNJakyKE0tYQ==",
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"openai": "bin/cli"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ws": "^8.18.0",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"ws": {
|
||||
"optional": true
|
||||
},
|
||||
"zod": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/p-finally": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
|
||||
@@ -1288,9 +1304,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/semver": {
|
||||
"version": "7.7.3",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz",
|
||||
"integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==",
|
||||
"version": "7.7.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
|
||||
"integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
@@ -1574,18 +1590,6 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi/node_modules/ansi-styles": {
|
||||
"version": "6.2.3",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
|
||||
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/zod": {
|
||||
"version": "3.25.76",
|
||||
"resolved": "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz",
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
"start": "node agent.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@langchain/core": "^1.1.19",
|
||||
"@langchain/google-vertexai": "^2.1.15",
|
||||
"@langchain/core": "^1.1.26",
|
||||
"@langchain/google-genai": "^2.1.19",
|
||||
"@langchain/google-vertexai": "^2.1.19",
|
||||
"@toolbox-sdk/core": "^0.2.1",
|
||||
"langchain": "^1.2.17",
|
||||
"langchain": "^1.2.25",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"author": "",
|
||||
|
||||
Reference in New Issue
Block a user