danny-avila/LibreChat · error · Error

${validation.error?.message}

Error message

${validation.error?.message}

What it means

discoverConnectedAgents validates each handoff sub-agent's model configuration via validateAgentModel. If validation.isValid is false, the error message from validation.error is re-thrown. Note: because the throw uses validation.error?.message, if error itself is undefined the thrown Error will have message 'undefined' — so a missing error object produces a confusing message.

Source

Thrown at packages/api/src/agents/discovery.ts:256

    if (!hasAccess) {
      logger.warn(
        `[discoverConnectedAgents] User ${userId} lacks VIEW access to handoff agent ${agentId}, skipping`,
      );
      markSkipped(agentId);
      return null;
    }

    const validation = await validateAgentModel({
      req,
      res,
      agent,
      modelsConfig,
      logViolation,
    });

    if (!validation.isValid) {
      throw new Error(validation.error?.message);
    }

    /**
     * Force `endpoint: agents` on the per-sub-agent init call so
     * `initializeAgent`'s `isAgentsEndpoint`-gated `allowedProviders`
     * check always fires for handoff sub-agents, regardless of which
     * endpoint the caller entered through. Without this, the OpenAI-
     * compat routes (whose `endpointOption.endpoint` is the primary
     * provider, not `agents`) would silently bypass the provider
     * allowlist configured under `endpoints.agents.allowedProviders`.
     */
    const subAgentEndpointOption: Partial<TEndpointOption> = {
      ...(endpointOption ?? {}),
      endpoint: EModelEndpoint.agents,
    };

    const scopedSkillIds = computeAccessibleSkillIds?.(agent);
    const config = await initializeAgent(

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Inspect validation.error.message in the logs (or reproduce via validateAgentModel directly) to see the specific model/provider violation.
  2. Correct the sub-agent's model and provider in the agent definition to one allowed by endpoints.agents.allowedProviders.
  3. Add the missing provider/model to the allowedProviders config if the restriction is too tight.
  4. If validation.error is undefined in your logs, the agent definition is in an unexpected state — re-save it.

Example fix

// before — rethrow loses context when error is undefined
if (!validation.isValid) {
  throw new Error(validation.error?.message);
}

// after — surface a clear message and keep the cause
if (!validation.isValid) {
  throw new Error(
    validation.error?.message ?? `Agent ${agent._id} failed model validation`,
    { cause: validation.error },
  );
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate sub-agent model before discovery
const v = await validateAgentModel({ req, res, agent, modelsConfig, logViolation });
if (!v.isValid) {
  throw new Error(v.error?.message ?? `Agent ${agent._id} failed model validation`);
}

Type guard

const hasModelViolation = (e: unknown): boolean =>
  e instanceof Error && /model|provider|allowedProviders/i.test(e.message);

Try / catch

try {
  await discoverConnectedAgents({ ... });
} catch (error) {
  if (error instanceof Error && /model|provider|allowedProviders/i.test(error.message)) {
    res.status(400).json({ error: `Handoff sub-agent misconfigured: ${error.message}` });
    return;
  }
  throw error;
}

Prevention

When it happens

Trigger: An agent referenced as a handoff sub-agent whose model configuration is invalid: missing model, mismatched provider, model not in the allowedProviders list, or endpointOption.endpoint not permitted by endpoints.agents.allowedProviders.

Common situations: An agent saved with a model id that was later removed from the provider; sub-agent's provider not in the agents allowlist; OpenAI-compat route used to reach an agent whose handoff target is on a disallowed provider; deleted API key for the sub-agent's provider.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/d0947f02036c5098. Report an issue: GitHub.