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
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>ADK Multi-Agent Blog Simulation</title>
  <style>
    :root{
      --bg:#f6f7fb;
      --panel:#ffffff;
      --card:#ffffff;
      --text:#1f2937;
      --muted:#6b7280;
      --border:#d1d5db;
      --accent:#2563eb;
      --accent-bg:#dbeafe;
      --ok:#16a34a;
      --retry:#d97706;
    }
    *{box-sizing:border-box}
    body{
      margin:0;
      font-family:Arial,Helvetica,sans-serif;
      background:var(--bg);
      color:var(--text);
    }
    .app{
      max-width:1200px;
      margin:0 auto;
      padding:24px;
    }
    h1{margin:0 0 8px;font-size:28px}
    .subtitle{color:var(--muted);margin-bottom:18px}
    .controls{
      display:flex;
      flex-wrap:wrap;
      gap:10px;
      align-items:center;
      margin-bottom:16px;
    }
    button,select{
      font:inherit;
      padding:10px 14px;
      border-radius:8px;
      border:1px solid var(--border);
      background:#fff;
      color:var(--text);
    }
    button{cursor:pointer}
    button.primary{
      background:var(--accent);
      color:#fff;
      border-color:var(--accent);
    }
    button:disabled{opacity:.5;cursor:not-allowed}
    .spacer{flex:1}
    .grid{
      display:grid;
      grid-template-columns:1fr 50px 1fr 50px 1fr;
      gap:12px;
      align-items:stretch;
    }
    .arrow{
      display:flex;
      align-items:center;
      justify-content:center;
      font-size:28px;
      color:var(--muted);
    }
    .card,.panel{
      background:var(--card);
      border:2px solid var(--border);
      border-radius:14px;
      padding:16px;
      transition:.2s ease;
    }
    .label{
      font-size:12px;
      text-transform:uppercase;
      letter-spacing:.08em;
      color:var(--muted);
      font-weight:700;
    }
    .title{
      margin-top:4px;
      font-size:18px;
      font-weight:700;
    }
    .node{
      border:2px solid var(--border);
      border-radius:10px;
      padding:10px;
      margin-top:10px;
      background:#fff;
      transition:.2s ease;
    }
    .down{
      text-align:center;
      color:var(--muted);
      padding:6px 0 0;
    }
    .loop-note{
      border:2px dashed var(--border);
      border-radius:10px;
      padding:9px;
      margin-top:10px;
      text-align:center;
      font-size:12px;
      color:var(--muted);
      transition:.2s ease;
    }
    .status{
      border:1px solid var(--border);
      border-radius:9px;
      padding:9px;
      margin-top:12px;
      font-size:14px;
    }
    .active{
      border-color:var(--accent)!important;
      background:var(--accent-bg)!important;
      transform:translateY(-2px);
    }
    .ok{border-color:var(--ok)!important}
    .retry{border-color:var(--retry)!important}
    .pulse{animation:pulse .7s ease-in-out infinite alternate}
    @keyframes pulse{from{opacity:.68}to{opacity:1}}
    .panel{margin-top:14px;border-width:1px}
    .panel-head{
      display:flex;
      gap:12px;
      justify-content:space-between;
      align-items:center;
      flex-wrap:wrap;
    }
    .badge{
      border:1px solid var(--border);
      border-radius:999px;
      padding:6px 10px;
      font-size:13px;
    }
    .queue{
      display:flex;
      flex-wrap:wrap;
      gap:8px;
      margin-top:12px;
    }
    .topic{
      border:1px solid var(--border);
      border-radius:999px;
      padding:6px 10px;
      font-size:13px;
      background:#fff;
    }
    .two-col{
      display:grid;
      grid-template-columns:1fr 1fr;
      gap:14px;
      margin-top:14px;
    }
    .state-row{
      display:flex;
      justify-content:space-between;
      gap:16px;
      border-bottom:1px solid var(--border);
      padding:8px 0;
      font-size:14px;
    }
    .state-row:last-child{border-bottom:0}
    .mono{font-family:Consolas,monospace}
    .muted{color:var(--muted)}
    .log{
      max-height:230px;
      overflow:auto;
      margin-top:10px;
      font-size:14px;
      line-height:1.5;
    }
    .final{margin-top:14px}
    @media(max-width:850px){
      .grid{grid-template-columns:1fr}
      .arrow{transform:rotate(90deg)}
      .two-col{grid-template-columns:1fr}
    }
    @media(prefers-reduced-motion:reduce){
      .card,.node,.loop-note{transition:none}
      .pulse{animation:none}
    }
  </style>
