Skip to content

feat(conversation): add metrics and usage types and deserializers#697

Draft
pjkroker wants to merge 8 commits intoaws-amplify:mainfrom
pjkroker:feature/bedrock-model-usage
Draft

feat(conversation): add metrics and usage types and deserializers#697
pjkroker wants to merge 8 commits intoaws-amplify:mainfrom
pjkroker:feature/bedrock-model-usage

Conversation

@pjkroker
Copy link
Copy Markdown
Contributor

@pjkroker pjkroker commented Mar 26, 2026

Problem

Streaming conversation responses from the Bedrock Converse API do not expose model usage or latency information. Consumers have no way to track token consumption or response latency for conversation turns.
Issue number: aws-amplify/amplify-backend#2355

Related PRs (all required for aws-amplify/amplify-backend#2355)

This feature spans 4 repositories. PRs should be merged in this order:

  1. amplify-category-apiaws-amplify/amplify-category-api#3448 — Defines AmplifyAIMetrics/AmplifyAIUsage GraphQL types and updates resolvers
  2. amplify-dataaws-amplify/amplify-data#697 — Adds TypeScript types and client-side deserializers
  3. amplify-backendaws-amplify/amplify-backend#3148 — Captures metrics/usage from Bedrock streaming response
  4. amplify-codegenaws-amplify/amplify-codegen#1008 — Adds fields to generated introspection metadata

Changes

Adds metrics and usage fields to conversation messages and stream events across the GraphQL schema, TypeScript types, and runtime deserializers.

Specifically:

  • AmplifyAIMetrics GraphQL type (latencyMs: Int) added to ConversationSchemaGraphQLTypes.ts
  • AmplifyAIUsage GraphQL type (inputTokens, outputTokens, totalTokens) added to ConversationSchemaGraphQLTypes.ts
  • metrics and usage fields added to AmplifyAIConversationMessage and AmplifyAIConversationMessageStreamPart
  • ConversationMessage TypeScript interface updated with optional metrics and usage
  • ConversationStreamEvent types updated — metrics/usage present on turn-done events, never on other event types
  • Runtime deserializers (convertItemToConversationMessage, conversationStreamEventDeserializers) pass through metrics and usage when present

Corresponding docs PR, if applicable:

Validation

  • Ran yarn build in packages/data-schema — builds cleanly
  • Ran yarn test in packages/data-schema — all tests pass
  • Added unit tests for convertItemToConversationMessage (metrics/usage present and absent)
  • Added unit tests for conversationStreamEventDeserializers (turn-done with metrics/usage, text event without, error event)
  • Updated createOnStreamEventFunction tests to include metrics/usage in expected undefined fields
  • Added defined behavior tests in 2-expected-use/ai-conversation.ts for list messages and turn-done stream events with metrics/usage
  • Updated snapshots for new GraphQL types
  • Manually tested against a Bedrock conversation endpoint

Checklist

  • If this PR includes a functional change to the runtime or type-level behavior of the code, I have added or updated automated test coverage for this change. (see Testing Strategy README)
  • If this PR requires a docs update, I have linked to that docs PR above.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 26, 2026

🦋 Changeset detected

Latest commit: 814af54

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/data-schema Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pjkroker pjkroker force-pushed the feature/bedrock-model-usage branch 3 times, most recently from 4eb3a97 to 6f31842 Compare March 30, 2026 09:13
@pjkroker pjkroker force-pushed the feature/bedrock-model-usage branch from 6f31842 to d1a7e9a Compare March 30, 2026 09:17
@pjkroker pjkroker force-pushed the feature/bedrock-model-usage branch from d1a7e9a to 0f5a822 Compare March 30, 2026 09:23
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.

1 participant