|
| 1 | +# Demo Narration Transcript |
| 2 | + |
| 3 | +## [OPENING] |
| 4 | + |
| 5 | +A well-designed agent should learn from its own mistakes. |
| 6 | +That's the paradigm this demo implements: a continuous self-improvement cycle where the agent's real-world failures |
| 7 | +become the training data for its next version. |
| 8 | + |
| 9 | +For this demo we use a company policy **Q&A assistant**, built with **Google ADK** and the **BigQuery Agent Analytics Plugin**. |
| 10 | + |
| 11 | +It's deliberately simple: a single LLM agent with just two tools: |
| 12 | +- `lookup_company_policy(topic)` — retrieves detailed policy data on a set of topics such as PTO, sick leave, |
| 13 | +- expenses, benefits, and holidays. |
| 14 | +- `get_current_date()` — returns today's date and day of the week, so the agent can answer date-relative questions. |
| 15 | + |
| 16 | +The agent's job is to answer employee questions — "How many PTO days do I get?", "What's the meal reimbursement limit?", |
| 17 | +"When is the next company holiday?", and so on. |
| 18 | + |
| 19 | +The prompt tells the agent to "answer only from the knowledge above" and to say "I don't know, contact HR" for anything not listed. |
| 20 | +A common pattern to restrict the model to known facts to prevent hallucinations. |
| 21 | + |
| 22 | +We will run it through the improvement cycle and see how it performs. |
| 23 | + |
| 24 | +--- |
| 25 | +## [High Level Overview of the Cycle Steps] |
| 26 | + |
| 27 | +The improvement cycle goes through the following actions and I will go into the more details when we actually execute it. |
| 28 | + |
| 29 | +1. Run the initial **eval test cases**. Our ground truth and base for regression tests |
| 30 | +2. Then we **generate** traffic. In production, these come from the real users; for the demo, |
| 31 | + we use Gemini to come up with the possible user questions and run them against the agent. |
| 32 | +3. Every session along with its metadata (token usage, latency, request/response, tool usage, trajectories and many more) is being logged to BigQuery via BigQuery Analytics plugin |
| 33 | + We **evaluate** each session quality — for usefulness and grounding |
| 34 | +4. * Then we work on **improving** the agent, by fine-tuning its instructions via the prompt optimizer. |
| 35 | +5. * Finally, **measure** the improvement against fresh, unseen traffic — and iterate if needed. |
| 36 | +6. At each evaluation step, the SDK's **deterministic evaluators** also check latency, token usage, and turn count — so we have an operational baseline from the start and can compare before and after. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## [GCP CLOUD SHELL - setup.sh] |
| 41 | +> Navigate to [Quick Start](https://github.com/GoogleCloudPlatform/BigQuery-Agent-Analytics-SDK/tree/main/examples/agent_improvement_cycle#quick-start) |
| 42 | +
|
| 43 | +We will start from scratch in a new Google Cloud project. |
| 44 | + |
| 45 | +- We have repo checked out and navigated inside the `examples/agent_improvement_cycle` directory |
| 46 | +- We have set the `Project ID` into environment variable using `export` |
| 47 | +- We have run the setup script `./setup.sh` that: |
| 48 | + - checks Python and authentication, |
| 49 | + - enables the BigQuery and Vertex AI APIs, |
| 50 | + - installs dependencies, |
| 51 | + - creates the initial prompt in the Vertex AI Prompt Registry and |
| 52 | + - Creates `.env` and updates `config.json` files that are input for the flow. |
| 53 | + |
| 54 | +--- |
| 55 | + |
| 56 | +## [cat .env and cat config.json] |
| 57 | + |
| 58 | +Here's the `.env` environment configuration created from our setup. |
| 59 | + |
| 60 | +And here is the `config.json` — the declarative interface. So you could later swap it with another agent of your own. |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## [GCP CLOUD SHELL - run_cycle.sh] |
| 65 | +> Navigate to [Solution](https://github.com/evekhm/BigQuery-Agent-Analytics-SDK/tree/feat/agent-improvement-cycle-demo/examples/agent_improvement_cycle#the-solution-learn-from-the-field) |
| 66 | +
|
| 67 | +We will trigger execution of the improvement cycle and we will catch up with it diving deeper into it steps. |
| 68 | + |
| 69 | +### [STARTING PROMPT displayed] |
| 70 | + |
| 71 | +Here's the V1 prompt. |
| 72 | +--- |
| 73 | + |
| 74 | +### [PRE-FLIGHT check] |
| 75 | + |
| 76 | +An interesting detail here: the model actually calls `lookup_company_policy` for these questions even with V1's having a flaw in its prompt. |
| 77 | +Not sure if everyone noticed it. Lets look at it again. The prompt actually discourages the agent to use its own tools and asks to rely only on the baked in information. |
| 78 | +However, because it mentions PTO, sick leave, and remote work by name in its inline knowledge it acts as a signal — the model recognizes the topic is valid and explores the available tools for more detail. |
| 79 | +However as we will see later, it does not happen for the topics which are not baked into the prompt. And for those un-known subhects it would fallback to the "I do not know, contact HR", while its tools have all of the available information. |
| 80 | + |
| 81 | +The model has no hint that the tool could help, so it obeys the refusal instruction. |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +### [STEP 1 — Generate Synthetic Traffic] |
| 86 | + |
| 87 | +Gemini generates ten diverse employee questions — things like "Do I need a doctor's note for four sick days?" and "What are the core hours for remote work?" These are intentionally different from the three golden test cases. They cover all six policy topics, including the ones V1's prompt doesn't mention. |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +### [STEP 2 — Run Traffic Through Agent] |
| 92 | + |
| 93 | +Step two sends those ten questions to the agent. Every session is logged to BigQuery through the BigQuery Agent Analytics Plugin. Watch the responses: for questions about topics mentioned in V1's prompt — like PTO rollover — the agent answers correctly. But for topics not in the prompt — parental leave, expenses, holidays — the agent says "I don't have that information, contact HR." It has the tools to answer, but the V1 prompt's "contact HR" instruction blocks it from even trying. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +### [STEP 3 — Evaluate Session Quality] |
| 98 | + |
| 99 | +Step three is where the SDK earns its keep. The quality report script reads those sessions back from BigQuery and an LLM judge scores each one. Four sessions are marked unhelpful — the agent deflected instead of using its tools. One is partial. Five are meaningful. The baseline score: fifty percent meaningful. That's our starting point. |
| 100 | + |
| 101 | +Right below the quality score, the SDK's deterministic CodeEvaluator runs on the same sessions — average latency, total tokens per session, turn count and error_rate. These are the operational baselines. No LLM needed, just math on the data already in BigQuery. We'll compare against these numbers after the improvement to make sure the new prompt didn't trade quality for cost. |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +### [STEP 4 — Improve Prompt] |
| 106 | + |
| 107 | +Step four is the core of the cycle. Let's break it down. |
| 108 | + |
| 109 | +#### 4a. Extract failed cases |
| 110 | + |
| 111 | +First, the failed cases are extracted into the golden eval set. These become the regression gate — any future prompt must pass all eight. This is how the eval set grows organically from real failures rather than from what we imagined users would ask. |
| 112 | + |
| 113 | +#### 4b. Generating ground truth via teacher agent |
| 114 | + |
| 115 | +The Vertex AI Prompt Optimizer operates in `target_response` mode — it needs (input, expected_output) pairs to optimize against. We have the inputs (the failed questions) and the bad outputs, but we're missing the ground truth: what should the agent have responded? |
| 116 | + |
| 117 | +Curating reference answers manually is impractical — these are questions we discovered through synthetic traffic, not ones we anticipated. We need to generate ground truth programmatically. |
| 118 | + |
| 119 | +This is where the teacher agent comes in. The concept borrows from `knowledge distillation` in ML — a technique where a capable "teacher" model generates labeled outputs that are then used to train or optimize a "student" model. In classical distillation, the teacher is typically a larger, more expensive model and the student is smaller and cheaper. Here we adapt the idea: the teacher and student share the same model and the same tools — the difference is the prompt. |
| 120 | +The teacher's prompt is generic tools first approach, but it is missing any possible domain knowledge, response formatting, vocabulary. |
| 121 | +Its sole purpose is to generate correct, tool-grounded outputs that serve as optimization targets. |
| 122 | +The Prompt Optimizer takes these targets and synthesizes a "production" prompt that captures the domain logic, tool mappings, and response patterns the agent needs. |
| 123 | + |
| 124 | +In real life, the gap between teacher and student is typically more nuanced. The teacher model is more sophisticated, but the concept is the same, |
| 125 | + |
| 126 | + |
| 127 | +#### 4c. Optimize and validate |
| 128 | + |
| 129 | +The triples — (question, V1 response, teacher response) — are passed to the Vertex AI Prompt Optimizer. |
| 130 | +The optimizer analyzes the gap between the bad and correct responses and generates an improved system instruction. |
| 131 | + |
| 132 | +When the candidate prompt returns, the regression gate validates it against all eight golden eval cases. Every case must pass, or the Optimizer needs to re-try. |
| 133 | +The prompt then is promoted from V1 to V2. |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## [STEP 5 — Measure Improvement] |
| 138 | + |
| 139 | +Step five is the moment of truth. Ten fresh, never-before-seen questions are generated and run through the agent with the new V2 prompt. The quality report scores them from BigQuery. |
| 140 | + |
| 141 | +We can see that previously failing type of questions are being answered now. |
| 142 | +The agent uses its tools and gives direct, grounded answers. No more "contact HR." |
| 143 | + |
| 144 | +Ten out of ten sessions scored as helpful and grounded — in a single cycle. |
| 145 | + |
| 146 | +And now the operational comparison — the same deterministic metrics we captured as a baseline in Step 3, run on the V2 sessions and shown side by side. |
| 147 | +Latency stayed flat or improved — the V2 prompt routes to tools directly instead of deliberating. Token usage is comparable. |
| 148 | +Turn count unchanged. The improved prompt didn't trade quality for cost. |
| 149 | + |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## [FINAL PROMPT displayed] |
| 154 | + |
| 155 | +Here's the optimized V2 prompt. It explicitly requires tool usage for every question, provides a topic-mapping strategy so the agent knows to look up "benefits" when asked about 401k. |
| 156 | +We have verified the new prompt against the test cases and also against the performance metrics. |
| 157 | + |
| 158 | +--- |
| 159 | + |
| 160 | +## [DONE summary] |
| 161 | + |
| 162 | +Let's recap what just happened: |
| 163 | + |
| 164 | +1. We started with a **V1 prompt** that had an anti-hallucination pattern — "answer only from knowledge above, otherwise contact HR." The agent had tools with all the answers, but the prompt blocked it from using them on topics not baked in. |
| 165 | + |
| 166 | +2. We ran **three golden eval cases** as a pre-flight — PTO, sick leave, remote work — all passed because those topics were mentioned in the prompt. |
| 167 | + |
| 168 | +3. We **generated ten synthetic questions** covering all six policy topics and ran them through the agent. The agent deflected on expenses, benefits, and holidays — topics it could answer but the prompt told it not to try. |
| 169 | + |
| 170 | +4. The **SDK's quality report** read those sessions from BigQuery and an LLM judge scored them. Baseline: roughly fifty percent meaningful. Right below, the **SDK's CodeEvaluator** established operational baselines — latency, tokens, turns, tool error rate — all from the same BigQuery data, no extra LLM calls. |
| 171 | + |
| 172 | +5. We **extracted the failures** into the golden eval set — growing it from three to about eight cases. A **teacher agent** — same model, same tools, different prompt — generated ground truth for each failed question. The **Vertex AI Prompt Optimizer** used those triples to generate an improved prompt, and the **regression gate** validated it against all golden cases before promoting it to V2. |
| 173 | + |
| 174 | +6. We ran **ten fresh questions** through V2. Quality went from fifty percent to one hundred percent. The **operational metrics comparison** confirmed latency, tokens, turns, and error rate all stayed within budget — the new prompt didn't trade quality for cost. |
| 175 | + |
| 176 | +The golden eval set grew organically from real failures. The prompt was optimized automatically. And every metric — quality and operational — was measured from data already in BigQuery. |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +## [Reset and run again] |
| 181 | + |
| 182 | +To reset everything back to V1 and start over: |
| 183 | +```shell |
| 184 | +./reset.sh |
| 185 | +``` |
| 186 | + |
| 187 | +This reverts the prompt in the Vertex AI Prompt Registry to V1, restores the original three golden eval cases, |
| 188 | +and clears reports. |
| 189 | + |
| 190 | +There are multiple options of how to run the flow: |
| 191 | +```shell |
| 192 | +./run_cycle.sh -h |
| 193 | +``` |
| 194 | + |
| 195 | +```text |
| 196 | +Options: |
| 197 | + --agent-config F Path to agent's config.json |
| 198 | + (default: config.json) |
| 199 | + --cycles N Run N improvement cycles (default: 1) |
| 200 | + --no-auto Always run all N cycles even if 100% |
| 201 | + meaningful (default: stop early) |
| 202 | + --eval-only Only run evaluation (Steps 1-3), skip improvement |
| 203 | + --app-name X Override agent app name for BQ filtering |
| 204 | + --traffic-count N Number of synthetic questions per cycle (default: 10) |
| 205 | + -h, --help Show this help message |
| 206 | +``` |
| 207 | + |
| 208 | +You can run again with multiple cycles to see iterative refinement: |
| 209 | +```shell |
| 210 | +./run_cycle.sh --cycles 3 |
| 211 | +``` |
| 212 | +By default, the cycle stops early once all synthetic traffic scores 100% meaningful. Each cycle generates fresh traffic, evaluates, improves, and measures. The golden eval set grows with each cycle as new edge cases are discovered. |
| 213 | + |
| 214 | +--- |
| 215 | + |
| 216 | +## [CLOSING] |
| 217 | + |
| 218 | +That's the agent improvement cycle. Capture sessions with the BigQuery Agent Analytics Plugin, evaluate quality with the SDK's LLM judge, |
| 219 | +check operational metrics with the SDK's CodeEvaluator, optimize prompts with Vertex AI, and measure the results — all automated, all repeatable. |
| 220 | +The golden eval set grows with every cycle, so failures you discover today become regression tests for tomorrow. |
0 commit comments