Skip to content

Fix empty Tools collection when loading PromptAgent from YAML#84

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-empty-tools-collection
Draft

Fix empty Tools collection when loading PromptAgent from YAML#84
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-empty-tools-collection

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

YamlDotNet 16.x deserializes nested YAML mappings as Dictionary<object, object>, but the generated LoadXxx collection methods only matched on Dictionary<string, object?>, causing all collection-type properties (tools, bindings, parameters, etc.) to be silently empty after YAML deserialization.

Changes

  • utils.cs.njk — Added NormalizeDictionary and NormalizeValue extension methods to Utils that recursively convert Dictionary<object, object>Dictionary<string, object?>, including nested values and lists.

  • file.cs.njk — Updated the generated LoadXxx collection template to normalize YamlDotNet dicts at method entry, and added an else if (item is Dictionary<object, object>) branch in the list-item loop.

These two template changes are applied automatically to all generated collection loaders: PromptAgent.LoadTools, Tool.LoadBindings, AgentManifest.LoadResources, ContainerAgent.LoadProtocolVersions, ObjectProperty.LoadProperties, PropertySchema.LoadProperties.

// Before — silently returns empty list from YAML
if (data is Dictionary<string, object?> dict) { ... }
else if (data is IEnumerable<object> list) { ... }

// After — normalizes YamlDotNet's dict type, handles both formats
if (data is Dictionary<object, object> rawYamlDict)
    data = rawYamlDict.NormalizeDictionary(); // recursive normalization

if (data is Dictionary<string, object?> dict) { ... }
else if (data is IEnumerable<object> list)
{
    // list items also normalized
    else if (item is Dictionary<object, object> yamlItemDict)
        result.Add(T.Load(yamlItemDict.NormalizeDictionary(), context));
}
  • PromptAgentToolsYamlTests.cs — Adds regression tests covering dictionary-format and list-format tools YAML deserialization.

Copilot AI changed the title [WIP] Fix empty tools collection when loading PromptAgent from YAML Fix empty Tools collection when loading PromptAgent from YAML Apr 3, 2026
Copilot AI requested a review from sethjuarez April 3, 2026 02:06
@sethjuarez
Copy link
Copy Markdown
Member

Hmmm - super important to remember that the CSharp code is generated from the emitter - we may need to update the template files for the emitter - @copilot - can you take that line of inquiry please?

@kerbybarrett
Copy link
Copy Markdown

Any plans to review/merge this? I currently have a locally cloned version of the c# code with my own fix, which is ... less than ideal. Or are there plans to leverage anything coming out of Foundry roadmap for canonical agent schema perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Yaml parsing for csharp returns empty tools collection

3 participants