Skip to content

Remove tools schema from request when reaching last step #5679

Closed
@wangwalton

Description

@wangwalton

Feature Description

There's no point to submitting tools as part of request in the last step (i.e. reaching maxSteps). It just eats up tokens.

import { generateText, tool } from "ai";
import { deepseek } from "@ai-sdk/deepseek";
import { z } from "zod";

export const weatherTool = tool({
  description: "Get the weather in a location",
  parameters: z.object({
    location: z.string().describe("The location to get the weather for"),
  }),

  execute: async ({ location }) => {
    console.log("weatherTool", { location });
    return {
      location,
      temperature: 72 + Math.floor(Math.random() * 21) - 10,
    };
  },
});

const main = async () => {
  const resp = await generateText({
    model: deepseek("deepseek-chat"),
    prompt: "what's the temp for seattle and sf and vancouver and toronto?",
    maxSteps: 2,
    tools: { weatherTool },
  });

  console.log(JSON.parse(resp.steps[1].request.body).tools);
};

main();

Outputs:

{type: 'function', function: {…}}

Use Cases

It would save significant tokens as most use cases only need maxSteps = 2, and if you have a big schema, it uses a lot of tokens.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions