remainingToolRounds (agents/stepBudget.ts)

librechat · packages/api/src/agents/stepBudget.ts · typescript · MIT
ai, tag:knn-classified

Utility to compute remaining tool rounds and generate budget notices for agent loops.

// Source: https://github.com/danny-avila/librechat | License: MIT | Copyright 2026 LibreChat
// Provided via justclaw.it.com; keep this notice with the code.
import { logger } from '@librechat/data-schemas';
import type { HookCallback } from '@librechat/agents';

/**
 * Graph supersteps a single tool-calling round costs: the tool node that runs the
 * batch, plus the model node that consumes its results. Derived from the agent
 * graph topology (`agentNode -> toolNode -> agentNode`), the same relationship the
 * `com_ui_agent_recursion_limit_info` copy describes to admins and that
 * `SUBAGENT_RECURSION_MULTIPLIER` encodes for child runs.
 */
const STEPS_PER_TOOL_ROUND = 2;

/**
 * Supersteps reserved for the final model call that answers without calling tools.
 * A turn that spends its l

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key