fix(models): route image input by preset capability (#6651)
* fix(providers): preserve images across retries and recovery Remove destructive text-only retries and validate tool image media at the boundary. Keep image identity across native transport preparation and compaction, and stop incomplete fallback or continuation without replaying tools. Resolves NAN-442 * fix(models): route image input by preset capability Replace the expanded image recovery and tool-format changes with an explicit supportsImages preset setting, capability-aware fallback selection, and an Image input switch in model settings. Keep original messages on retry and fail on actual non-transient image errors. * docs(models): introduce image input settings positively * test(agent): align image request fixtures with preset routing Cover successful image requests and direct validation errors when attributing model responses. Configure the image-capability check for the existing text-only provider mocks so governance and override-reuse tests exercise their scripted primary/fallback paths.
This commit is contained in:
1 parent
6a24b17629
commit
3f65a8f86c
36 files changed
+483
-444
No files matched your search
@@ -223,7 +223,6 @@ class FallbackProvider(LLMProvider):
|
||||
async def _run_chat_with_retry(
|
||||
self,
|
||||
kw: dict[str, Any],
|
||||
original_messages: list[dict[str, Any]],
|
||||
*,
|
||||
stream: bool,
|
||||
retry_mode: str,
|
||||
@@ -293,7 +292,6 @@ class FallbackProvider(LLMProvider):
|
||||
return await self._retry_with_fallback(
|
||||
_call_provider,
|
||||
call_kwargs,
|
||||
original_messages,
|
||||
retry_mode=retry_mode,
|
||||
on_retry_wait=on_retry_wait,
|
||||
on_retry_exhausted=on_retry_exhausted,
|
||||
@@ -348,7 +346,6 @@ class FallbackProvider(LLMProvider):
|
||||
self,
|
||||
call: Callable[[LLMProvider, dict[str, Any]], Awaitable[LLMResponse]],
|
||||
kwargs: dict[str, Any],
|
||||
original_messages: list[dict[str, Any]],
|
||||
*,
|
||||
retry_mode: str,
|
||||
on_retry_wait: RetryEventCallback | None,
|
||||
@@ -430,7 +427,6 @@ class FallbackProvider(LLMProvider):
|
||||
return await self._run_with_retry(
|
||||
_call_chain,
|
||||
dict(kwargs),
|
||||
original_messages,
|
||||
retry_mode="persistent",
|
||||
on_retry_wait=on_retry_wait,
|
||||
on_retry_exhausted=on_retry_exhausted,
|
||||
@@ -506,7 +502,12 @@ class FallbackProvider(LLMProvider):
|
||||
# continuation, so the incoming primary state remains reusable.
|
||||
preserve_primary_state = True
|
||||
|
||||
if self._primary_available():
|
||||
has_images = self._request_contains_images(kwargs["messages"], kwargs.get("provider_context"))
|
||||
image_error = self._primary._image_input_error(kwargs["messages"], kwargs.get("provider_context"))
|
||||
if image_error is not None:
|
||||
primary_response = image_error
|
||||
primary_error = image_error.content or primary_error
|
||||
elif self._primary_available():
|
||||
primary_was_attempted = True
|
||||
response, primary_exception = await self._call_provider(
|
||||
call, self._primary, kwargs
|
||||
@@ -563,6 +564,8 @@ class FallbackProvider(LLMProvider):
|
||||
last_response = primary_response
|
||||
primary_skipped = not primary_was_attempted
|
||||
for idx, fallback in enumerate(self._fallback_presets):
|
||||
if has_images and not fallback.supports_images:
|
||||
continue
|
||||
fallback_model = fallback.model
|
||||
if has_streamed is not None and has_streamed[0]:
|
||||
is_timeout = (
|
||||
@@ -579,7 +582,9 @@ class FallbackProvider(LLMProvider):
|
||||
await on_stream_recover()
|
||||
else:
|
||||
break
|
||||
if idx == 0 and primary_skipped:
|
||||
if image_error is not None:
|
||||
logger.info("Primary model '{}' does not accept images; trying '{}'", primary_model, fallback_model)
|
||||
elif idx == 0 and primary_skipped:
|
||||
logger.info(
|
||||
"Primary model '{}' circuit open, trying fallback '{}'",
|
||||
primary_model, fallback_model,
|
||||
|
||||
Reference in new issue
Block a user