MicrosoftExtensions: Idiomatic CacheControl Support#73
Open
PederHP wants to merge 2 commits intoanthropics:nextfrom
Open
MicrosoftExtensions: Idiomatic CacheControl Support#73PederHP wants to merge 2 commits intoanthropics:nextfrom
PederHP wants to merge 2 commits intoanthropics:nextfrom
Conversation
b38ea33 to
6a6e29c
Compare
Contributor
Author
|
Let me know if you want a separate extension for beta and non-beta cache control (currently the outer one is shared). I also added a new file. I can fold it into the extensions file, but it's getting massive, so I think if it's not ok to have more than one top-level MEAI related file - then maybe there should be a folder? Otherwise the file is just going to keep growing and get more and more unwieldy. |
a6ccfa7 to
007b0c0
Compare
6a6e29c to
f88b66b
Compare
ae28dee to
edc3cfb
Compare
Add handling for nullable union types (e.g., "type": ["integer", "null"]) generated by the C# MCP SDK for optional nullable parameters. Transforms them to simple types for non-required properties since structured outputs doesn't support union types. Changes: - Add nullable union type normalization in schema transform - Add TransformNullableUnionType helper for tool property processing - Reorder required/properties parsing to support transformation - Add tests for nullable union type transformation
Add AIContentCacheExtensions with WithCacheControl() methods that allow setting Anthropic prompt caching on AIContent instances via AdditionalProperties. Changes: - New AIContentCacheExtensions.cs with WithCacheControl(CacheControlEphemeral) and WithCacheControl(TTL) extension methods - Update CreateMessageParams in both AnthropicClientExtensions and AnthropicBetaClientExtensions to apply cache control when mapping AIContent to Anthropic content block params (TextBlockParam, ImageBlockParam, DocumentBlockParam, ToolUseBlockParam, ToolResultBlockParam) - Fix system message handling in both clients to support cache control - Add unit tests for extension methods and request serialization The Beta client converts from CacheControlEphemeral to BetaCacheControlEphemeral internally, so users can use the same extension methods with both clients.
6892ce7 to
413a2b2
Compare
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.
For agentic loops the cost difference between caching and not caching is massive, and it's really awkward to use caching with the extensions. And not really possible at all at the system-level (because of how it converts without using the raw representation factory). Using raw representation factory also means one has to re-implement the mapping from MEAI to Anthropic content types. Instead this PR adds a new extension method that uses AdditionalProperties to store the CacheControl and then uses it while mapping in the existing extension code.