{"record":{"id":"0c360221fe652846","repo":"danny-avila/LibreChat","slug":"this-tool-is-only-available-for-agents","errorCode":null,"errorMessage":"This tool is only available for agents.","messagePattern":"This tool is only available for agents\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/app/clients/tools/structured/GeminiImageGen.js","lineNumber":316,"sourceCode":"        promptTokens,\n        completionTokens,\n      },\n    );\n  } catch (error) {\n    logger.error('[GeminiImageGen] Error recording token usage:', error);\n  }\n}\n\n/**\n * Creates Gemini Image Generation tool\n * @param {Object} fields - Configuration fields\n * @returns {ReturnType<tool>} - The image generation tool\n */\nfunction createGeminiImageTool(fields = {}) {\n  const override = fields.override ?? false;\n\n  if (!override && !fields.isAgent) {\n    throw new Error('This tool is only available for agents.');\n  }\n\n  const { req, imageFiles = [], userId, fileStrategy, GEMINI_API_KEY, GOOGLE_KEY } = fields;\n\n  const imageOutputType = fields.imageOutputType || EImageOutputType.PNG;\n\n  const geminiImageGenTool = tool(\n    async ({ prompt, image_ids, aspectRatio, imageSize }, runnableConfig) => {\n      if (!prompt) {\n        throw new Error('Missing required field: prompt');\n      }\n\n      logger.debug('[GeminiImageGen] Generating image', { aspectRatio, imageSize });\n\n      let ai;\n      try {\n        ai = await initializeGeminiClient({\n          GEMINI_API_KEY,","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/app/clients/tools/structured/GeminiImageGen.js#L298-L334","documentation":"Construction-time guard in createGeminiImageTool: the Gemini image tool is intentionally restricted to the agent execution path. If `fields.override` is false AND `fields.isAgent` is not truthy, the factory throws before building the tool. This prevents the tool from being registered for legacy (non-agent) request flows.","triggerScenarios":"Calling createGeminiImageTool() from a code path that does not pass `isAgent: true` and is not an app-bootstrap call (where override:true is expected). Typically a non-agent endpoint or a manual/programmatic instantiation.","commonSituations":"Wiring the Gemini image tool into a legacy assistant/non-agent tool registry; a refactor that lost the isAgent flag when forwarding fields; testing the factory directly without setting either flag; a custom route that tries to use the tool outside the agent controller.","solutions":["Only construct this tool from the agent tool-loading path, which sets `isAgent: true` on fields.","For app/manifest initialization where no call will be made, pass `override: true`.","If you need image generation outside agents, use the dedicated non-agent image endpoint instead of this tool.","Audit the call site to confirm `fields` is being forwarded with isAgent intact from the request context."],"exampleFix":"// before\nconst tools = createGeminiImageTool({ req }); // throws: not an agent\n\n// after — agent path\nconst tools = createGeminiImageTool({ req, isAgent: true });\n// or — bootstrap/manifest only\nconst tools = createGeminiImageTool({ override: true });","handlingStrategy":"validation","validationCode":"function assertAgentFactory(fields = {}) {\n  if (!fields.override && !fields.isAgent) {\n    throw new Error('createGeminiImageTool requires isAgent:true (or override:true for bootstrap).');\n  }\n}","typeGuard":"function isAgentFactoryCall(fields) {\n  return Boolean(fields?.override || fields?.isAgent);\n}","tryCatchPattern":null,"preventionTips":["Only call createGeminiImageTool from the agent tool-loading path.","Forward fields unchanged through the agent controller so isAgent survives.","Use override:true exclusively for manifest/bootstrap."],"tags":["gemini","agent-only","authorization","tool-factory"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}