Repository navigation
fix(agent): preserve structured output before history offloading - #5429
Conversation
|
Marking this ready for review. One housekeeping note: this is a TypeScript-only change (touches only |
|
Hi maintainers — gentle nudge: the "Run integration tests" check on this PR has been sitting in |
|
I've merged from main, because there were unrelated test failures fixed in main. Once the CI passes, PR should merge. Thank you for the fix! :) |
Reapplies two fixes from main that were dropped when the earlier rebase of 31800e8 resolved via --theirs: - fa313cc (strands-agents#5429) extract structuredOutput before the deferred append, so a message-added hook that offloads the JSON block can't lose it. - a4865cd (strands-agents#5628) activate interrupt state before yielding InterruptEvents in the catch path, so a consumer that stops at an InterruptEvent can still resume.
Reapplies two fixes from main that were dropped when the earlier rebase of 31800e8 resolved via --theirs: - fa313cc (strands-agents#5429) extract structuredOutput before the deferred append, so a message-added hook that offloads the JSON block can't lose it. - a4865cd (strands-agents#5628) activate interrupt state before yielding InterruptEvents in the catch path, so a consumer that stops at an InterruptEvent can still resume.
Reapplies two fixes from main that were dropped when the earlier rebase of 31800e8 resolved via --theirs: - fa313cc (strands-agents#5429) extract structuredOutput before the deferred append, so a message-added hook that offloads the JSON block can't lose it. - a4865cd (strands-agents#5628) activate interrupt state before yielding InterruptEvents in the catch path, so a consumer that stops at an InterruptEvent can still resume.
…ands-agents#5429) Co-authored-by: Murat Kaan Meral <[email protected]>
Human Overview
Summary
Fix an issue where large agent responses get truncated by context management before being returned to the caller.
The Problem
When the agent generates a valid but lengthy response, context management compresses it into a short preview for history. The app then pulls the final result from this pruned history, receiving an incomplete answer and often triggering unnecessary retry loops or degraded returns.
The Fix
Decouple conversation context from the final deliverable:
Verification
Description
Context management can replace a successful structured-output tool result with a text preview before the agent returns it, losing the validated answer and triggering another model call. Capture that validated output before message-added hooks while preserving hook-requested end turns and history offloading.
Related Issues
Resolves #5207
Documentation PR
No documentation change is needed; this restores the existing structured-output behavior.
Type of Change
Bug fix
Testing
Offline regression: two cases fail on the original implementation and pass with the fix. The affected Agent file passes in Node and Chromium (141 tests). Related Node tests pass (723); full Node coverage passes (5353 passed, 6 skipped). Build, lint, formatting, type-check and browser bundle pass. The pre-push aggregate reports existing dependency advisories (3 high, 6 moderate); dependency files are unchanged. No live-provider integration tests were run.
hatch run prepareAdditional Details
Validation and AI assistance
TypeScript-only change. Ran the repository's pre-push script, the affected Agent browser tests, and the offline MockMessageModel reproduction. The configured npm mirror does not support its audit endpoint; the official npm registry audit reports the existing advisories above. Full browser coverage, package smoke tests and real-provider integrations were not run.
AI assisted the investigation, implementation, tests and technical PR draft. The Human Overview above is the contributor's own text, preserved as provided. Update to its verification status: independent review by a fresh Astra xhigh agent is now complete with no actionable findings; it separately passed 312 focused tests and six offline edge probes. This fix concerns validated tool-based structured output. The human reading and understanding attestations have since been explicitly confirmed by the contributor and are checked in the checklist below.
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.