Add opt-in deferred image generation in code mode (#63594)

## What changed

Add `features.defer_image_generation` so code mode can discover the image
generation tool through `ALL_TOOLS` without including its definition in
the initial model request. Direct exposure remains the default and
applies when `image_gen` is excluded from code mode.

## Testing

Update the app-server GIF edit test to discover and invoke the deferred
tool through code mode. Verify that the initial request omits the tool
definition, the discovered definition includes the GIF option, and the
edit preserves animation and API defaults.

GitOrigin-RevId: 899f689bae0b86099a0ca3736d1cd2576bc3a7a9
This commit is contained in:
verma-oai
2026-11-24 09:52:16 +00:00
committed by copyberry
parent d4b84f9bb0
commit 37aeac06b3
5 changed files with 49 additions and 10 deletions
@@ -14,8 +14,10 @@ use codex_extension_api::ToolExecutor;
use codex_http_client::HttpClientFactory;
use codex_login::AuthManager;
use codex_model_provider_info::ModelProviderInfo;
use codex_tools::ToolExposure;
use codex_utils_absolute_path::AbsolutePathBuf;
use crate::IMAGE_GEN_NAMESPACE;
use crate::backend::CodexImagesBackend;
use crate::tool::ImageGenerationTool;
@@ -31,6 +33,7 @@ type SaveRootResolver = dyn Fn(&Config) -> Option<AbsolutePathBuf> + Send + Sync
struct ImageGenerationExtensionConfig {
available: bool,
gif_enabled: bool,
defer_image_generation: bool,
http_client_factory: HttpClientFactory,
provider: ModelProviderInfo,
save_root: Option<AbsolutePathBuf>,
@@ -44,6 +47,12 @@ impl ImageGenerationExtensionConfig {
|| config.model_provider.requires_openai_auth
|| config.model_provider.uses_openai_actor_authorization(),
gif_enabled: config.features.image_generation_animation_enabled(),
defer_image_generation: config.features.defer_image_generation_enabled()
&& !config
.code_mode
.excluded_tool_namespaces
.iter()
.any(|namespace| namespace == IMAGE_GEN_NAMESPACE),
http_client_factory: config.http_client_factory(),
provider: config.model_provider.clone(),
save_root: resolve_save_root(config),
@@ -106,6 +115,11 @@ impl ToolContributor for ImageGenerationExtension {
})
});
let exposure = if config.defer_image_generation {
ToolExposure::Deferred
} else {
ToolExposure::Direct
};
vec![Arc::new(ImageGenerationTool::new(
CodexImagesBackend::new(
auth.model_provider(config.provider.clone()),
@@ -117,6 +131,7 @@ impl ToolContributor for ImageGenerationExtension {
config.save_root.clone(),
thread_store.level_id().to_string(),
config.gif_enabled,
exposure,
))]
}
}
+4 -2
View File
@@ -81,6 +81,7 @@ pub(crate) struct ImageGenerationTool {
save_root: Option<AbsolutePathBuf>,
thread_id: String,
gif_enabled: bool,
exposure: ToolExposure,
}
impl ImageGenerationTool {
@@ -90,12 +91,14 @@ impl ImageGenerationTool {
save_root: Option<AbsolutePathBuf>,
thread_id: String,
gif_enabled: bool,
exposure: ToolExposure,
) -> Self {
Self {
backend,
save_root,
thread_id,
gif_enabled,
exposure,
}
}
}
@@ -148,9 +151,8 @@ impl<'call> ToolExecutor<ToolCall<'call>> for ImageGenerationTool {
imagegen_tool_spec(self.gif_enabled)
}
/// Exposes image generation directly and through the nested code-mode tool surface.
fn exposure(&self) -> ToolExposure {
ToolExposure::Direct
self.exposure
}
/// Executes the selected image operation and returns the completed image result.