Skip to content

fix: scope system-instruction change detection to a single agent - #522

Open
mittalpk wants to merge 1 commit into
google:mainfrom
mittalpk:fix/scope-system-instruction-diff-to-agent
Open

fix: scope system-instruction change detection to a single agent#522
mittalpk wants to merge 1 commit into
google:mainfrom
mittalpk:fix/scope-system-instruction-diff-to-agent

Conversation

@mittalpk

@mittalpk mittalpk commented Sep 3, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #462 — the "System Instruction Performance Analysis" warning in the dev UI false-positives on any multi-agent / sub-agent session, even when no system instruction was actually modified.

updateSystemInstructionFlags() in chat.component.ts flattens every LLM span across a session, sorts by time, and compares each chronologically-adjacent pair for a changed system instruction — with no partitioning by agent. In a root-agent-delegates-to-sub-agent flow, the LLM calls interleave across agents (e.g. root -> sub -> sub -> root), so two calls from different agents end up compared directly. Each agent has its own system instruction and its own cache context, so this is a category error, not a real change — independent of whether the two agents happen to share a model/provider.

The fix

Group the (already time-sorted) LLM spans by agent before doing the consecutive-pair comparison, instead of comparing across the whole session. The comparison logic itself is unchanged — it's the same per-pair check, just scoped to run within each agent's own sequence of calls.

Agent identity is resolved as eventData.get(span.attrEventId)?.author, falling back to the span's own attrAgentName (an OTel-promoted attribute that already exists on Span but wasn't used anywhere in the app) when the event lookup doesn't resolve — e.g. for spans without a matching event in eventData.

Testing

Added 3 unit tests for updateSystemInstructionFlags() (previously untested):

  • Two LLM turns from different agents with different system instructions → no longer flagged.
  • Two LLM turns from the same agent with a genuinely different system instruction → still correctly flagged (unchanged behavior).
  • The attrAgentName fallback path, when the event has no resolvable author.

Confirmed the first and third tests fail against the pre-fix code (Expected true to be falsy) and pass after this change. Full test suite (646 tests) and ng build both pass.

updateSystemInstructionFlags() compared consecutive LLM spans across the
entire session, with no partitioning by agent. In any multi-agent /
sub-agent flow, crossing an agent boundary makes the system instruction
legitimately differ (each agent has its own instruction and cache
context), which incorrectly tripped the "System Instruction Performance
Analysis" warning and showed a diff between two unrelated agents' prompts.

Group the time-sorted LLM spans by agent (event author, falling back to
the span's own attrAgentName) before comparing consecutive turns, so the
comparison only ever runs within a single agent's own sequence of calls.

Fixes google#462
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adk web: 'System Instruction Performance Analysis' false-positives in multi-agent sessions

1 participant