Skip to content

fix: use non-interactive flag for Nova Sonic history and system promp…#2188

Open
prettyprettyprettygood wants to merge 1 commit intostrands-agents:mainfrom
prettyprettyprettygood:nova-sonic-session-renewal
Open

fix: use non-interactive flag for Nova Sonic history and system promp…#2188
prettyprettyprettygood wants to merge 1 commit intostrands-agents:mainfrom
prettyprettyprettygood:nova-sonic-session-renewal

Conversation

@prettyprettyprettygood
Copy link
Copy Markdown

@prettyprettyprettygood prettyprettyprettygood commented Apr 22, 2026

…t events

Description

When a BidiAgent session is renewed (stopped and recreated with conversation history), Nova Sonic repeats or re-summarizes prior assistant responses. This happens because conversation history messages are sent with interactive: True, causing Nova Sonic to treat them as new live inputs requiring a response rather than prior context.

Additionally, there are no size guards on replayed history, so unbounded message accumulation can cause failures or degraded performance on session renewal.

Public API Changes

_get_text_content_start_event now accepts an optional interactive parameter (defaults to True, fully backward compatible):

# Before
def _get_text_content_start_event(self, content_name: str, role: str = "USER") -> str:

# After
def _get_text_content_start_event(self, content_name: str, role: str = "USER", interactive: bool = True) -> str:

No changes to any public-facing API. All changes are internal to BidiNovaSonicModel.

Changes

  • History messages are now sent with interactive: False so Nova Sonic treats them as prior context, not new inputs
  • System prompt events are also sent with interactive: False to match Nova Sonic best practices
  • Individual history messages are truncated to 50KB, total history capped at 200KB
  • When the size limit is reached, oldest messages are dropped first to prioritize recent context
  • History replay always starts with a user-role message (leading assistant messages are dropped)

Related Issues

Documentation PR

Type of Change

Bug fix

Testing

  • Tested with a local BidiAgent harness that refreshes sessions every 30 seconds

  • Verified via debug logging that history messages are sent with interactive: false

  • Confirmed Nova Sonic no longer repeats prior responses after session renewal

  • Validated that oldest messages are correctly dropped when history exceeds size limits

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment thread src/strands/experimental/bidi/models/nova_sonic.py Outdated
Comment thread src/strands/experimental/bidi/models/nova_sonic.py Outdated
Comment thread src/strands/experimental/bidi/models/nova_sonic.py
@github-actions
Copy link
Copy Markdown

Assessment: Request Changes

The core fix (setting interactive=False for history and system prompt events) is well-motivated and the implementation logic is sound. The two-pass approach for size-limited history with newest-first priority is a good design choice.

Review Categories
  • Testing: This is the primary blocker — the PR introduces significant new behavior (interactive flag, truncation, size caps, leading-message stripping) with zero new or updated tests. The existing tests don't assert on the interactive field, so the central bug fix has no automated verification.
  • Maintainability: Size limit constants are inlined as magic numbers; extracting them as module/class constants would improve discoverability and testability.
  • Minor efficiency: A small redundant UTF-8 re-encoding in the truncation path.

The approach and reasoning are solid — just needs test coverage to land safely.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant