From c478570455377e239ff0d1b4bd0e2947268c0e2f Mon Sep 17 00:00:00 2001 From: Corie Watson Date: Thu, 27 Nov 2025 13:24:56 +0000 Subject: [PATCH 1/3] feat(anthropic): add tool testapp --- js/testapps/anthropic/src/stable/tools.ts | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 js/testapps/anthropic/src/stable/tools.ts diff --git a/js/testapps/anthropic/src/stable/tools.ts b/js/testapps/anthropic/src/stable/tools.ts new file mode 100644 index 0000000000..7609b1c81d --- /dev/null +++ b/js/testapps/anthropic/src/stable/tools.ts @@ -0,0 +1,51 @@ +/** + * Copyright 2025 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { anthropic } from '@genkit-ai/anthropic'; +import { genkit, z } from 'genkit'; + +const ai = genkit({ + plugins: [ + // Configure the plugin with environment-driven API key + anthropic(), + ], +}); + +const getWeather = ai.defineTool( + { + name: 'getWeather', + description: 'Gets the current weather in a given location', + inputSchema: z.object({ + location: z.string().describe('The location to get the current weather for'), + }), + outputSchema: z.string(), + }, + async (input: any) => { + // Here, we would typically make an API call or database query. For this + // example, we just return a fixed value. + return `The current weather in ${input.location} is 63°F and sunny.`; + }, +); + +ai.defineFlow('anthropic-stable-tools', async () => { + const { text } = await ai.generate({ + model: anthropic.model('claude-sonnet-4-5'), + tools: [getWeather], + prompt: 'What is the weather in Paris?', + }); + + return text; +}); From 4d50ca0412cfb29301a50a1b9bf10fc2f16f7f1b Mon Sep 17 00:00:00 2001 From: Corie Watson Date: Mon, 1 Dec 2025 00:56:16 +0000 Subject: [PATCH 2/3] chore: format --- js/testapps/anthropic/src/stable/tools.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/testapps/anthropic/src/stable/tools.ts b/js/testapps/anthropic/src/stable/tools.ts index 7609b1c81d..8bd93162b8 100644 --- a/js/testapps/anthropic/src/stable/tools.ts +++ b/js/testapps/anthropic/src/stable/tools.ts @@ -29,7 +29,9 @@ const getWeather = ai.defineTool( name: 'getWeather', description: 'Gets the current weather in a given location', inputSchema: z.object({ - location: z.string().describe('The location to get the current weather for'), + location: z + .string() + .describe('The location to get the current weather for'), }), outputSchema: z.string(), }, @@ -37,7 +39,7 @@ const getWeather = ai.defineTool( // Here, we would typically make an API call or database query. For this // example, we just return a fixed value. return `The current weather in ${input.location} is 63°F and sunny.`; - }, + } ); ai.defineFlow('anthropic-stable-tools', async () => { From 81514853b3d3f2a2ff881a28b4545abde917c6ce Mon Sep 17 00:00:00 2001 From: Corie Watson Date: Tue, 2 Dec 2025 11:44:52 +0000 Subject: [PATCH 3/3] feat(testapps/anthropic): script and flow param --- js/testapps/anthropic/package.json | 1 + js/testapps/anthropic/src/stable/tools.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/js/testapps/anthropic/package.json b/js/testapps/anthropic/package.json index 08e1a0d2fd..b5a21749b0 100644 --- a/js/testapps/anthropic/package.json +++ b/js/testapps/anthropic/package.json @@ -13,6 +13,7 @@ "dev:stable:text-plain": "genkit start -- npx tsx --watch src/stable/text-plain.ts", "dev:stable:webp": "genkit start -- npx tsx --watch src/stable/webp.ts", "dev:stable:pdf": "genkit start -- npx tsx --watch src/stable/pdf.ts", + "dev:stable:tools": "genkit start -- npx tsx --watch src/stable/tools.ts", "genkit:dev": "cross-env GENKIT_ENV=dev npm run dev:stable", "genkit:start": "cross-env GENKIT_ENV=dev genkit start -- tsx --watch src/stable/basic.ts", "dev": "export GENKIT_RUNTIME_ID=$(openssl rand -hex 8) && node lib/stable/basic.js 2>&1" diff --git a/js/testapps/anthropic/src/stable/tools.ts b/js/testapps/anthropic/src/stable/tools.ts index 7609b1c81d..4c99e4fe5d 100644 --- a/js/testapps/anthropic/src/stable/tools.ts +++ b/js/testapps/anthropic/src/stable/tools.ts @@ -40,11 +40,11 @@ const getWeather = ai.defineTool( }, ); -ai.defineFlow('anthropic-stable-tools', async () => { +ai.defineFlow('anthropic-stable-tools', async ({ place }) => { const { text } = await ai.generate({ model: anthropic.model('claude-sonnet-4-5'), tools: [getWeather], - prompt: 'What is the weather in Paris?', + prompt: `What is the weather in ${place}?`, }); return text;