Use image-aware text estimates throughout loop budgeting - #64
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The loop independently estimated context by stringifying messages, turning image base64 into millions of text tokens even when the provider understood typed media. Use a structured text-only estimate consistently in preflight, measured candidates, overflow recovery, and both dispatch telemetry paths. Image token cost remains unknown without a provider count; images and canonical history are untouched. Provider-native limits and failure semantics are unchanged.
Companion context-simple and context-managed changes remove the same false accounting upstream of the loop. Class review included loop-basic/events (delegate context budgeting), Microsoft and bkrabach loop-live (delegate execution to streaming), all known provider sources, and the latest MODULES.md catalog. No host/Foundation dependency is added.
Validation: 449 loop tests pass, including 20 large-valid-PNG runtime scenarios across streaming/nonstreaming, estimate/actual context modes, and absent/unavailable/exact/oversized/failed counters. Existing real OpenAI integration tests run without skips. The real Unified fixture sends the original 6,310,938-byte PNG once and completes with no image data in public events and no network requests. OpenAI request-budget suite: 85 pass. Live provider acceptance and deployment dependency updates remain pending. New files pass Ruff; pre-existing main-file lint findings are unchanged.
Companion draft PRs: microsoft/amplifier-module-context-simple#46, #64, microsoft/amplifier-bundle-context-managed#11.
Text estimates are partial, not a complete-request fit guarantee. Provider-native counts, request-size validation, and actual provider errors retain authority.