{"record":{"id":"d76ff9171ab63902","repo":"danny-avila/LibreChat","slug":"no-tool-resource-provided-for-agent-file-upload","errorCode":null,"errorMessage":"No tool resource provided for agent file upload","messagePattern":"No tool resource provided for agent file upload","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/server/services/Files/process.js","lineNumber":678,"sourceCode":" * Saves file metadata to the database with an expiry TTL.\n * Files must be deleted from the server filesystem manually.\n *\n * @param {Object} params - The parameters object.\n * @param {ServerRequest} params.req - The Express request object.\n * @param {Express.Response} params.res - The Express response object.\n * @param {FileMetadata} params.metadata - Additional metadata for the file.\n * @param {import('@librechat/api').UploadSseStream | null} [params.sseStream] - Active upload SSE stream, if enabled.\n * @returns {Promise<void>}\n */\nconst processAgentFileUpload = async ({ req, res, metadata, sseStream }) => {\n  const { file } = req;\n  const appConfig = req.config;\n  const { agent_id, tool_resource, file_id, temp_file_id = null } = metadata;\n\n  let messageAttachment = !!metadata.message_file;\n\n  if (agent_id && !tool_resource && !messageAttachment) {\n    throw new Error('No tool resource provided for agent file upload');\n  }\n\n  if (tool_resource === EToolResources.file_search && file.mimetype.startsWith('image')) {\n    throw new Error('Image uploads are not supported for file search tool resources');\n  }\n\n  if (!messageAttachment && !agent_id) {\n    throw new Error('No agent ID provided for agent file upload');\n  }\n\n  const isImage = file.mimetype.startsWith('image');\n  let fileInfoMetadata;\n  const entity_id = messageAttachment === true ? undefined : agent_id;\n  const basePath = mime.getType(file.originalname)?.startsWith('image') ? 'images' : 'uploads';\n  if (tool_resource === EToolResources.execute_code) {\n    const isCodeEnabled = await checkCapability(req, AgentCapabilities.execute_code);\n    if (!isCodeEnabled) {\n      throw new Error('Code execution is not enabled for Agents');","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/process.js#L660-L696","documentation":"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.","triggerScenarios":"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).","commonSituations":"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`.","solutions":["Include `tool_resource` (e.g., `file_search`, `execute_code`, `context`) in the upload metadata when uploading to an agent.","If the file is a chat attachment, set `message_file: true` in metadata so it routes as a messageAttachment.","Validate the request shape on the client before submit: `if (agent_id && !tool_resource && !message_file) return error;`.","Audit the frontend upload handler for the flow that triggered this — the field is likely being dropped conditionally."],"exampleFix":"// before\nfetch('/api/files', { body: formData }); // formData has agent_id only\n\n// after\nformData.append('tool_resource', 'file_search');\n// or, if it is a chat attachment:\nformData.append('message_file', 'true');","handlingStrategy":"validation","validationCode":"function validateAgentUploadMetadata(metadata) {\n  const { agent_id, tool_resource, message_file } = metadata;\n  if (agent_id && !tool_resource && !message_file) {\n    return 'tool_resource is required for agent uploads (or set message_file)';\n  }\n  return null;\n}","typeGuard":null,"tryCatchPattern":"try { await processAgentFileUpload({ req, res, metadata }); }\ncatch (e) {\n  if (/No tool resource provided/.test(e.message)) return res.status(400).json({ error: e.message });\n  throw e;\n}","preventionTips":["Always pair `agent_id` with a `tool_resource` (or `message_file: true`) in upload metadata.","Validate the metadata shape on the client before submit.","Audit frontend upload flows that conditionally drop tool_resource."],"tags":["agent","file-upload","metadata","validation"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}