<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zuhal Kale on Medium]]></title>
        <description><![CDATA[Stories by Zuhal Kale on Medium]]></description>
        <link>https://medium.com/@kalezuhal?source=rss-0dd86234693e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_F4NWghAOuoo56MWn89JdA.jpeg</url>
            <title>Stories by Zuhal Kale on Medium</title>
            <link>https://medium.com/@kalezuhal?source=rss-0dd86234693e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 21:14:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kalezuhal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Testing AI Agents: A QA Playbook for the Streaming Era]]></title>
            <link>https://medium.com/@kalezuhal/testing-ai-agents-a-qa-playbook-for-the-streaming-era-7adf64a1ee39?source=rss-0dd86234693e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7adf64a1ee39</guid>
            <dc:creator><![CDATA[Zuhal Kale]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 14:14:00 GMT</pubDate>
            <atom:updated>2026-10-28T14:14:00.233Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How I stopped treating LLM-powered features like flaky endpoints and started testing them like the stateful, event-driven systems they actually are.</em></p><p><strong>The problem with “just try it in the chat window”</strong></p><p>Most teams onboarding their first AI agent test it the way they’d test a search box: type something, look at the answer, ship it. That works for a demo. It falls apart the moment the agent has to call tools, mutate state, or make routing decisions across sub-agents. By the time a bug surfaces in production, the QA path is a screenshot of a conversation and a Jira comment that reads “cannot reproduce.”</p><p>Testing agents well means treating them as three things simultaneously:</p><ol><li>A “non-deterministic function” whose output shape you can constrain but not fully pin.</li><li>A “streaming protocol” with an ordered event trace, not a single response body.</li><li>A “stateful actor” whose behavior depends on the persona it’s running against as much as the prompt it receives.</li></ol><p><em>This article is the playbook I’ve settled on after enough burned afternoons debugging “the agent didn’t say the right thing” tickets. It’s framework-agnostic — the underlying transport in your stack may be WebSockets, SSE, gRPC streams, or something else — but the QA discipline transfers.</em></p><p><strong>1. Understand the transport before you write a single test</strong></p><p>Agent stacks stream in a few different shapes. You’ll see at least these:</p><ul><li>Single-request streaming — one HTTP POST that returns an SSE or chunked-transfer body. The request is the subscription.</li><li>Two-step invoke + listen — one call opens a channel (WebSocket, SSE, gRPC server-stream), a second call kicks off the run. Common when the same channel is reused for multiple turns.</li><li>Three-step initiate + subscribe + invoke — a stream ID is allocated first, a subscription is opened against it, then invoke references the ID. Common in GraphQL-subscription-backed stacks and anywhere the stream needs to be addressable independent of the invocation.</li></ul><p>The right test-client shape depends on which one you’re on, but a shared discipline applies to all of them: the listener must be attached before the run starts producing events. In single-request streaming that’s free — the response body is the listener. In the two- and three-step variants it’s on you to enforce ordering: open the channel, wait for whatever “ready” signal the transport provides (a WebSocket `connection_ack` frame, a gRPC stream established callback, an SSE `open` event), and only then fire the invoke.</p><p>Get that wrong and you race the agent. The first content chunks, the `start` event, and often the first tool call all land before your listener is attached. Your test reports a partial response and looks like a bot regression when it’s really a client bug in your test rig.</p><p><strong>QA rule zero: </strong>whatever transport you’re on, the reproduction should be deterministic in event ordering. If it isn’t, fix the client before you argue about the model.</p><p>Every event the stream emits is a testable artifact — but the exact event vocabulary is a per-provider choice, not a shared standard. Think in terms of signal categories first, then map them to whatever your stack actually emits:</p><ul><li>Run started: The agent accepted the invocation and is producing output.</li><li>Text delta: A chunk of user-visible response. Concatenate in order for the final text.</li><li>Tool call: The agent decided to invoke a tool — first-class signal for routing correctness.</li><li>Tool progress: Optional intermediate status from long-running tools.</li><li>Model reasoning: Chain-of-thought exposed by the model.</li><li>Run completed: Terminal event, plus a summary payload (stop reason, usage, sometimes tool history).</li><li>Error / intervention: Guardrail fired, provider errored, or the stream aborted.</li><li>Product-layer extras: Widgets, links, suggested replies, sources — surfaced by an application layer wrapped around the model, not by the model itself.</li></ul><p>The discipline is the same regardless of naming: collect the full event trace, don’t rely only on the assembled text, and write assertions against the categories you care about — routing bugs live in the tool-call events, not in the final reply.</p><p><strong>2. Detect drift before your suite silently rots</strong></p><p>Agent stacks evolve fast. The failure mode you need to defend against is not “the test fails” — that’s the good failure. The bad failure is “the test still passes but no longer captures the field you care about.” Your suite goes green while the thing under test has changed underneath it.</p><p>There are two shapes of drift, and they need different countermeasures.</p><p><strong>Mechanical drift </strong>— the contract changed. New event subtype, renamed field, retired enum value, tightened input validation. This is catchable before a run: if your stack exposes a schema you can query, do it and diff against what your suite depends on.</p><p>- GraphQL— one introspection call. Diff types, fields, enum values, and the possible-types set for any interface your fragments cover.<br>- Typed RPC (gRPC, Connect, MCP JSON-RPC) — compare the current proto / manifest against the one your client was generated from.<br>- OpenAPI / JSON Schema — pin the version, diff on upgrade.<br>- Tool registries in agent frameworks — enumerate available tools; alert when a tool your suite references disappears or when a new one appears.</p><p>Fail loudly on missing referenced entities. Warn on additive changes (new subtype, new optional field) — your fragments still parse, but you may be dropping data. Cheap insurance where it’s available.</p><p><strong>Behavioral drift </strong>— the contract didn’t change, but the behavior did. Model version bumped, provider tweaked a default, a prompt somewhere in the routing chain got edited, a tool description got reworded. No schema will surface this. What changes is which tool the agent picks, how it phrases a refusal, whether it asks a clarifying question or guesses. Purely prompt- and behavior-driven features live entirely in this world.</p><p>The countermeasure here is different:</p><ul><li><strong>Golden traces.</strong> Pin a small canonical scenario set with expected tool sequences and expected response shapes (not exact wording). Re-run on every prompt/model change. Diff the traces. A route that used to hit `search_docs → summarize` now hits `answer_from_memory` — that’s a signal, whether or not the final text still “looks right.”</li><li><strong>Semantic snapshots.</strong> For text where exact-match is too brittle, store an embedding of the golden response and alert on cosine distance above a threshold. Coarse, but catches “the tone shifted from formal to chatty” style drift.</li><li><strong>Canary questions.</strong> A tiny set of prompts (5–15) that exercise every routing edge you care about. Run them on every prompt or model change. If any canary flips its tool sequence, block the change until a human signs off.</li></ul><p>Neither branch alone is sufficient. A mechanical schema check will catch a renamed field but miss the model swap. A golden-trace suite will catch the model swap but miss the fact that a new required field on the invoke input silently defaulted to `null`. Run both; scope each to what it can actually see.</p><p><strong>3. Derive test scenarios from acceptance criteria — on two axes</strong></p><p>Given a feature spec, most engineers write one test per acceptance criterion. That’s necessary but not sufficient for agents. You need two axes of coverage.</p><p><strong>Axis 1: Category</strong></p><p>For every acceptance criterion, generate:</p><ul><li>One positive scenario — the phrasing a cooperative user would produce.</li><li>One negative scenario per stated exclusion — “the agent must NOT emit widget X when Y” becomes an explicit test that constructs Y and asserts widget X is absent.</li><li>Adversarial variants — misspellings, indirect phrasings, hostile framings, prompts that hint at the wrong tool. Model routing is fragile in exactly these places.</li></ul><p><strong>Axis 2: Persona state</strong></p><p>This is the axis most teams miss.</p><p>When an acceptance criterion is about mutating state — “the agent must turn on feature X,” “the agent must not claim state changed when it hasn’t” — the same question produces different correct behavior depending on whether the persona is already in the target state.</p><p>Cover both:</p><ul><li>State-opposite persona — the feature is currently off, and the AC says “turn it on.” Confirms the write fires when it should. Confirms the informational path doesn’t mutate.</li><li>State-target persona — the feature is already on. Surfaces idempotency bugs, false-positive claims (“I turned it on for you” when it was already on), and no-op handling.</li></ul><p>The bug reporter’s original repro is almost always a single persona state. The AC’s correctness is across both. Silent no-op bugs and phantom-write bugs are invisible on a state-opposite persona alone.</p><p>A rule of thumb: state-opposite carries the full question set; state-target only needs the mutation-relevant subset (explicit commands + informational variants that must not mutate).</p><p><strong>4. Ground the question set before you freeze it</strong></p><p>Acceptance criteria are usually written to be specifiable, not phrased the way users actually talk. If you generate scenarios purely from AC, you’ll test the happy phrasing and miss the routing edges.</p><p>Before finalizing your question set, ground it in whatever design surface you have — prior tickets, PRDs, precedent flows, related bug reports. You’re looking for:</p><p>- Phrasings the design team already worried about.<br>- Adversarial variants that have historically hit routing edges.<br>- Explicit negatives from design docs that never made it into the AC.</p><p>Cap the grounding effort — this is a helper, not the main event. A couple of targeted searches is usually enough to add three or four questions that the raw AC would not have suggested. Those are almost always the ones that catch real bugs.</p><p><strong>5. Human-in-the-loop gates for AI QA</strong></p><p>Traditional test suites run start-to-finish without asking permission. AI QA is different because the test design itself is a judgment call — LLMs let you generate plausible-looking scenarios that miss the point, and the cost of running the wrong test set against the wrong persona is a report that looks legitimate but proves nothing.</p><p>I use four confirmation gates on any spec-driven run:</p><ol><li>Acceptance criteria — after extracting AC from the ticket, show them verbatim and confirm they’re the right criteria to test against.</li><li>Question set — after deriving scenarios, show the full list (category + verbatim message) and let the human add, drop, or edit before you run anything.</li><li>Persona — once a test account is resolved, check if state matches the AC depends on. Confirm before invoking.</li><li>Publishing results — draft the summary comment; wait for explicit confirmation before posting it.</li></ol><p>Everything else — shell commands, grounding searches, running the harness itself — proceeds autonomously. The gates are placed where a human’s judgment is materially better than a model’s, not everywhere.</p><p><strong>6. Judging the result — a layered check</strong></p><p>For each scenario, you want a signal that’s more nuanced than “did the response contain the right substring.”</p><p>Layer 1 — infrastructure signal:</p><p>- Did the invocation actually run? (Distinguish “agent said the wrong thing” from “the mutation was rejected before the agent ran.”)<br>- Did the stream terminate cleanly with a `stop` event?<br>- Did the `metadata.error` flag come back false?</p><p>Layer 2 — hard constraints (when specified in AC):</p><p>- `mustInclude` — token or phrase must appear.<br>- `mustAvoid` — token or phrase must not appear.<br>- `expectedRefusal` — the agent should decline; asserting on the shape of the refusal, not its exact words.</p><p>Layer 3 — event-level assertions:</p><p>- Correct tool called? (Check the `tool_use` events.)<br>- Correct widget emitted? (Check the `metadata.widgets` payload.)<br>- Correct links attached? (Check `sources` / `webSources`.)<br>- Correct in-app link surfaced? (Check `deeplinks.path`, not `deeplinks.title` — titles are display copy; paths are the contract.)<br>- Correct follow-up prompts? (Check `suggestedReplies`.)</p><p>Layer 4 — LLM-as-judge:</p><p>For open-ended criteria (“the response is helpful,” “the tone is appropriate for a hostile user”), a model can score the output. The principle is diversify your judges and never trust a single score, not any specific rule about which model to use.</p><p>Concretely:</p><ul><li>Prefer a different model than the one under test as a default heuristic. Same-model or same-family judges have a documented tendency toward self-preference — rationalizing the mistakes they’d make themselves, scoring their own outputs more favorably in blind pairwise comparisons. It’s a real effect, not a universal one; it’s the reason for the heuristic, not proof it can’t be worked around.</li><li>When you do use same-model judging, mitigate it. Give the judge an explicit rubric rather than a vibes-based prompt. Use reference-based judging (compare against a gold answer) rather than open-ended scoring where you can. Calibrate the judge against a small human-labeled set before trusting it in bulk. Where budget allows, run multiple judges and require agreement.</li><li>Never let the judge decide alone. Judges are a signal; humans review edge cases, especially the ones that flip the pass/fail bit.</li></ul><p><strong>7. Report verbatim, always</strong></p><p>The single highest-leverage QA discipline I’ve adopted is this: never paraphrase agent output in a report.</p><p>Every scenario in the coverage table includes the verbatim response. Newlines get escaped so the table renders, but the words are the words. If a response is too long for a table cell, truncate head+tail with an explicit marker — don’t summarize.</p><p>Two reasons:</p><ol><li>Paraphrase hides bugs. “The agent explained the feature correctly” is a claim; “here’s what it said” is evidence. The difference matters when someone re-reads the report three sprints later.</li><li>Paraphrase erases the phrasing that caused the bug. Half the routing bugs I catch are visible in a single word choice — a specific verb tense, a diminutive, an unexpected hedge. Summarizing them out destroys the signal.</li></ol><p>The report structure I use:</p><ul><li>Summary line — N scenarios / P positive / A adversarial / Q negative / W widgets emitted / E errors.</li><li>Acceptance criteria block— verbatim from the ticket.</li><li>Personas used — one row per distinct test account with just enough state to be interpretable.</li><li>Test results table — one row per scenario: persona, category, question, verbatim response, widgets emitted, pass/fail, one-line rationale.</li><li>Notable observations — 2–5 bullets on anything that surprised me or that the design intent flagged that this run confirmed or contradicted.</li></ul><p>Order the table positive → adversarial → negative. It reads better and helps the reviewer skim.</p><p><strong>Closing thought</strong></p><p>The mistake I made for a long time was thinking of AI QA as a variant of API testing with fuzzier assertions. It isn’t. The transport is stateful, the output is a stream, the assertions live on the event trace as much as the final text, and the persona state is a first-class input to correctness.</p><p>Treat it that way and the tests stop being flaky. They start telling you exactly what changed and why.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7adf64a1ee39" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>