feat: add request metadata to the conversation history and emitted telemetry #2313
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes:
Adding metadata about our send message requests, storing it as part of the conversation history, and sending it as part of
ChatAddedMessage
telemetry.Details
Couple things to call out:
ChatAddedMessage
telemetry is now correctly being sent in all error cases, and sent after tool use execution. We may need to add more timing information after tool use execution completes, but this is omitted for now.RequestMetadata
is created for including information about how the response stream is handled (contains timing info between chunks, total size, etc.). This is stored in the conversation history.RequestMetadata
on sigint is seemingly required by the use of anArc<Mutex<Option<RequestMetadata>>>
value. This is essentially shared state between the response handler and the sigint handler, and is required because the sigint handler has no notion of what the stream output would be otherwise. This isn't ideal, but seems to be required with the current code setup without a larger refactor around ctrl+c handling.codewhispererterminal_recordUserTurnCompletion
to the definitions, but is currently unimplemented in the code. This will be done in a followup PR.Important Callouts
This will break the conversation serialization format with the current version since the history is being updated from
(UserMessage, AssistantMessage)
to a structHistoryEntry { user, assistant, request_metadata }
.If we want to preserve backwards compatibility, then a separate PR could be made adding versioning to the conversation state instead, but doing that as part of this PR would be too much work.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.