.NET: Allow custom argument marshaling for skill scripts#6498
Open
SergeyMenshykh wants to merge 2 commits into
Open
.NET: Allow custom argument marshaling for skill scripts#6498SergeyMenshykh wants to merge 2 commits into
SergeyMenshykh wants to merge 2 commits into
Conversation
Add an optional Func<JsonElement?, AIFunctionArguments> argument marshaler to inline and class-based skills so callers can customize how raw JSON tool-call arguments are converted into AIFunctionArguments before delegate invocation. This enables handling backends (e.g. vLLM) that send tool-call arguments as a JSON string instead of a JSON object. The marshaler can be supplied at the script, inline-skill, or class-skill level; when omitted, the existing strict JSON-object behavior is preserved unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces configurable argument marshaling for .NET skill scripts so callers can handle OpenAI-compatible backends (e.g., vLLM) that emit tool-call arguments as a JSON string instead of a JSON object, while preserving the existing strict default behavior.
Changes:
- Added an optional
Func<JsonElement?, AIFunctionArguments>? argumentMarshalerthat converts raw JSON arguments intoAIFunctionArgumentsbefore invoking the script delegate. - Plumbed the marshaler through
AgentInlineSkillScript,AgentInlineSkill(skill-level default), andAgentClassSkill<T>(applies to discovered/programmatic scripts). - Added unit tests covering default behavior vs. custom string-parsing marshaler behavior and precedence rules.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/SkillScriptArgumentMarshalerTests.cs | Adds tests validating default strict object-only marshaling and custom marshaler support (including vLLM-like string-wrapped JSON). |
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkillScript.cs | Adds a per-script marshaler hook and uses it in RunAsync prior to AIFunction invocation. |
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkill.cs | Adds a skill-level default marshaler and wires it into scripts added via AddScript. |
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentClassSkill.cs | Adds a skill-level marshaler for class-based skills and passes it to discovered/programmatic scripts. |
Comments suppressed due to low confidence (1)
dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentClassSkill.cs:124
- AgentClassSkill is a public base class; replacing the protected parameterless constructor with a single ctor that takes an (optional) parameter is a binary-breaking change for already-compiled derived skills (they will look for base .ctor() and fail at runtime). Keep a true parameterless ctor and add a new overload that accepts argumentMarshaler.
protected AgentClassSkill(Func<JsonElement?, AIFunctionArguments>? argumentMarshaler = null)
{
this._argumentMarshaler = argumentMarshaler;
this._resources = new Lazy<IReadOnlyList<AgentSkillResource>?>(this.DiscoverResources);
this._scripts = new Lazy<IReadOnlyList<AgentSkillScript>?>(this.DiscoverScripts);
this._content = new Lazy<string>(() => AgentInlineSkillContentBuilder.Build(
this.Frontmatter.Name,
this.Frontmatter.Description,
this.Instructions,
this.Scripts));
}
peibekwe
approved these changes
Jun 12, 2026
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.
Summary
vLLM and some other OpenAI-compatible backends send tool-call
argumentsas a JSON string (e.g."{\"query\":\"hello\"}") instead of a JSON object. Skill scripts only accept a JSON object, so these calls fail with anInvalidOperationException.This PR lets callers plug in their own argument conversion logic.
Changes
Func<JsonElement?, AIFunctionArguments>? argumentMarshalerthat controls how raw JSON arguments are converted before the script delegate runs.AgentInlineSkillScriptconstructor - per script.AgentInlineSkillconstructor - applies to all scripts added viaAddScript.AgentClassSkill<T>constructor - applies to discovered scripts and those created viaCreateScript.InvalidOperationExceptionis thrown.Closes #6020