</head>
<body>
  <div class="app" id="blogSim">
    <h1>ADK Multi-Agent Blog Simulation</h1>
    <div class="subtitle">Watch topics flow through the Blogger root agent, planner validation loop, writer validation loop, and final response.</div>

    <div class="controls">
      <button id="startBtn" class="primary" type="button">Start Simulation</button>
      <button id="pauseBtn" type="button" disabled>Pause</button>
      <button id="resetBtn" type="button">Reset</button>
      <div class="spacer"></div>
      <label>Speed
        <select id="speed">
          <option value="1400">Slow</option>
          <option value="850" selected>Normal</option>
          <option value="420">Fast</option>
        </select>
      </label>
    </div>

    <div class="grid">
      <section id="rootCard" class="card">
        <div class="label">Root Agent</div>
        <div class="title">Blogger</div>
        <p class="muted">Instruction-enforced sequence:</p>
        <div class="mono">1. Planner β†’ 2. Writer β†’ 3. Final</div>
        <div id="rootStatus" class="status">Waiting for topic</div>
      </section>

      <div class="arrow">β†’</div>

      <section id="plannerCard" class="card">
        <div class="label">LoopAgent Β· Max 3</div>
        <div class="title">RobustBlogPlanner</div>
        <div id="plannerAgent" class="node">BlogPlanner</div>
        <div class="down">↓ blog_outline</div>
        <div id="outlineValidator" class="node">OutlineValidationChecker</div>
        <div id="plannerLoop" class="loop-note">retry ↻ until OK or 3 iterations</div>
      </section>

      <div class="arrow">β†’</div>

      <section id="writerCard" class="card">
        <div class="label">LoopAgent Β· Max 3</div>
        <div class="title">RobustBlogWriter</div>
        <div id="writerAgent" class="node">BlogWriter</div>
        <div class="down">↓ blog_post</div>
        <div id="postValidator" class="node">BlogPostValidationChecker</div>
        <div id="writerLoop" class="loop-note">retry ↻ until OK or 3 iterations</div>
      </section>
    </div>

    <section class="panel">
      <div class="panel-head">
        <div>
          <div class="label">Incoming Topic Queue</div>
          <div id="currentTopic" class="title">No topic active</div>
        </div>
        <div id="iterationBadge" class="badge">Idle</div>
      </div>
      <div id="topicQueue" class="queue"></div>
    </section>

    <div class="two-col">
      <section class="panel" style="margin-top:0">
        <div class="title">State / Output Keys</div>
        <div class="state-row"><span class="mono">blog_outline</span><span id="outlineState" class="muted">empty</span></div>
        <div class="state-row"><span class="mono">validation_result</span><span id="validationState" class="muted">empty</span></div>
        <div class="state-row"><span class="mono">blog_post</span><span id="postState" class="muted">empty</span></div>
      </section>

      <section class="panel" style="margin-top:0">
        <div class="title">Execution Log</div>
        <div id="log" class="log"><div class="muted">Simulation ready.</div></div>
      </section>
    </div>

    <section id="finalCard" class="panel final">
      <div class="label">Final Response</div>
      <div id="finalOutput" class="muted" style="margin-top:8px">Validated blog + 3 alternate titles + 2 tweet-length hooks will appear here.</div>
    </section>
  </div>

  <script>
    (() => {
      const root = document.getElementById('blogSim');
      const $ = id => document.getElementById(id);
      const topics = [
        'ADK Agent Patterns',
        'Context Engineering',
        'Vertex AI Memory',
        'Agentic Coding Workflows',
        'Responsible AI Guardrails'
      ];

      let running = false;
      let paused = false;
      let stopped = false;
      let topicIndex = 0;

      const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
      const delay = () => Number($('speed').value) || 850;

      async function waitStep(mult = 1) {
        let remaining = delay() * mult;
        while (remaining > 0 && !stopped) {
          if (!paused) remaining -= 80;
          await sleep(80);
        }
      }

      function log(msg) {
        const d = document.createElement('div');
        d.textContent = msg;
        $('log').appendChild(d);
        $('log').scrollTop = $('log').scrollHeight;
      }

      function clearActive() {
        root.querySelectorAll('.active,.pulse,.retry,.ok').forEach(el => {
          el.classList.remove('active','pulse','retry','ok');
        });
      }

      function activate(id, status) {
        clearActive();
        const el = $(id);
        if (el) el.classList.add('active','pulse');
        if (status) $('iterationBadge').textContent = status;
      }

      function renderQueue() {
        $('topicQueue').innerHTML = '';
        topics.forEach((t, i) => {
          const span = document.createElement('span');
          span.className = 'topic';
          span.textContent = (i < topicIndex ? 'βœ“ ' : '') + t;
          if (i === topicIndex && running) span.classList.add('active');
          $('topicQueue').appendChild(span);
        });
      }

      async function planner(topic) {
        const iterations = topicIndex % 2 === 0 ? 2 : 1;
        for (let i = 1; i <= iterations; i++) {
          activate('plannerAgent', `Planner iteration ${i}/3`);
          $('rootStatus').textContent = 'Calling planner_tool';
          log(`Planner: generating outline for β€œ${topic}”`);
          await waitStep();

          $('outlineState').textContent = `outline v${i}`;

          activate('outlineValidator', 'Validating outline');
          log('OutlineValidationChecker: checking title, intro, 4–6 sections, conclusion');
          await waitStep();

          if (i < iterations) {
            $('validationState').textContent = 'retry';
            $('outlineValidator').classList.add('retry');
            $('plannerLoop').classList.add('active');
            log('Validation result: retry β†’ LoopAgent starts next iteration');
            await waitStep(.75);
          } else {
            $('validationState').textContent = 'ok';
            $('outlineValidator').classList.add('ok');
            log('Validation result: ok β†’ planner returns control to Blogger');
            await waitStep(.75);
          }
        }
      }

      async function writer(topic) {
        const iterations = topicIndex % 3 === 0 ? 2 : 1;
        for (let i = 1; i <= iterations; i++) {
          activate('writerAgent', `Writer iteration ${i}/3`);
          $('rootStatus').textContent = 'Calling writer_tool';
          log('Writer: producing article from blog_outline');
          await waitStep();

          $('postState').textContent = `draft v${i}`;

          activate('postValidator', 'Validating article');
          log('BlogPostValidationChecker: checking structure and technical clarity');
          await waitStep();

          if (i < iterations) {
            $('validationState').textContent = 'retry';
            $('postValidator').classList.add('retry');
            $('writerLoop').classList.add('active');
            log('Validation result: retry β†’ writer loop repeats');
            await waitStep(.75);
          } else {
            $('validationState').textContent = 'ok';
            $('postValidator').classList.add('ok');
            log('Validation result: ok β†’ writer returns control to Blogger');
            await waitStep(.75);
          }
        }
      }

      async function processTopic(topic) {
        $('currentTopic').textContent = topic;
        $('outlineState').textContent = 'empty';
        $('validationState').textContent = 'empty';
        $('postState').textContent = 'empty';
        $('finalOutput').textContent = 'Processing…';

        activate('rootCard', 'Step 1 Β· Planner');
        $('rootStatus').textContent = 'Topic received β†’ planner first';
        log(`Blogger received topic: β€œ${topic}”`);
        await waitStep(.8);

        await planner(topic);
        if (stopped) return;

        activate('rootCard', 'Step 2 Β· Writer');
        $('rootStatus').textContent = 'Planner complete β†’ writer second';
        log('Blogger: planner returned; invoking writer_tool');
        await waitStep(.8);

        await writer(topic);
        if (stopped) return;

        activate('finalCard', 'Step 3 Β· Final');
        $('rootStatus').textContent = 'Writer complete β†’ final response';
        $('finalOutput').innerHTML =
          `<strong>${topic}</strong><br>βœ“ Validated blog post<br>βœ“ 3 alternate titles<br>βœ“ 2 tweet-length hooks`;
        log('Blogger: assembling final response with titles and hooks');
        await waitStep();

        clearActive();
      }

      async function run() {
        if (running) return;

        running = true;
        paused = false;
        stopped = false;

        $('startBtn').disabled = true;
        $('pauseBtn').disabled = false;
        $('pauseBtn').textContent = 'Pause';

        log('--- Simulation started ---');
        renderQueue();

        while (topicIndex < topics.length && !stopped) {
          renderQueue();
          await processTopic(topics[topicIndex]);
          if (stopped) break;

          topicIndex++;
          renderQueue();
          await waitStep(.5);
        }

        if (!stopped && topicIndex >= topics.length) {
          $('currentTopic').textContent = 'All queued topics complete';
          $('iterationBadge').textContent = 'Complete';
          $('rootStatus').textContent = 'Waiting for next topic';
          log('--- Queue complete ---');
        }

        running = false;
        $('startBtn').disabled = false;
        $('startBtn').textContent =
          topicIndex >= topics.length ? 'Run Again' : 'Start Simulation';
        $('pauseBtn').disabled = true;
      }

      $('startBtn').addEventListener('click', () => {
        if (topicIndex >= topics.length) {
          topicIndex = 0;
          renderQueue();
        }
        run();
      });

      $('pauseBtn').addEventListener('click', () => {
        paused = !paused;
        $('pauseBtn').textContent = paused ? 'Resume' : 'Pause';
        $('iterationBadge').textContent = paused ? 'Paused' : 'Running';
      });

      $('resetBtn').addEventListener('click', () => {
        stopped = true;
        paused = false;
        running = false;
        topicIndex = 0;

        clearActive();

        $('startBtn').disabled = false;
        $('startBtn').textContent = 'Start Simulation';
        $('pauseBtn').disabled = true;
        $('pauseBtn').textContent = 'Pause';

        $('currentTopic').textContent = 'No topic active';
        $('iterationBadge').textContent = 'Idle';
        $('rootStatus').textContent = 'Waiting for topic';
        $('outlineState').textContent = 'empty';
        $('validationState').textContent = 'empty';
        $('postState').textContent = 'empty';

        $('finalOutput').textContent =
          'Validated blog + 3 alternate titles + 2 tweet-length hooks will appear here.';

        $('log').innerHTML =
          '<div class="muted">Simulation reset.</div>';

        renderQueue();
      });

      renderQueue();
    })();
  </script>
</body>
</html>