danny-avila/LibreChat · error

No tool resource provided for agent file upload

Error message

No tool resource provided for agent file upload

What it means

Thrown by processAgentFileUpload when `agent_id` is present but neither `tool_resource` nor `messageAttachment` (metadata.message_file) is provided. The contract is: an agent-targeted upload must declare which tool resource bucket the file belongs to, unless it is a chat message attachment. Without a tool_resource the server cannot decide where to store or how to route the file.

Source

Thrown at api/server/services/Files/process.js:678

 * Saves file metadata to the database with an expiry TTL.
 * Files must be deleted from the server filesystem manually.
 *
 * @param {Object} params - The parameters object.
 * @param {ServerRequest} params.req - The Express request object.
 * @param {Express.Response} params.res - The Express response object.
 * @param {FileMetadata} params.metadata - Additional metadata for the file.
 * @param {import('@librechat/api').UploadSseStream | null} [params.sseStream] - Active upload SSE stream, if enabled.
 * @returns {Promise<void>}
 */
const processAgentFileUpload = async ({ req, res, metadata, sseStream }) => {
  const { file } = req;
  const appConfig = req.config;
  const { agent_id, tool_resource, file_id, temp_file_id = null } = metadata;

  let messageAttachment = !!metadata.message_file;

  if (agent_id && !tool_resource && !messageAttachment) {
    throw new Error('No tool resource provided for agent file upload');
  }

  if (tool_resource === EToolResources.file_search && file.mimetype.startsWith('image')) {
    throw new Error('Image uploads are not supported for file search tool resources');
  }

  if (!messageAttachment && !agent_id) {
    throw new Error('No agent ID provided for agent file upload');
  }

  const isImage = file.mimetype.startsWith('image');
  let fileInfoMetadata;
  const entity_id = messageAttachment === true ? undefined : agent_id;
  const basePath = mime.getType(file.originalname)?.startsWith('image') ? 'images' : 'uploads';
  if (tool_resource === EToolResources.execute_code) {
    const isCodeEnabled = await checkCapability(req, AgentCapabilities.execute_code);
    if (!isCodeEnabled) {
      throw new Error('Code execution is not enabled for Agents');

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Include `tool_resource` (e.g., `file_search`, `execute_code`, `context`) in the upload metadata when uploading to an agent.
  2. If the file is a chat attachment, set `message_file: true` in metadata so it routes as a messageAttachment.
  3. Validate the request shape on the client before submit: `if (agent_id && !tool_resource && !message_file) return error;`.
  4. Audit the frontend upload handler for the flow that triggered this — the field is likely being dropped conditionally.

Example fix

// before
fetch('/api/files', { body: formData }); // formData has agent_id only

// after
formData.append('tool_resource', 'file_search');
// or, if it is a chat attachment:
formData.append('message_file', 'true');
Defensive patterns

Strategy: validation

Validate before calling

function validateAgentUploadMetadata(metadata) {
  const { agent_id, tool_resource, message_file } = metadata;
  if (agent_id && !tool_resource && !message_file) {
    return 'tool_resource is required for agent uploads (or set message_file)';
  }
  return null;
}

Try / catch

try { await processAgentFileUpload({ req, res, metadata }); }
catch (e) {
  if (/No tool resource provided/.test(e.message)) return res.status(400).json({ error: e.message });
  throw e;
}

Prevention

When it happens

Trigger: POST to the agent file upload endpoint with `agent_id` in metadata but omitting `tool_resource` and `message_file`. Common with direct API use or a frontend bug that drops the field on certain UI flows (e.g., uploading to an agent without first selecting a tool).

Common situations: Frontend form forgets to include `tool_resource` when the user picks an agent but no tool context; a client integration sending partial metadata; an admin testing the endpoint manually with only `agent_id`.

Related errors


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