Files
somew1nd a45daf23f8 feat: add agentic video analysis and clarify action results
Report device actions as dispatched and preserve full failure details. Route
Flash through McpActionExecutor and use ToolFailure across helper tools and
agent loops instead of inferring failure from response text.

Require model-provided descriptions for coordinate targets. Keep observed
element metadata separate from those descriptions in safety checks, visual
summaries, history, and frontend labels.

Add Gemini Interactions API video analysis with configurable processing mode,
chunk size, and timeouts. Centralize Google provider capabilities and token
usage normalization, and update google-genai to 2.22.0.

Preserve system instructions on follow-up interactions, replan pending chunks
when falling back to static processing, and reject unanswered native video
and audio segments instead of caching placeholder results. Keep helper-tool
failure status intact through history tools and committee calls.

Validation: 1,762 Python unit tests passed (3 skipped), 40 frontend formatter
tests passed, and the production UI build completed. Ruff lint, formatting,
the quality ratchet, and git diff checks passed.
2026-09-08 17:05:54 -07:00

57 lines
2.0 KiB
Python

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Typed failures for text-returning helper tools.
Tools return ``ToolFailure`` on failure; callers use ``is_tool_failure`` to
check the result. The str subclass keeps results compatible with text consumers
without treating words such as "Error" in tool output as a failure signal.
Pydantic converts str subclasses to plain strings in ``ToolMessage.content``
and ``ToolExecutionResult.text_summary``. Check the raw result before wrapping
it and pass ``status="error"`` to preserve the failure state.
"""
from typing import Any
from langchain_core.messages import ToolMessage
class ToolFailure(str):
"""A helper tool's failure report, carried as the text the agent reads."""
__slots__ = ()
def is_tool_failure(result: Any) -> bool:
"""Whether a tool result reports failure.
True for a ``ToolMessage`` whose ``status`` is ``"error"``, for a
:class:`ToolFailure` text, and for a content-block list whose text is a
:class:`ToolFailure`. Plain strings are never failures, whatever they say.
"""
if isinstance(result, ToolMessage):
if result.status == "error":
return True
result = result.content
if isinstance(result, ToolFailure):
return True
if isinstance(result, list):
for block in result:
if isinstance(block, ToolFailure):
return True
if isinstance(block, dict) and isinstance(block.get("text"), ToolFailure):
return True
return False