toolCalled()
A stop rule that ends a chat call once the model asks for one of the tools you name.
A stop rule for chat()’s stopWhen: the call ends after the step in which the model asked for one of these tools, even when maxSteps has steps left.
function toolCalled(...names: string[]): StopRuleA stop rule is any function that gets { steps }, the steps so far, and returns true to stop, or a promise of it.
Example
Give the model a tool it uses to hand in its final answer, and stop there:
import { space, tool, toolCalled } from "digitospace"
import { z } from "zod"
const answer = tool({
description: "Give the final answer",
input: z.object({ summary: z.string(), total: z.number() }),
run: (input) => input,
})
const reply = await space.ai.chat("Add up this week’s orders.", {
model: "openai/gpt-oss-120b",
tools: { findOrders, answer },
maxSteps: 10,
stopWhen: toolCalled("answer"),
})
console.log(reply.toolResults.at(-1)?.output)Last updated