























@@ -379,22 +379,37 @@ export function createImageTool(options?: {
379379fsPolicy?: ToolFsPolicy;
380380/** If true, the model has native vision capability and images in the prompt are auto-injected */
381381modelHasVision?: boolean;
382+/**
383+ * Avoid resolving auto image-provider/model candidates while registering the
384+ * tool. The concrete image model is still resolved before execution.
385+ */
386+deferAutoModelResolution?: boolean;
382387}): AnyAgentTool | null {
383388const agentDir = options?.agentDir?.trim();
389+const explicit = coerceImageModelConfig(options?.config);
384390if (!agentDir) {
385-const explicit = coerceImageModelConfig(options?.config);
386391if (hasToolModelConfig(explicit)) {
387392throw new Error("createImageTool requires agentDir when enabled");
388393}
389394return null;
390395}
391-const imageModelConfig = resolveImageModelConfigForTool({
392-cfg: options?.config,
393- agentDir,
394-workspaceDir: options?.workspaceDir,
395-authStore: options?.authProfileStore,
396-});
397-if (!imageModelConfig) {
396+const explicitImageModelConfig = hasToolModelConfig(explicit)
397+ ? resolveConfiguredImageModelRefs({
398+cfg: options?.config,
399+imageModelConfig: explicit,
400+})
401+ : null;
402+const shouldResolveAutoImageModel =
403+!explicitImageModelConfig && !options?.deferAutoModelResolution;
404+const resolvedImageModelConfig = shouldResolveAutoImageModel
405+ ? resolveImageModelConfigForTool({
406+cfg: options?.config,
407+ agentDir,
408+workspaceDir: options?.workspaceDir,
409+authStore: options?.authProfileStore,
410+})
411+ : explicitImageModelConfig;
412+if (!resolvedImageModelConfig && !options?.deferAutoModelResolution) {
398413return null;
399414}
400415const remoteMediaSsrfPolicy = resolveRemoteMediaSsrfPolicy(options?.config);
@@ -403,7 +418,9 @@ export function createImageTool(options?: {
403418// so this tool is only needed when image wasn't provided in the prompt
404419const description = options?.modelHasVision
405420 ? "Analyze one or more images with a vision model. Use image for a single path/URL, or images for multiple (up to 20). Only use this tool when images were NOT already provided in the user's message. Images mentioned in the prompt are automatically visible to you."
406- : "Analyze one or more images with the configured image model (agents.defaults.imageModel). Use image for a single path/URL, or images for multiple (up to 20). Provide a prompt describing what to analyze.";
421+ : explicitImageModelConfig
422+ ? "Analyze one or more images with the configured image model (agents.defaults.imageModel). Use image for a single path/URL, or images for multiple (up to 20). Provide a prompt describing what to analyze."
423+ : "Analyze one or more images with an available vision model. Use image for a single path/URL, or images for multiple (up to 20). Provide a prompt describing what to analyze.";
407424408425return {
409426label: "Image",
@@ -603,6 +620,19 @@ export function createImageTool(options?: {
603620}
604621605622// MARK: - Run image prompt with all loaded images
623+const imageModelConfig =
624+resolvedImageModelConfig ??
625+resolveImageModelConfigForTool({
626+cfg: options?.config,
627+ agentDir,
628+workspaceDir: options?.workspaceDir,
629+authStore: options?.authProfileStore,
630+});
631+if (!imageModelConfig) {
632+throw new Error(
633+"No image model is configured. Set agents.defaults.imageModel or configure an image-capable provider.",
634+);
635+}
606636const result = await runImagePrompt({
607637cfg: options?.config,
608638 agentDir,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。