danny-avila/LibreChat · error · Error
This tool is only available for agents.
Error message
This tool is only available for agents.
What it means
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.
Source
Thrown at api/app/clients/tools/structured/GeminiImageGen.js:316
promptTokens,
completionTokens,
},
);
} catch (error) {
logger.error('[GeminiImageGen] Error recording token usage:', error);
}
}
/**
* Creates Gemini Image Generation tool
* @param {Object} fields - Configuration fields
* @returns {ReturnType<tool>} - The image generation tool
*/
function createGeminiImageTool(fields = {}) {
const override = fields.override ?? false;
if (!override && !fields.isAgent) {
throw new Error('This tool is only available for agents.');
}
const { req, imageFiles = [], userId, fileStrategy, GEMINI_API_KEY, GOOGLE_KEY } = fields;
const imageOutputType = fields.imageOutputType || EImageOutputType.PNG;
const geminiImageGenTool = tool(
async ({ prompt, image_ids, aspectRatio, imageSize }, runnableConfig) => {
if (!prompt) {
throw new Error('Missing required field: prompt');
}
logger.debug('[GeminiImageGen] Generating image', { aspectRatio, imageSize });
let ai;
try {
ai = await initializeGeminiClient({
GEMINI_API_KEY,View on GitHub (pinned to 5ff282f900)
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.
Example fix
// before
const tools = createGeminiImageTool({ req }); // throws: not an agent
// after — agent path
const tools = createGeminiImageTool({ req, isAgent: true });
// or — bootstrap/manifest only
const tools = createGeminiImageTool({ override: true }); Defensive patterns
Strategy: validation
Validate before calling
function assertAgentFactory(fields = {}) {
if (!fields.override && !fields.isAgent) {
throw new Error('createGeminiImageTool requires isAgent:true (or override:true for bootstrap).');
}
} Type guard
function isAgentFactoryCall(fields) {
return Boolean(fields?.override || fields?.isAgent);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- This tool is only available for agents.
- Gemini Image Generation requires one of: user-provided API k
- Missing required field: prompt
- You no longer have access to subagent ${agentId}.
- User ID not found in blob path
AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12).
Data as JSON: /api/errors/0c360221fe652846.
Report an issue: GitHub.