992 B
992 B
layout
| layout |
|---|
| default |
toolCallLimitMiddleware: Limitar Tools
import { createAgent, toolCallLimitMiddleware } from "langchain";
const agent = createAgent({
model: "mistral:mistral-large-latest",
tools: [searchTool, databaseTool, scraperTool],
middleware: [
// Límite global: máx 20 por thread, 10 por run
toolCallLimitMiddleware({ threadLimit: 20, runLimit: 10 }),
// Límite específico para búsquedas
toolCallLimitMiddleware({
toolName: "search",
threadLimit: 5,
runLimit: 3,
}),
// Límite estricto para scraping (lanza error si excede)
toolCallLimitMiddleware({
toolName: "scrape_webpage",
runLimit: 2,
exitBehavior: "error", // "continue" | "error" | "end"
}),
],
});
Requiere checkpointer para `threadLimit`. `runLimit` se resetea en cada invocación.