-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add internal method overloads that take RequestContext #52777
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
base: main
Are you sure you want to change the base?
Add internal method overloads that take RequestContext #52777
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds internal method overloads that accept RequestContext
instead of CancellationToken
to provide more flexibility for configuring requests without abandoning convenience methods. The changes enable setting custom headers (like user-agent) on requests while maintaining the existing public surface.
Key changes:
- Replaces
FromCancellationToken()
calls withToRequestContext()
extension method - Adds internal method overloads accepting
RequestContext
parameters - Implements user-agent header injection for MEAI implementation
Reviewed Changes
Copilot reviewed 7 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
CancellationTokenExtensions.cs |
New extension method to convert CancellationToken to RequestContext |
PersistentAgentsChatClient.cs |
Adds user-agent policy and converts method calls to use RequestContext |
ThreadRuns.cs |
Adds internal GetRunsAsync overload and converts to use extension method |
ThreadRuns.Streaming.cs |
Adds internal streaming method overloads and converts method calls |
PersistentAgentsFiles.cs |
Converts file upload methods to use extension method |
PersistentAgentsAdministrationClient.cs |
Removes obsolete protocol method documentation |
PersistentAgentsChatClientTests.cs |
Minor whitespace cleanup |
sdk/ai/Azure.AI.Agents.Persistent/src/Custom/PersistentAgentsChatClient.cs
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/src/Custom/PersistentAgentsChatClient.cs
Outdated
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/src/Custom/ThreadRuns.Streaming.cs
Outdated
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/src/Custom/PersistentAgentsAdministrationClient.cs
Outdated
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/src/Custom/PersistentAgentsChatClient.cs
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/src/Custom/PersistentAgentsChatClient.cs
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/tests/PersistentAgentsChatClientTests.cs
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/tests/PersistentAgentsChatClientUserAgentHeaderTests.cs
Outdated
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/tests/Azure.AI.Agents.Persistent.Tests.csproj
Outdated
Show resolved
Hide resolved
sdk/ai/Azure.AI.Agents.Persistent/tests/PersistentAgentsChatClientUserAgentHeaderTests.cs
Outdated
Show resolved
Hide resolved
…o add-requestoptions-internal-api
…o add-requestoptions-internal-api
Contributing to the Azure SDK
Note
This doesn't change current existing public surface.
Today, if you're using the convenience types and you just want to set a user-agent header on a request (you're handed the instance and thus can't configure it at creation), the only supported option I see is to abandon the convenience methods and adopt the protocol methods, which some of those methods are internal as well as most of the types used for those are also internal which means formatting all the input JSON and parsing all the responses. That's a big pill to swallow.
Based on need, could we add a few convenience overloads that just take a RequestContext instead of a CancellationToken?. It results in minimal additional surface area with almost no additional duplicated code, as it's just taking a RequestContext instead of taking a CancellationToken and calling ToRequestContext on it.
I've demonstrated in this PR with methods used by
PersistentAgentChatClient
implementation internals, as well as other methods that are important for AgentCreation in the upcoming agent framework.Similar to this
OpenAI SDK
update:Additional changes
CC: @stephentoub