{"record":{"id":"0588a6839d6d9730","repo":"danny-avila/LibreChat","slug":"no-agent-id-provided-for-agent-file-upload","errorCode":null,"errorMessage":"No agent ID provided for agent file upload","messagePattern":"No agent ID provided for agent file upload","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/server/services/Files/process.js","lineNumber":686,"sourceCode":" * @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');\n    }\n    const { handleFileUpload: uploadCodeEnvFile } = getStrategyFunctions(FileSources.execute_code);\n    const stream = fs.createReadStream(file.path);\n    /* Resource identity for codeapi's sessionKey:\n     * - chat attachments (messageAttachment=true): `kind: 'user'`, codeapi\n     *   buckets under `<tenant>:user:<authContext.userId>` regardless of `id`.\n     * - agent setup files (messageAttachment=false): `kind: 'agent'`, shared\n     *   per agent identity. `id` carries the agent id. */","sourceCodeStart":668,"sourceCodeEnd":704,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/process.js#L668-L704","documentation":"Thrown when there is no `agent_id` and the upload is not a `messageAttachment` (metadata.message_file). The contract is mutually exclusive: an agent upload needs an agent_id, OR the upload must be flagged as a chat message attachment. Without either, the server has no entity to bind the file to.","triggerScenarios":"POST to the agent file upload endpoint with metadata that omits both `agent_id` and `message_file`. Common when a generic upload call is reused without context, or a frontend drops the agent_id field when no agent is selected.","commonSituations":"Client integration calling the endpoint without agent context; a frontend bug where the agent_id form field is conditionally rendered and absent; a malformed curl/test script.","solutions":["Provide `agent_id` in metadata when uploading to an agent.","Or set `message_file: true` to upload as a chat attachment bound to the user.","Validate client-side: `if (!agent_id && !message_file) return error;` before submit.","If you reached this branch unexpectedly, log the metadata payload — a field is missing upstream."],"exampleFix":"// before\nmetadata: { tool_resource: 'file_search' }\n\n// after\nmetadata: { agent_id: req.body.agent_id, tool_resource: 'file_search' }","handlingStrategy":"validation","validationCode":"function validateAgentUploadMetadata(metadata) {\n  const { agent_id, message_file } = metadata;\n  if (!agent_id && !message_file) {\n    return 'Either agent_id or message_file must be provided';\n  }\n  return null;\n}","typeGuard":null,"tryCatchPattern":"try { await processAgentFileUpload({ req, res, metadata }); }\ncatch (e) {\n  if (/No agent ID provided/.test(e.message)) return res.status(400).json({ error: e.message });\n  throw e;\n}","preventionTips":["Always send either agent_id or message_file in upload metadata.","Client-side: prevent submit if neither is present.","Log the full metadata payload when this fires to find the dropped field."],"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"}