Repository navigation
Conversation
…gents#4015) The trace portion of the model metadata event (e.g. Bedrock guardrail assessments) was dropped after usage/metrics extraction, so it never reached the assistant message metadata and was unavailable in AfterModelCallEvent.ModelStopResponse.message. Capture trace in process_stream and thread it onto the assistant message metadata (via event_loop), and add a trace field to MessageMetadata. The ModelStopReason tuple shape is unchanged to avoid touching its many consumers.
|
Refreshed this branch onto the latest Verification after the refresh:
|
|
Refreshed this branch onto the latest Verification on the refreshed head:
The trace-metadata behavior remains covered on the current base. |
|
Refreshed this PR onto the latest Verification from
GitHub reports the branch as mergeable; the maintainer-controlled Strands review gate remains pending. |
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
…tasks/4015 Co-authored-by: TRAE CLI <traecli@bytedance.com>
Description
Closes #4015.
When a model emits a metadata event containing a
trace(e.g. Bedrock guardrail assessments returned by the Converse API), the event loop extracted onlyusageandmetricsand discarded thetrace. As a result the trace was never attached to the assistant message metadata and was unavailable inAfterModelCallEvent.ModelStopResponse.message, so hooks could not inspect guardrail results without resorting to a callback + global/agent state workaround (as described in the issue).Changes
event_loop/streaming.py: capture thetraceportion of the metadata chunk inprocess_streamand attach it to the constructed assistant message metadata. TheModelStopReasontuple shape is intentionally left unchanged (it has many consumers), so the trace travels on the message rather than by widening the tuple.event_loop/event_loop.py: when populatingmessage["metadata"](usage/metrics), preserve anytracecaptured during streaming so it reaches hooks/events/state.types/content.py: add an optionaltracefield toMessageMetadata.The trace key is only added when the provider actually emits a trace, so messages without a trace are unchanged.
Testing
hatch test tests/strands/event_loop/test_event_loop_metadata.py— 5 passed (2 new regression tests: trace surfaces on the assistant message metadata; notracekey added when absent).hatch test tests/strands/event_loop/test_streaming.py tests/strands/event_loop/test_event_loop.py— 144 passed.hatch test tests/strands/hooks tests/strands/types— 167 passed.ruff check/ruff format --check— clean;mypyon the changed modules — no issues.Note
I use a coding assistant to help implement, and I review and take responsibility for the final change.