Spaces:
Sleeping

File size: 40,915 Bytes
1af9fb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
# 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*