JuliusBrussee/caveman · error

caveman agent: subagent maxInputChars must be a positive…

Error message

caveman agent: subagent maxInputChars must be a positive integer

What it means

The subagent() tool factory validates maxInputChars (default 32768) and throws if it is not a positive safe integer, i.e. zero, negative, non-integer, or beyond Number.MAX_SAFE_INTEGER are all rejected. The option caps how many input characters a subagent invocation may receive.

Solutions

  1. Omit maxInputChars to use the 32_768 default
  2. Pass a positive safe integer (e.g. 65536) parsed with Number.parseInt and validated with Number.isSafeInteger
  3. Clamp: maxInputChars = Math.max(1, Math.floor(value)) after parsing
  4. Fix the config source so the value is numeric, not a string/NaN

Example fix

// before
subagent({ maxInputChars: Number(process.env.SUBAGENT_LIMIT) }); // NaN if unset
// after
const n = Number.parseInt(process.env.SUBAGENT_LIMIT ?? "32768", 10);
subagent({ maxInputChars: Number.isSafeInteger(n) && n > 0 ? n : 32768 });
Defensive patterns

Strategy: validation

Validate before calling

const n = options.maxInputChars ?? 32768;
if (!Number.isSafeInteger(n) || n <= 0) throw new Error("maxInputChars must be a positive integer");

Type guard

const isValidMaxInputChars = (v) => v === undefined || (Number.isSafeInteger(v) && v > 0);

Try / catch

try { tool = subagent(opts); } catch (err) { if (String(err.message).includes("maxInputChars must be a positive integer")) { tool = subagent({ ...opts, maxInputChars: 32768 }); } else throw err; }

Prevention

When it happens

Trigger: subagent({ maxInputChars: 0 }) or -1; passing a float like 1024.5; passing Infinity/NaN (e.g. from a misparsed config value); passing a string from env config without parsing.

Common situations: Reading the limit from config/env where an empty string or 'unlimited' becomes NaN; attempting to disable the cap with 0; arithmetic producing fractional values.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/c38ca2a3640da1d0. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/index.ts:169

  maxInputChars?: number;
  maxCalls?: number;
  /**
   * This child's wallet in USD. Under a USD-metered run the wallet is carved
   * out of the parent's **remaining** budget when the child is spawned, and its
   * unspent remainder returns to the parent when the child finishes.
   */
  maxCostUsd?: number;
  /**
   * This child's wallet in tokens — the denomination sibling of `maxCostUsd`,
   * used by a token-metered run. A token-metered run cannot fund a subagent
   * that declares no token wallet.
   */
  maxTokens?: number;
  maxContextTokens?: number;
}): ToolDefinition {
  const maxInputChars = options.maxInputChars ?? 32_768;
  if (!Number.isSafeInteger(maxInputChars) || maxInputChars <= 0) {
    throw new Error("caveman agent: subagent maxInputChars must be a positive integer");
  }
  const maxCalls = options.maxCalls ?? 1;
  const maxCostUsd = options.maxCostUsd ?? 1;
  const maxContextTokens = options.maxContextTokens ?? 128_000;
  if (!Number.isSafeInteger(maxCalls) || maxCalls <= 0) {
    throw new Error("caveman agent: subagent maxCalls must be a positive integer");
  }
  if (!Number.isFinite(maxCostUsd) || maxCostUsd <= 0) {
    throw new Error("caveman agent: subagent maxCostUsd must be positive");
  }
  if (options.maxTokens !== undefined &&
      (!Number.isSafeInteger(options.maxTokens) || options.maxTokens <= 0)) {
    throw new Error("caveman agent: subagent maxTokens must be a positive integer");
  }
  if (!Number.isSafeInteger(maxContextTokens) || maxContextTokens <= 0) {
    throw new Error("caveman agent: subagent maxContextTokens must be a positive integer");
  }
  return tool({

View on GitHub (pinned to 3ee70a1026)