-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathtools-helpers-zod.ts
More file actions
executable file
·38 lines (33 loc) · 1006 Bytes
/
tools-helpers-zod.ts
File metadata and controls
executable file
·38 lines (33 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env -S npm run tsn -T
import Anthropic from '@anthropic-ai/sdk';
import { betaZodTool } from '@anthropic-ai/sdk/helpers/beta/zod';
import { z } from 'zod';
const client = new Anthropic();
async function main() {
const message = await client.beta.messages.toolRunner({
messages: [
{
role: 'user',
content: `What is the weather in SF?`,
},
],
tools: [
betaZodTool({
name: 'getWeather',
description: 'Get the weather at a specific location',
inputSchema: z.object({
location: z.string().describe('The city and state, e.g. San Francisco, CA'),
}),
run: ({ location }) => {
return `The weather is foggy with a temperature of 20°C in ${location}.`;
},
}),
],
model: 'claude-sonnet-4-5-20250929',
max_tokens: 1024,
// the maximum number of iterations to run the tool
max_iterations: 10,
});
console.log('Final response:', message.content);
}
main();