-
Notifications
You must be signed in to change notification settings - Fork 2.2k
azure-ai-agents LRO poller util fix for custom end states #48157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+278
−83
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7689800
Poller fix
jpalvarezl 7a4df25
Polled operation fix changelog entries
jpalvarezl 0216116
PR copilot feedback
jpalvarezl 998166b
New recordings
jpalvarezl e7dabcb
Using TSP defined custom status for PollUtils
jpalvarezl ad70deb
Removed comments
jpalvarezl 780e2ff
Using right value for header from enum
jpalvarezl d84dc59
Added comment with warning
jpalvarezl c4b39b2
Merge branch 'main' into jpalvarezl/fix/memory_store_tests
jpalvarezl da452ae
Merge branch 'main' into jpalvarezl/fix/memory_store_tests
jpalvarezl 08bf02a
Applying poller customization through AgentsCustomization.java
jpalvarezl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
85 changes: 85 additions & 0 deletions
85
...re-ai-agents/src/main/java/com/azure/ai/agents/implementation/AgentsServicePollUtils.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.ai.agents.implementation; | ||
|
|
||
| import com.azure.ai.agents.models.FoundryFeaturesOptInKeys; | ||
| import com.azure.ai.agents.models.MemoryStoreUpdateStatus; | ||
| import com.azure.core.http.HttpHeaderName; | ||
| import com.azure.core.http.HttpHeaders; | ||
| import com.azure.core.http.policy.AddHeadersFromContextPolicy; | ||
| import com.azure.core.util.Context; | ||
| import com.azure.core.util.polling.LongRunningOperationStatus; | ||
| import com.azure.core.util.polling.PollResponse; | ||
| import com.azure.core.util.polling.PollingStrategyOptions; | ||
|
|
||
| /** | ||
| * Shared polling helpers for the Agents SDK. | ||
| * | ||
| * <p>The generated {@code OperationLocationPollingStrategy} / {@code SyncOperationLocationPollingStrategy} | ||
| * delegate here so that the two strategies stay in sync and only minimal edits are needed in the | ||
| * generated files.</p> | ||
| * | ||
| * <p>This class is package-private; it is <b>not</b> part of the public API.</p> | ||
| */ | ||
| final class AgentsServicePollUtils { | ||
|
|
||
| /** Required preview-feature header for Memory Stores operations. */ | ||
| private static final HttpHeaderName FOUNDRY_FEATURES = HttpHeaderName.fromString("Foundry-Features"); | ||
| private static final String FOUNDRY_FEATURES_VALUE = FoundryFeaturesOptInKeys.MEMORY_STORES_V1_PREVIEW.toString(); | ||
|
|
||
| private AgentsServicePollUtils() { | ||
| } | ||
|
|
||
| /** | ||
| * Adds the {@code Foundry-Features} header to the given {@link PollingStrategyOptions}'s | ||
| * {@link Context}. If the context already carries {@link HttpHeaders} under the | ||
| * {@link AddHeadersFromContextPolicy} key they are preserved; the {@code Foundry-Features} | ||
| * entry is merged in. Because the pipeline already contains | ||
| * {@link AddHeadersFromContextPolicy}, the header is automatically added to every HTTP | ||
| * request the parent strategy makes (initial, poll, and final-result GETs). | ||
| * | ||
| * <p><strong>Note:</strong> this method mutates and returns the same | ||
| * {@code PollingStrategyOptions} instance.</p> | ||
| */ | ||
| static PollingStrategyOptions withFoundryFeatures(PollingStrategyOptions options) { | ||
| Context context = options.getContext() != null ? options.getContext() : Context.NONE; | ||
| Object existing = context.getData(AddHeadersFromContextPolicy.AZURE_REQUEST_HTTP_HEADERS_KEY).orElse(null); | ||
| HttpHeaders headers | ||
| = (existing instanceof HttpHeaders) ? new HttpHeaders((HttpHeaders) existing) : new HttpHeaders(); | ||
| headers.set(FOUNDRY_FEATURES, FOUNDRY_FEATURES_VALUE); | ||
| return options.setContext(context.addData(AddHeadersFromContextPolicy.AZURE_REQUEST_HTTP_HEADERS_KEY, headers)); | ||
| } | ||
|
|
||
| /** | ||
| * Remaps a {@link PollResponse} whose status may contain a custom service terminal state | ||
| * ({@code "completed"}, {@code "superseded"}) that the base {@code OperationResourcePollingStrategy} | ||
| * cannot recognize. If no remapping is needed the original response is returned as-is. | ||
| * | ||
| * <p>The Memory Stores Azure core defines:</p> | ||
| * <ul> | ||
| * <li>{@code "completed"} {@link LongRunningOperationStatus#SUCCESSFULLY_COMPLETED}</li> | ||
| * <li>{@code "superseded"} {@link LongRunningOperationStatus#USER_CANCELLED}</li> | ||
| * </ul> | ||
| */ | ||
| static <T> PollResponse<T> remapStatus(PollResponse<T> response) { | ||
| LongRunningOperationStatus status = response.getStatus(); | ||
| LongRunningOperationStatus mapped = mapCustomStatus(status); | ||
| if (mapped == status) { | ||
| return response; | ||
| } | ||
| return new PollResponse<>(mapped, response.getValue(), response.getRetryAfter()); | ||
| } | ||
|
|
||
| private static LongRunningOperationStatus mapCustomStatus(LongRunningOperationStatus status) { | ||
| // Standard statuses (Succeeded, Failed, Canceled, InProgress, NotStarted) are already | ||
| // mapped correctly by the parent's PollResult; only remap the custom ones. | ||
| String name = status.toString(); | ||
| if (MemoryStoreUpdateStatus.COMPLETED.toString().equalsIgnoreCase(name)) { | ||
| return LongRunningOperationStatus.SUCCESSFULLY_COMPLETED; | ||
| } else if (MemoryStoreUpdateStatus.SUPERSEDED.toString().equalsIgnoreCase(name)) { | ||
| return LongRunningOperationStatus.USER_CANCELLED; | ||
| } | ||
| return status; | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.