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.
This commit is contained in:
somew1nd committed 2026-09-08 17:05:54 -07:00
1 parent 611d1a0947
commit a45daf23f8
120 files changed
+6301 -1710

No files matched your search

+127
View File
@@ -14,12 +14,15 @@
from unittest.mock import AsyncMock, MagicMock, patch
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage
from langchain_core.tools import StructuredTool
import pytest
from artemis.agents.checker.checker import (
CheckReport,
CheckVerdict,
_normalize_report,
_run_check_loop,
assemble_checker_prompt_segments,
build_checker_tools,
build_probe_argv,
@@ -28,6 +31,7 @@ from artemis.agents.checker.checker import (
verdicts_allow_release,
)
from artemis.context import ArtemisContext, ExecutionSetup
from artemis.core.tool_failure import ToolFailure
from artemis.graph.checkpoints import EvidenceAnchor
from artemis.utils.plan_grammar import CheckItem
@@ -569,3 +573,126 @@ async def test_no_transcript_without_attempt_id_or_streamed_text(tmp_path):
assert _read_streams(tmp_path) == []
assert not (tmp_path / "check_streams.jsonl").exists()
# --- Probe failures are structural; history rows keep target provenance ---------------
@pytest.mark.asyncio
async def test_probe_device_invalid_kind_is_a_tool_failure():
"""A refused probe answers with a ToolFailure, so the tool loop marks the
ToolMessage as an error structurally rather than by sniffing its wording."""
from artemis.agents.checker.checker import get_probe_tool
from artemis.core.tool_failure import is_tool_failure
tool = get_probe_tool(_mock_ctx(disable_device_probes=False))
result = await tool.ainvoke({"kind": "shell", "params": None})
assert is_tool_failure(result)
assert "Error" in str(result)
@pytest.mark.asyncio
async def test_probe_device_execution_error_is_a_tool_failure():
from artemis.agents.checker.checker import get_probe_tool
from artemis.core.tool_failure import is_tool_failure
ctx = _mock_ctx(disable_device_probes=False)
ctx.get_adb_client.side_effect = RuntimeError("no adb")
tool = get_probe_tool(ctx)
result = await tool.ainvoke({"kind": "battery", "params": None})
assert is_tool_failure(result)
assert "no adb" in str(result)
def test_format_history_marks_self_described_targets_only():
"""A step without a summary renders its action through the shared renderer,
so the Checker sees which target labels are the model's own statement."""
from artemis.agents.checker.checker import _format_history
from artemis.utils.task_tree import SELF_DESCRIBED_MARKER
ctx = _mock_ctx()
ctx.data_engine.get_agent_friendly_steps.return_value = [
{
"step_number": 1,
"relative_time": "T+00:01",
"summary": "",
"action_taken": {
"action": "click",
"coordinates": [500, 600],
"target_description": "play button",
},
},
{
"step_number": 2,
"relative_time": "T+00:05",
"summary": None,
"action_taken": {
"action": "click",
"coordinates": [100, 200],
"target_text": "Login",
"target_resource_id": "com.app:id/login",
},
},
]
text = _format_history(ctx)
lines = text.splitlines()
assert lines[0].startswith("- Step 1 (T+00:01): ")
assert f"'play button' {SELF_DESCRIBED_MARKER}" in lines[0]
assert lines[1].startswith("- Step 2 (T+00:05): ")
assert "'Login'" in lines[1]
assert SELF_DESCRIBED_MARKER not in lines[1]
# Neither row is the raw JSON record.
assert "target_description" not in text
assert "target_resource_id" not in text
# --- tool results: status is structural, never sniffed from the words -----------------
# A helper tool reports failure structurally (``ToolFailure``); free-form text
# that merely starts with "Error" is an ordinary answer.
_STATUS_CASES = [
pytest.param(ToolFailure("Error: note 'progress' not found"), "error", id="tool_failure"),
pytest.param("Error 404 was typed into the search box", "success", id="plain_error_text"),
]
def _text_tool(name: str, result):
async def _run(key: str) -> str:
return result
return StructuredTool.from_function(coroutine=_run, name=name, description=name)
@pytest.mark.asyncio
@pytest.mark.parametrize("result, expected_status", _STATUS_CASES)
async def test_check_loop_tool_message_status_is_structural(result, expected_status):
ctx = _mock_ctx()
tool = _text_tool("read_note", result)
tool_turn = AIMessage(
content="", tool_calls=[{"name": "read_note", "args": {"key": "progress"}, "id": "c1"}]
)
final_turn = AIMessage(content="done", tool_calls=[])
llm = MagicMock()
llm.bind_tools.return_value = llm
llm.with_structured_output.return_value.ainvoke = AsyncMock(
return_value=CheckReport(verdicts=[])
)
messages = [SystemMessage(content="s"), HumanMessage(content="h")]
with (
patch("artemis.agents.checker.checker.get_llm", return_value=llm),
patch(
"artemis.agents.checker.checker.acomplete",
new=AsyncMock(side_effect=[tool_turn, final_turn]),
),
):
await _run_check_loop(ctx, messages, [tool], check_items=[])
tool_msgs = [m for m in messages if isinstance(m, ToolMessage)]
assert len(tool_msgs) == 1
assert tool_msgs[0].tool_call_id == "c1"
assert tool_msgs[0].status == expected_status
assert tool_msgs[0].content == str(result)