# TFA - Test Failure Analysis System ## Architecture & Design Document **Version:** 2.0 **Date:** January 2026 **Status:** Multi-Platform Implementation Complete --- ## Table of Contents 1. [Executive Summary](#1-executive-summary) 2. [System Overview](#2-system-overview) 3. [Architecture](#3-architecture) 4. [Agent Design](#4-agent-design) 5. [Data Models](#5-data-models) 6. [Tool Implementation](#6-tool-implementation) 7. [Integration Points](#7-integration-points) 8. [Deployment & Configuration](#8-deployment--configuration) 9. [Testing Strategy](#9-testing-strategy) 10. [Performance & Scalability](#10-performance--scalability) --- ## 1. Executive Summary ### 1.1 Purpose The Test Failure Analysis (TFA) system is an AI-powered multi-agent pipeline designed to automatically analyze test failures across all Gmail platforms. It reduces manual triage time from hours to minutes by: - Collecting comprehensive failure data from multiple sources - Classifying failures into actionable categories with platform-specific patterns - Determining appropriate remediation actions with platform-specific routing - Generating human-readable reports and recommendations ### 1.2 Supported Platforms | Platform | Frameworks | Environment | Artifacts | |----------|------------|-------------|-----------| | πŸ€– **Android** | Copycat, Espresso, UI Automator | Devices, Emulators, API levels | logcat, screenshots, UI XML | | 🌐 **Web** | Selenium, Playwright, Cypress, WebdriverIO | Chrome, Firefox, Safari, Edge | console logs, HAR, DOM snapshots | | 🍎 **iOS** | XCUITest, EarlGrey | Devices, Simulators, iOS versions | device logs, screenshots, crash reports | ### 1.3 Key Features | Feature | Description | |---------|-------------| | **Multi-Platform Support** | Android, Web, and iOS test analysis | | **Four-Agent Pipeline** | Sequential processing through specialized agents | | **7 Failure Categories** | Infrastructure, Code Regression, UI Regression, Configuration, Dependency, Test Logic Error, Unknown | | **Platform-Specific Patterns** | Error patterns tailored to each platform | | **Sponge API Integration** | 9 tools for test data retrieval and analysis | | **Multiple Output Formats** | Markdown reports, Slack messages, ticket descriptions | | **Confidence Scoring** | Evidence-based classification with confidence levels | ### 1.4 Technology Stack - **Agent Framework:** Google ADK (Agent Development Kit) v1.22+ - **LLM:** Google Gemini 2.0 Flash - **Language:** Python 3.11+ - **Data API:** Sponge Test Results API - **Async Runtime:** asyncio with httpx --- ## 2. System Overview ### 2.1 High-Level Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ TFA ORCHESTRATOR β”‚ β”‚ (Root Coordinating Agent - Multi-Platform) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Android β”‚ β”‚ Web β”‚ β”‚ iOS β”‚ β”‚ Tests β”‚ β”‚ Tests β”‚ β”‚ Tests β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ AGENT 1 β”‚ β”‚ AGENT 2 β”‚ β”‚ AGENT 3 β”‚ β”‚ AGENT 4 β”‚ β”‚ β”‚ Information │──▢│ Failure │──▢│ Action │──▢│Recommendationβ”‚ β”‚ β”‚ Collector β”‚ β”‚ Classifier β”‚ β”‚ Determiner β”‚ β”‚ Summarizer β”‚ β”‚ β”‚ (Platform- β”‚ β”‚ (Platform- β”‚ β”‚ (Platform- β”‚ β”‚ (Platform- β”‚ β”‚ β”‚ Aware) β”‚ β”‚ Patterns) β”‚ β”‚ Routing) β”‚ β”‚ Reports) β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β–Ό β–Ό β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ Sponge Tools β”‚ β”‚ Outputs β”‚ β”‚ β”‚ (9 tools) β”‚ β”‚ MD/Slack/Bug β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ SPONGE API β”‚ β”‚ (Test Invocations, Actions, Artifacts) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### 2.2 Data Flow ``` Test Failure Event (Android/Web/iOS) β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ INPUT: invocation_id, test_name, platform (optional) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ AGENT 1: Information Collector (Platform-Aware) β”‚ β”‚ ─────────────────────────────────────────────────────────────────── β”‚ β”‚ β€’ Detect platform from test path, framework, or error patterns β”‚ β”‚ β€’ Fetch invocation data from Sponge API β”‚ β”‚ β€’ Retrieve failed actions with error details β”‚ β”‚ β€’ Collect platform-specific artifacts: β”‚ β”‚ - Android: logcat, UI XML, screenshots β”‚ β”‚ - Web: console logs, HAR files, DOM snapshots β”‚ β”‚ - iOS: device logs, crash reports, view hierarchy β”‚ β”‚ β€’ Search historical test results β”‚ β”‚ β€’ Detect regression points β”‚ β”‚ β€’ Analyze flakiness patterns β”‚ β”‚ β”‚ β”‚ OUTPUT: InformationPackage (JSON with platform context) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ AGENT 2: Failure Classifier (Platform-Specific Patterns) β”‚ β”‚ ─────────────────────────────────────────────────────────────────── β”‚ β”‚ β€’ Apply platform-specific error patterns: β”‚ β”‚ - Android: SocketTimeout, ActivityNotFound, etc. β”‚ β”‚ - Web: StaleElement, WebDriverException, etc. β”‚ β”‚ - iOS: XCUIElementNotFound, NSURLError, etc. β”‚ β”‚ β€’ Match against known failure patterns β”‚ β”‚ β€’ Correlate with recent code changes (CLs) β”‚ β”‚ β€’ Calculate confidence scores β”‚ β”‚ β€’ Identify similar historical failures β”‚ β”‚ β”‚ β”‚ OUTPUT: Classification (category, subcategory, confidence) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ AGENT 3: Action Determiner (Platform-Specific Routing) β”‚ β”‚ ─────────────────────────────────────────────────────────────────── β”‚ β”‚ β€’ Apply decision matrix based on classification β”‚ β”‚ β€’ Route to platform-specific stakeholders: β”‚ β”‚ - Android: android-team@, mobile-harness@ β”‚ β”‚ - Web: web-team@, selenium-grid@ β”‚ β”‚ - iOS: ios-team@, xcode-team@ β”‚ β”‚ β€’ Determine ticket creation requirements β”‚ β”‚ β€’ Evaluate blocking/quarantine decisions β”‚ β”‚ β€’ Estimate resolution time β”‚ β”‚ β”‚ β”‚ OUTPUT: ActionPlan (actions, stakeholders, blocking) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ AGENT 4: Recommendation Summarizer (Platform-Aware Reports) β”‚ β”‚ ─────────────────────────────────────────────────────────────────── β”‚ β”‚ β€’ Generate executive summary with platform context β”‚ β”‚ β€’ Create detailed markdown report with platform-specific details β”‚ β”‚ β€’ Format Slack notification with platform emoji β”‚ β”‚ β€’ Prepare bug ticket description with environment info β”‚ β”‚ β€’ Include platform-specific diagnostic commands β”‚ β”‚ β”‚ β”‚ OUTPUT: TFAReport (multiple formats) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ FINAL OUTPUT β”‚ β”‚ β€’ Platform: Android/Web/iOS β”‚ β”‚ β€’ Full Markdown Report β”‚ β”‚ β€’ Slack Message β”‚ β”‚ β€’ Bug Ticket Description β”‚ β”‚ β€’ Confidence Score β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## 3. Architecture ### 3.1 Project Structure ``` tfa_agents/ β”œβ”€β”€ __init__.py # Package entry point, exports TFARunner β”œβ”€β”€ agent.py # Root orchestrator agent definition β”œβ”€β”€ runner.py # Execution runner with sync/async support β”œβ”€β”€ demo.py # Interactive demo scenarios β”‚ β”œβ”€β”€ agents/ # Four specialized agents β”‚ β”œβ”€β”€ __init__.py β”‚ β”œβ”€β”€ information_collector.py # Agent 1: Data gathering β”‚ β”œβ”€β”€ failure_classifier.py # Agent 2: Categorization β”‚ β”œβ”€β”€ action_determiner.py # Agent 3: Action planning β”‚ └── recommendation_summarizer.py # Agent 4: Report generation β”‚ β”œβ”€β”€ tools/ # Sponge API integration β”‚ β”œβ”€β”€ __init__.py β”‚ β”œβ”€β”€ sponge_client.py # Base client with data models β”‚ β”œβ”€β”€ sponge_tools.py # ADK FunctionTool wrappers β”‚ β”œβ”€β”€ sponge_mock.py # Mock client for testing β”‚ β”œβ”€β”€ sponge_http_client.py # Production HTTP client β”‚ └── test_sponge_tools.py # Tool tests β”‚ └── shared/ # Shared data models β”œβ”€β”€ __init__.py └── models.py # Pydantic/dataclass models ``` ### 3.2 Component Dependencies ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ TFARunner β”‚ β”‚ (runner.py) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ root_agent β”‚ β”‚ (agent.py) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ information_ β”‚ β”‚ failure_ β”‚ β”‚ action_ β”‚ β”‚ collector β”‚ β”‚ classifier β”‚ β”‚ determiner β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ sponge_tools β”‚ β”‚recommendation_β”‚ β”‚ (9 tools) β”‚ β”‚ summarizer β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ SpongeClient β”‚ β”‚ (HTTP/Mock) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### 3.3 Google ADK Integration The system uses Google ADK's agent framework: ```python from google.adk import Agent from google.adk.runners import Runner from google.adk.sessions import InMemorySessionService from google.adk.tools import FunctionTool from google.genai.types import Content, Part ``` **Key ADK Concepts Used:** | Concept | Usage | |---------|-------| | `Agent` | Define each of the 4 specialized agents | | `sub_agents` | Connect agents in the orchestrator | | `FunctionTool` | Wrap Sponge API functions as tools | | `Runner` | Execute agent pipeline | | `InMemorySessionService` | Manage conversation state | --- ## 4. Agent Design ### 4.1 Agent 1: Information Collector **Purpose:** Gather all relevant data required for failure analysis. **Model:** `gemini-2.0-flash` **Tools Available:** | Tool | Purpose | |------|---------| | `get_invocation_data` | Fetch complete invocation with targets and summary | | `get_failed_actions` | Get non-passing actions with error details | | `get_test_artifacts` | Retrieve logs, screenshots, UI dumps | | `get_action_details` | Detailed action info for a target | | `search_historical_failures` | Cross-invocation history with patterns | | `compare_test_runs` | Diff passing vs failing runs | | `get_test_timeline` | Chronological execution view | | `find_regression_point` | Detect when test started failing | | `get_flaky_test_analysis` | Analyze test for flakiness | **Output Schema:** ```json { "invocation_id": "uuid", "test_metadata": { "test_id": "string", "test_name": "string", "test_file": "string", "suite": "string", "failure_line": 48, "failure_command": "waitFor element" }, "failure_details": { "error_message": "string", "stack_trace": "string", "failure_point": "string", "error_type": "string" }, "device_environment": { "model": "Pixel 6 Pro", "api_level": 34, "density_dpi": 560 }, "historical_data": { "pass_rate_last_50": 0.52, "pattern_detected": "regression" }, "regression_analysis": { "regression_detected": true, "pass_rate_before": 1.0, "pass_rate_after": 0.06 }, "flakiness_analysis": { "is_flaky": false, "flakiness_score": 0.15 } } ``` ### 4.2 Agent 2: Failure Classifier **Purpose:** Categorize failures into predefined categories with confidence scores. **Model:** `gemini-2.0-flash` **Tools:** None (analysis-only agent) **Classification Categories:** | Category | Subcategories | Indicators | |----------|---------------|------------| | **Infrastructure** | Network Timeout, Storage Exhaustion, Device Provisioning | SocketTimeoutException, storage < 500MB | | **Code Regression** | State Management, API Integration, Business Logic | CL correlation, pass rate drop | | **UI Regression** | Element Positioning, Material Design, Layout | Element not found, layout changes | | **Configuration** | Missing Package, Feature Flag, Provisioning Error | ActivityNotFoundException | | **Dependency** | Play Services, Calendar Provider, Third-Party | ClassNotFoundException, version mismatch | | **Test Logic Error** | Incorrect Assertion, Wrong Selector, Flaky Design | App works but test fails | | **Unknown** | Intermittent, Non-Reproducible | Confidence < 60% | **Classification Algorithm:** ``` 1. CHECK INFRASTRUCTURE β†’ Network/Storage/Device errors? 2. CHECK CODE REGRESSION β†’ CL correlation? Pass rate drop? 3. CHECK UI REGRESSION β†’ Element changes? Layout modified? 4. CHECK CONFIGURATION β†’ Missing packages? Wrong flags? 5. CHECK DEPENDENCY β†’ Version mismatch? External crashes? 6. CHECK TEST LOGIC β†’ App working but test fails? 7. DEFAULT TO UNKNOWN β†’ Confidence < 60% ``` **Confidence Scoring:** - **0.9-1.0:** Multiple strong indicators, clear pattern - **0.8-0.9:** Strong primary indicator with support - **0.7-0.8:** Clear indicator but some ambiguity - **0.6-0.7:** Likely but needs verification - **< 0.6:** Insufficient evidence β†’ Unknown ### 4.3 Agent 3: Action Determiner **Purpose:** Determine appropriate actions based on classification. **Model:** `gemini-2.0-flash` **Tools:** None (could add ticket creation tools) **Decision Matrix:** | Classification | Confidence | Actions | |----------------|------------|---------| | Infrastructure - Network | >0.8 | Alert infra team, Retry 2x, File ticket | | Code Regression | >0.8 | P1 bug, Notify CL author, Consider rollback | | UI Regression | >0.8 | P2 bug, Update selectors, Notify UI team | | Configuration | >0.9 | Update config, Reprovision devices | | Dependency | >0.8 | Coordinate update, File dependency bug | | Test Logic Error | >0.75 | Assign to test author, Quarantine if flaky | | Unknown | <0.6 | Manual review, Add instrumentation | **Action Types:** ```python class ActionType(str, Enum): CREATE_TICKET = "create_ticket" NOTIFY_STAKEHOLDERS = "notify_stakeholders" RETRY_TEST = "retry_test" QUARANTINE_TEST = "quarantine_test" BLOCK_DEPLOYMENT = "block_deployment" ROLLBACK_CL = "rollback_cl" UPDATE_CONFIG = "update_config" MANUAL_REVIEW = "manual_review" ``` ### 4.4 Agent 4: Recommendation Summarizer **Purpose:** Generate human-readable reports in multiple formats. **Model:** `gemini-2.0-flash` **Tools:** None (formatting-only agent) **Output Formats:** 1. **Full Markdown Report** - Executive summary - Quick facts table - Root cause analysis - Recommended actions (prioritized) - Investigation details - Next steps per stakeholder 2. **Slack Message** - Concise alert format - Classification and confidence - Key actions taken - Links to full report 3. **Bug Ticket Description** - Summary paragraph - Environment details - Failure details with stack trace - Reproduction steps - Suggested fix --- ## 5. Data Models ### 5.1 Core Models Located in `tfa_agents/shared/models.py`: ```python # Platform Enums class Platform(str, Enum): ANDROID = "Android" WEB = "Web" IOS = "iOS" class TestFramework(str, Enum): # Android COPYCAT = "Copycat" ESPRESSO = "Espresso" UI_AUTOMATOR = "UI Automator" # Web SELENIUM = "Selenium" PLAYWRIGHT = "Playwright" CYPRESS = "Cypress" WEBDRIVER_IO = "WebdriverIO" # iOS XCUITEST = "XCUITest" EARL_GREY = "EarlGrey" # Failure Categories class FailureCategory(str, Enum): INFRASTRUCTURE = "Infrastructure" CODE_REGRESSION = "Code Regression" UI_REGRESSION = "UI Regression" CONFIGURATION = "Configuration" DEPENDENCY = "Dependency" TEST_LOGIC_ERROR = "Test Logic Error" UNKNOWN = "Unknown/Inconclusive" class Severity(str, Enum): P0 = "P0" # Critical P1 = "P1" # High P2 = "P2" # Medium P3 = "P3" # Low class ActionType(str, Enum): CREATE_TICKET = "create_ticket" NOTIFY_STAKEHOLDERS = "notify_stakeholders" # ... etc ``` ### 5.2 Platform-Specific Environment Models ```python @dataclass class DeviceEnvironment: """Android device environment.""" model: str api_level: int density_dpi: int os_build: str storage_available_mb: int gmail_version: Optional[str] play_services_version: Optional[str] @dataclass class BrowserEnvironment: """Web browser environment.""" browser_name: str # Chrome, Firefox, Safari, Edge browser_version: str driver_version: str os_name: str # Windows, macOS, Linux os_version: str viewport_width: int viewport_height: int headless: bool gmail_version: Optional[str] @dataclass class IOSDeviceEnvironment: """iOS device environment.""" device_model: str # iPhone 15 Pro, iPad Air, etc. ios_version: str simulator: bool screen_scale: float storage_available_mb: int gmail_version: Optional[str] xcode_version: Optional[str] ``` ### 5.3 Platform-Specific Error Patterns | Platform | Error Pattern | Likely Category | |----------|---------------|-----------------| | **Android** | SocketTimeoutException | Infrastructure - Network | | **Android** | NoSuchElementException | UI Regression | | **Android** | ActivityNotFoundException | Configuration | | **Android** | ClassNotFoundException | Dependency | | **Web** | TimeoutException | Infrastructure or UI | | **Web** | StaleElementReferenceException | UI Regression | | **Web** | WebDriverException | Infrastructure | | **Web** | JavaScriptError | Code Regression | | **iOS** | XCUIElementNotFound | UI Regression | | **iOS** | XCTestErrorDomain | Test Logic Error | | **iOS** | NSURLErrorDomain | Infrastructure - Network | | **iOS** | EarlGreyError | Test Logic Error | ### 5.4 Data Transfer Objects ```python @dataclass class TestMetadata: test_id: str test_name: str test_file: str suite: str execution_time: str duration_ms: int platform: Platform # NEW: Platform identification framework: TestFramework # NEW: Framework identification failure_line: Optional[int] failure_command: Optional[str] @dataclass class FailureDetails: error_message: str stack_trace: str failure_point: str error_type: str @dataclass class Classification: category: FailureCategory subcategory: str confidence: float reasoning: str related_cl: Optional[str] pattern_matches: list[PatternMatch] similar_failures: list[SimilarFailure] @dataclass class ActionPlan: recommended_actions: list[RecommendedAction] stakeholders_to_notify: list[str] blocking_recommendations: BlockingRecommendation follow_up_required: bool estimated_resolution_hours: Optional[float] @dataclass class InformationPackage: """Complete information package - platform-aware.""" invocation_id: str test_metadata: TestMetadata failure_details: FailureDetails code_context: CodeContext historical_data: HistoricalData artifacts: list[Artifact] # Platform-specific environments (only one populated) device_environment: Optional[DeviceEnvironment] # Android browser_environment: Optional[BrowserEnvironment] # Web ios_environment: Optional[IOSDeviceEnvironment] # iOS @dataclass class TFAReport: platform: Platform # NEW framework: TestFramework # NEW executive_summary: str severity: Severity classification: Classification action_plan: ActionPlan full_report_markdown: str slack_message: str ticket_description: str analysis_time_seconds: float confidence_score: float ``` ### 5.3 Sponge API Models Located in `tfa_agents/tools/sponge_client.py`: ```python @dataclass class InvocationData: invocation_id: str status: str start_time: Optional[str] end_time: Optional[str] properties: dict @dataclass class ActionData: action_id: str target_id: str status: str attempt_number: int duration_ms: Optional[int] error_message: Optional[str] stack_trace: Optional[str] @dataclass class FileData: path: str file_type: str size_bytes: Optional[int] uri: Optional[str] ``` --- ## 6. Tool Implementation ### 6.1 Sponge API Tools Nine tools wrap the Sponge API for agent use: | Tool | Function | Key Parameters | |------|----------|----------------| | `get_invocation_data` | Fetch complete invocation | `invocation_id` | | `get_failed_actions` | Get failed actions | `invocation_id`, `target_id` | | `get_test_artifacts` | Retrieve artifacts | `invocation_id`, `build_target`, `file_types` | | `get_action_details` | Detailed action info | `invocation_id`, `target_id` | | `search_historical_failures` | Historical results | `target_id`, `lookback_count` | | `compare_test_runs` | Diff pass/fail runs | `target_id`, `passing_id`, `failing_id` | | `get_test_timeline` | Execution timeline | `invocation_id`, `target_id` | | `find_regression_point` | Detect regression | `target_id`, `lookback_count` | | `get_flaky_test_analysis` | Flakiness analysis | `target_id`, `window_size` | ### 6.2 Tool Registration Tools are registered as ADK FunctionTools: ```python from google.adk.tools import FunctionTool sponge_tools = [ FunctionTool(get_invocation_data), FunctionTool(get_failed_actions), FunctionTool(get_test_artifacts), FunctionTool(get_action_details), FunctionTool(search_historical_failures), FunctionTool(compare_test_runs), FunctionTool(get_test_timeline), FunctionTool(find_regression_point), FunctionTool(get_flaky_test_analysis), ] ``` ### 6.3 Client Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ sponge_tools.py β”‚ β”‚ (FunctionTool wrappers) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ _get_client() β”‚ β”‚ (Global client instance) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ MockSpongeClient β”‚ β”‚ SpongeHttpClient β”‚ β”‚ (Testing) β”‚ β”‚ (Production) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Mock Data β”‚ β”‚ Sponge API β”‚ β”‚ (Scenarios) β”‚ β”‚ (HTTP/REST) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### 6.4 Mock Client Scenarios For testing without real API: ```python from tfa_agents.tools.sponge_mock import use_mock_client # Available scenarios: use_mock_client("code_regression") # CL broke functionality use_mock_client("infrastructure") # Network/device issues use_mock_client("flaky_test") # Intermittent failures use_mock_client("configuration") # Missing packages ``` --- ## 7. Integration Points ### 7.1 Input Sources | Source | Data Retrieved | |--------|----------------| | **Sponge API** | Test invocations, actions, artifacts, history | | **Mobile Harness** | Device state, provisioning status | | **Git/Gerrit** | Recent CLs, code changes | | **Test Config** | Feature flags, required packages | ### 7.2 Output Destinations | Destination | Format | Content | |-------------|--------|---------| | **Console/CLI** | Markdown | Full analysis report | | **Slack** | Formatted message | Alert with key details | | **JIRA/Buganizer** | Ticket description | Bug report content | | **Dashboard** | JSON | Structured analysis data | ### 7.3 Sponge API Operations Based on the Sponge API Data Model: ``` Invocation (1) β”‚ β”œβ”€β”€ DownloadMetadata (1) β”œβ”€β”€ Targets (*) β”œβ”€β”€ Configurations (*) β”œβ”€β”€ ConfiguredTargets (*) β”‚ └── Actions (*) β”‚ └── Files/Artifacts (*) └── FileSets (*) └── Files (*) ``` **Key Operations:** - `get_invocation(invocation_id)` β†’ Single invocation - `export_invocation(invocation_id, field_mask)` β†’ Full export - `list_actions(invocation_id, actions_filter)` β†’ Filtered actions - `get_all_artifacts(invocation_id, file_types)` β†’ Test artifacts - `search_configured_targets(query)` β†’ Cross-invocation search --- ## 8. Deployment & Configuration ### 8.1 Installation ```bash # Create virtual environment python -m venv .venv .venv\Scripts\Activate.ps1 # Windows source .venv/bin/activate # Linux/Mac # Install dependencies pip install google-adk httpx ``` ### 8.2 Configuration **Environment Variables:** ```bash # Required for production GOOGLE_API_KEY=your-gemini-api-key # Optional SPONGE_API_ENDPOINT=https://sponge.corp.google.com/api/v2 SPONGE_BEARER_TOKEN=your-oauth-token ``` **Programmatic Configuration:** ```python # For production Sponge API from tfa_agents.tools.sponge_http_client import configure_production_client configure_production_client( api_endpoint="https://sponge.corp.google.com/api/v2", bearer_token="your-oauth-token" ) # For testing with mock data from tfa_agents.tools.sponge_mock import use_mock_client use_mock_client("code_regression") ``` ### 8.3 Usage Examples **Python API:** ```python from tfa_agents import TFARunner runner = TFARunner() result = runner.analyze_failure( invocation_id="fe3e0b7f-7bb9-4524-8a79-3c62cf028243", test_name="mark_multiple_emails_as_read" ) print(result) ``` **Async API:** ```python import asyncio from tfa_agents import TFARunner async def analyze(): runner = TFARunner() result = await runner.analyze_failure_async( invocation_id="fe3e0b7f-...", test_name="mark_multiple_emails_as_read" ) return result result = asyncio.run(analyze()) ``` **CLI:** ```bash python -m tfa_agents.runner \ --mock code_regression \ -v \ fe3e0b7f-7bb9-4524-8a79-3c62cf028243 \ mark_multiple_emails_as_read ``` --- ## 9. Testing Strategy ### 9.1 Test Levels | Level | Scope | Tools | |-------|-------|-------| | **Unit** | Individual tools | pytest, mock client | | **Integration** | Agent pipeline | Mock Sponge data | | **E2E** | Full system | Real API (staging) | ### 9.2 Mock Testing ```python # test_mock.py - Standalone tool tests python test_mock.py # Output: # βœ… Code Regression Scenario - PASSED # βœ… Flaky Test Scenario - PASSED # βœ… Infrastructure Scenario - PASSED ``` ### 9.3 Agent Testing ```python # test_agents.py - Full pipeline test # Requires GOOGLE_API_KEY python test_agents.py ``` ### 9.4 Test Scenarios | Scenario | Mock Data | Expected Classification | |----------|-----------|------------------------| | `code_regression` | CL correlation, pass rate drop | Code Regression (88%) | | `infrastructure` | SocketTimeoutException | Infrastructure (92%) | | `flaky_test` | Alternating pass/fail | Test Logic Error (70%) | | `configuration` | ActivityNotFoundException | Configuration (95%) | --- ## 10. Performance & Scalability ### 10.1 Target SLAs | Agent | Target Time | |-------|-------------| | Information Collector | < 20 seconds | | Failure Classifier | < 10 seconds | | Action Determiner | < 5 seconds | | Recommendation Summarizer | < 10 seconds | | **Total Pipeline** | **< 60 seconds** | ### 10.2 Scalability Considerations **Current Design:** - Sequential agent pipeline - Single invocation per request - In-memory session state **Future Enhancements:** - Parallel tool execution in Agent 1 - Batch processing for multiple failures - Persistent session storage - Caching for historical data ### 10.3 Resource Requirements | Resource | Requirement | |----------|-------------| | Python | 3.11+ | | Memory | ~500MB per analysis | | Network | Sponge API access | | LLM | Gemini API quota | --- ## Appendix A: File Reference | File | Lines | Purpose | |------|-------|---------| | `agent.py` | ~80 | Root orchestrator definition | | `runner.py` | ~220 | Execution runner | | `agents/information_collector.py` | ~120 | Agent 1 definition | | `agents/failure_classifier.py` | ~200 | Agent 2 definition | | `agents/action_determiner.py` | ~200 | Agent 3 definition | | `agents/recommendation_summarizer.py` | ~180 | Agent 4 definition | | `tools/sponge_tools.py` | ~350 | 9 Sponge API tools | | `tools/sponge_client.py` | ~200 | Base client + models | | `tools/sponge_mock.py` | ~250 | Mock client | | `tools/sponge_http_client.py` | ~200 | Production HTTP client | | `shared/models.py` | ~200 | Data models | --- ## Appendix B: Glossary | Term | Definition | |------|------------| | **ADK** | Agent Development Kit - Google's framework for building AI agents | | **CL** | Changelist - A code change submission (similar to PR/commit) | | **Copycat** | Gmail Android test automation framework | | **Invocation** | A single test execution run | | **Mobile Harness** | Test lab infrastructure for Android devices | | **Sponge** | Google's test results storage and analysis system | | **TFA** | Test Failure Analysis - This system | --- ## Appendix C: References - [Google ADK Documentation](https://google.github.io/adk-docs/) - [Gemini API](https://ai.google.dev/) - [Sponge API Data Model](./Sponge%20API%20Data%20Model.txt) - [Gmail Test Categorization Guide](./categorization.txt) - [Original TFA Architecture](./4tfa.txt) - [TFA Flow Diagrams (Mermaid)](./TFA_FLOW_DIAGRAM.md) - End-to-end visual diagrams - [Gemini API](https://ai.google.dev/) - [Sponge API Data Model](./Sponge%20API%20Data%20Model.txt) - [Gmail Test Categorization Guide](./categorization.txt) - [Original TFA Architecture](./4tfa.txt) --- *Document generated: January 2026*