Skip to content

Commit 63f9e9b

Browse files
authored
chore (provider,ai): tools have input/output instead of args,result (vercel#6760)
## Background `args`, `parameters`, and `result` for tools are not intuitive and do not align with `inputSchema` and `outputSchema` from MCP tools ## Summary Switch to `input` and `output` for tools.
1 parent 6392f60 commit 63f9e9b

File tree

226 files changed

+2169
-2165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+2169
-2165
lines changed

.changeset/cool-bulldogs-fix.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@ai-sdk/provider': major
3+
'ai': major
4+
---
5+
6+
chore (provider,ai): tools have input/output instead of args,result

examples/ai-core/src/complex/math-agent/agent-required-tool-choice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ async function main() {
1212
description:
1313
'A tool for evaluating mathematical expressions. Example expressions: ' +
1414
"'1.2 * (2 + 4.5)', '12.7 cm to inch', 'sin(45 deg) ^ 2'.",
15-
parameters: z.object({ expression: z.string() }),
15+
inputSchema: z.object({ expression: z.string() }),
1616
execute: async ({ expression }) => mathjs.evaluate(expression),
1717
}),
1818
// answer tool: the LLM will provide a structured answer
1919
answer: tool({
2020
description: 'A tool for providing the final answer.',
21-
parameters: z.object({
21+
inputSchema: z.object({
2222
steps: z.array(
2323
z.object({
2424
calculation: z.string(),

examples/ai-core/src/complex/math-agent/agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function main() {
1212
description:
1313
'A tool for evaluating mathematical expressions. Example expressions: ' +
1414
"'1.2 * (2 + 4.5)', '12.7 cm to inch', 'sin(45 deg) ^ 2'.",
15-
parameters: z.object({ expression: z.string() }),
15+
inputSchema: z.object({ expression: z.string() }),
1616
execute: async ({ expression }) => mathjs.evaluate(expression),
1717
}),
1818
},

examples/ai-core/src/e2e/feature-test-suite.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ export function createFeatureTestSuite({
614614
'What is 2+2? Use the calculator tool to compute this.',
615615
tools: {
616616
calculator: {
617-
parameters: z.object({
617+
inputSchema: z.object({
618618
expression: z
619619
.string()
620620
.describe('The mathematical expression to evaluate'),
@@ -627,9 +627,9 @@ export function createFeatureTestSuite({
627627

628628
expect(result.toolCalls?.[0]).toMatchObject({
629629
toolName: 'calculator',
630-
args: { expression: '2+2' },
630+
input: { expression: '2+2' },
631631
});
632-
expect(result.toolResults?.[0].result).toBe('4');
632+
expect(result.toolResults?.[0].output).toBe('4');
633633
if (!customAssertions.skipUsage) {
634634
expect(result.usage?.totalTokens).toBeGreaterThan(0);
635635
}
@@ -643,7 +643,7 @@ export function createFeatureTestSuite({
643643
'What is 2+2? Use the calculator tool to compute this.',
644644
tools: {
645645
calculator: {
646-
parameters: z.object({
646+
inputSchema: z.object({
647647
expression: z.string(),
648648
}),
649649
execute: async ({ expression }) => {
@@ -678,7 +678,7 @@ export function createFeatureTestSuite({
678678
'Check the temperature in San Francisco and play music that matches the weather. Be sure to report the chosen song name.',
679679
tools: {
680680
getTemperature: {
681-
parameters: z.object({
681+
inputSchema: z.object({
682682
city: z
683683
.string()
684684
.describe('The city to check temperature for'),
@@ -689,7 +689,7 @@ export function createFeatureTestSuite({
689689
},
690690
},
691691
playWeatherMusic: {
692-
parameters: z.object({
692+
inputSchema: z.object({
693693
temperature: z
694694
.number()
695695
.describe('Temperature in Celsius'),

examples/ai-core/src/generate-text/amazon-bedrock-cache-point-tool-call.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { bedrock } from '@ai-sdk/amazon-bedrock';
55

66
const weatherTool = tool({
77
description: 'Get the weather in a location',
8-
parameters: z.object({
8+
inputSchema: z.object({
99
location: z.string().describe('The location to get the weather for'),
1010
}),
1111
// location below is inferred to be a string:
@@ -142,7 +142,7 @@ async function main() {
142142
for (const toolCall of result.toolCalls) {
143143
switch (toolCall.toolName) {
144144
case 'weather': {
145-
toolCall.args.location; // string
145+
toolCall.input.location; // string
146146
break;
147147
}
148148
}
@@ -152,9 +152,9 @@ async function main() {
152152
for (const toolResult of result.toolResults) {
153153
switch (toolResult.toolName) {
154154
case 'weather': {
155-
toolResult.args.location; // string
156-
toolResult.result.location; // string
157-
toolResult.result.temperature; // number
155+
toolResult.input.location; // string
156+
toolResult.output.location; // string
157+
toolResult.output.temperature; // number
158158
break;
159159
}
160160
}

examples/ai-core/src/generate-text/amazon-bedrock-chatbot.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ async function main() {
3333
process.stdout.write(`\nAssistant: ${text}`);
3434
}
3535

36-
for (const { toolName, args } of toolCalls) {
36+
for (const { toolName, input } of toolCalls) {
3737
process.stdout.write(
38-
`\nTool call: '${toolName}' ${JSON.stringify(args)}`,
38+
`\nTool call: '${toolName}' ${JSON.stringify(input)}`,
3939
);
4040
}
4141

42-
for (const { toolName, result } of toolResults) {
42+
for (const { toolName, output } of toolResults) {
4343
process.stdout.write(
44-
`\nTool response: '${toolName}' ${JSON.stringify(result)}`,
44+
`\nTool response: '${toolName}' ${JSON.stringify(output)}`,
4545
);
4646
}
4747

examples/ai-core/src/generate-text/amazon-bedrock-reasoning-chatbot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ async function main() {
4343
for (const toolCall of step.toolCalls) {
4444
console.log(
4545
`\x1b[33m${toolCall.toolName}\x1b[0m` +
46-
JSON.stringify(toolCall.args),
46+
JSON.stringify(toolCall.input),
4747
);
4848
}
4949
}

examples/ai-core/src/generate-text/amazon-bedrock-tool-call-image-result.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function main() {
2020
tools: {
2121
submit: tool({
2222
description: 'Download an image',
23-
parameters: z.object({
23+
inputSchema: z.object({
2424
url: z.string().describe('The image URL'),
2525
}),
2626
execute: async ({ url }) => {

examples/ai-core/src/generate-text/amazon-bedrock-tool-call.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async function main() {
1010
tools: {
1111
weather: weatherTool,
1212
cityAttractions: tool({
13-
parameters: z.object({ city: z.string() }),
13+
inputSchema: z.object({ city: z.string() }),
1414
}),
1515
},
1616
prompt:
@@ -21,12 +21,12 @@ async function main() {
2121
for (const toolCall of result.toolCalls) {
2222
switch (toolCall.toolName) {
2323
case 'cityAttractions': {
24-
toolCall.args.city; // string
24+
toolCall.input.city; // string
2525
break;
2626
}
2727

2828
case 'weather': {
29-
toolCall.args.location; // string
29+
toolCall.input.location; // string
3030
break;
3131
}
3232
}
@@ -37,15 +37,15 @@ async function main() {
3737
switch (toolResult.toolName) {
3838
// NOT AVAILABLE (NO EXECUTE METHOD)
3939
// case 'cityAttractions': {
40-
// toolResult.args.city; // string
40+
// toolResult.input.city; // string
4141
// toolResult.result;
4242
// break;
4343
// }
4444

4545
case 'weather': {
46-
toolResult.args.location; // string
47-
toolResult.result.location; // string
48-
toolResult.result.temperature; // number
46+
toolResult.input.location; // string
47+
toolResult.output.location; // string
48+
toolResult.output.temperature; // number
4949
break;
5050
}
5151
}

examples/ai-core/src/generate-text/amazon-bedrock-tool-choice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function main() {
1111
tools: {
1212
weather: weatherTool,
1313
cityAttractions: tool({
14-
parameters: z.object({ city: z.string() }),
14+
inputSchema: z.object({ city: z.string() }),
1515
}),
1616
},
1717
toolChoice: {

examples/ai-core/src/generate-text/anthropic-chatbot.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ async function main() {
3333
process.stdout.write(`\nAssistant: ${text}`);
3434
}
3535

36-
for (const { toolName, args } of toolCalls) {
36+
for (const { toolName, input } of toolCalls) {
3737
process.stdout.write(
38-
`\nTool call: '${toolName}' ${JSON.stringify(args)}`,
38+
`\nTool call: '${toolName}' ${JSON.stringify(input)}`,
3939
);
4040
}
4141

42-
for (const { toolName, result } of toolResults) {
42+
for (const { toolName, output } of toolResults) {
4343
process.stdout.write(
44-
`\nTool response: '${toolName}' ${JSON.stringify(result)}`,
44+
`\nTool response: '${toolName}' ${JSON.stringify(output)}`,
4545
);
4646
}
4747

examples/ai-core/src/generate-text/anthropic-reasoning-chatbot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function main() {
5656
for (const toolCall of step.toolCalls) {
5757
console.log(
5858
`\x1b[33m${toolCall.toolName}\x1b[0m` +
59-
JSON.stringify(toolCall.args),
59+
JSON.stringify(toolCall.input),
6060
);
6161
}
6262
}

examples/ai-core/src/generate-text/anthropic-tool-call.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function main() {
1111
tools: {
1212
weather: weatherTool,
1313
cityAttractions: tool({
14-
parameters: z.object({ city: z.string() }),
14+
inputSchema: z.object({ city: z.string() }),
1515
}),
1616
},
1717
prompt:
@@ -22,12 +22,12 @@ async function main() {
2222
for (const toolCall of result.toolCalls) {
2323
switch (toolCall.toolName) {
2424
case 'cityAttractions': {
25-
toolCall.args.city; // string
25+
toolCall.input.city; // string
2626
break;
2727
}
2828

2929
case 'weather': {
30-
toolCall.args.location; // string
30+
toolCall.input.location; // string
3131
break;
3232
}
3333
}
@@ -38,15 +38,15 @@ async function main() {
3838
switch (toolResult.toolName) {
3939
// NOT AVAILABLE (NO EXECUTE METHOD)
4040
// case 'cityAttractions': {
41-
// toolResult.args.city; // string
41+
// toolResult.input.city; // string
4242
// toolResult.result;
4343
// break;
4444
// }
4545

4646
case 'weather': {
47-
toolResult.args.location; // string
48-
toolResult.result.location; // string
49-
toolResult.result.temperature; // number
47+
toolResult.input.location; // string
48+
toolResult.output.location; // string
49+
toolResult.output.temperature; // number
5050
break;
5151
}
5252
}

examples/ai-core/src/generate-text/anthropic-tool-choice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function main() {
1111
tools: {
1212
weather: weatherTool,
1313
cityAttractions: tool({
14-
parameters: z.object({ city: z.string() }),
14+
inputSchema: z.object({ city: z.string() }),
1515
}),
1616
},
1717
toolChoice: {

examples/ai-core/src/generate-text/cerebras-tool-call.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function main() {
1111
tools: {
1212
weather: weatherTool,
1313
cityAttractions: tool({
14-
parameters: z.object({ city: z.string() }),
14+
inputSchema: z.object({ city: z.string() }),
1515
}),
1616
},
1717
prompt:
@@ -22,12 +22,12 @@ async function main() {
2222
for (const toolCall of result.toolCalls) {
2323
switch (toolCall.toolName) {
2424
case 'cityAttractions': {
25-
toolCall.args.city; // string
25+
toolCall.input.city; // string
2626
break;
2727
}
2828

2929
case 'weather': {
30-
toolCall.args.location; // string
30+
toolCall.input.location; // string
3131
break;
3232
}
3333
}
@@ -38,15 +38,15 @@ async function main() {
3838
switch (toolResult.toolName) {
3939
// NOT AVAILABLE (NO EXECUTE METHOD)
4040
// case 'cityAttractions': {
41-
// toolResult.args.city; // string
41+
// toolResult.input.city; // string
4242
// toolResult.result;
4343
// break;
4444
// }
4545

4646
case 'weather': {
47-
toolResult.args.location; // string
48-
toolResult.result.location; // string
49-
toolResult.result.temperature; // number
47+
toolResult.input.location; // string
48+
toolResult.output.location; // string
49+
toolResult.output.temperature; // number
5050
break;
5151
}
5252
}

examples/ai-core/src/generate-text/cohere-chatbot.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ async function main() {
3333
process.stdout.write(`\nAssistant: ${text}`);
3434
}
3535

36-
for (const { toolName, args } of toolCalls) {
36+
for (const { toolName, input } of toolCalls) {
3737
process.stdout.write(
38-
`\nTool call: '${toolName}' ${JSON.stringify(args)}`,
38+
`\nTool call: '${toolName}' ${JSON.stringify(input)}`,
3939
);
4040
}
4141

42-
for (const { toolName, result } of toolResults) {
42+
for (const { toolName, output } of toolResults) {
4343
process.stdout.write(
44-
`\nTool response: '${toolName}' ${JSON.stringify(result)}`,
44+
`\nTool response: '${toolName}' ${JSON.stringify(output)}`,
4545
);
4646
}
4747

examples/ai-core/src/generate-text/cohere-tool-call-empty-params.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async function main() {
99
tools: {
1010
currentTime: tool({
1111
description: 'Get the current time',
12-
parameters: z.object({}),
12+
inputSchema: z.object({}),
1313
execute: async () => ({
1414
currentTime: new Date().toLocaleTimeString(),
1515
}),
@@ -22,7 +22,7 @@ async function main() {
2222
for (const toolCall of result.toolCalls) {
2323
switch (toolCall.toolName) {
2424
case 'currentTime': {
25-
toolCall.args; // {}
25+
toolCall.input; // {}
2626
break;
2727
}
2828
}
@@ -32,7 +32,7 @@ async function main() {
3232
for (const toolResult of result.toolResults) {
3333
switch (toolResult.toolName) {
3434
case 'currentTime': {
35-
toolResult.args; // {}
35+
toolResult.input; // {}
3636
break;
3737
}
3838
}

0 commit comments

Comments
 (0)