Skip to content

Fix panic in agent.yaml parsing and enable CI tests for azure.ai.agents#6683

Merged
rajeshkamal5050 merged 12 commits intomainfrom
copilot/fix-agent-yaml-parsing-error-again
Feb 5, 2026
Merged

Fix panic in agent.yaml parsing and enable CI tests for azure.ai.agents#6683
rajeshkamal5050 merged 12 commits intomainfrom
copilot/fix-agent-yaml-parsing-error-again

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

This PR fixes a panic that occurred when parsing agent.yaml files that don't have a template field, and enables CI tests for the azure.ai.agents extension.

image image

Changes

Bug Fixes

  • Fix panic when template field is missing: The parser previously crashed with a nil pointer dereference when processing YAML files without a template field. Now it returns a clear error message with documentation links.
  • Fix duplicate error message fragments: Removed redundant error wrapping that caused messages like "YAML content does not conform to AgentManifest format: YAML content does not conform to AgentManifest format: ..." to appear.
  • Update sample agent.yaml files: Changed agent: to template: in test samples to match the correct AgentManifest schema.

Improvements

  • Better error messages: Error messages now include links to the AgentManifest schema documentation and example repositories.
  • Enable CI tests: Added ci-test.ps1 to run unit tests for the azure.ai.agents extension in the CI pipeline.
  • Add comprehensive tests: New tests cover:
    • Valid manifest with template field
    • Empty/null template field
    • Missing template field
    • Invalid template field type
    • The exact YAML from the original issue

Testing

  • All new unit tests pass
  • Tested manually with agent.yaml files both with and without template fields
Original prompt

This section details on the original issue you should resolve

<issue_title>[azure.ai.agents] azd ai agent init panics during agent.yaml parsing with interface conversion error</issue_title>
<issue_description>## Description

When running azd ai agent init -m <path-to-agent.yaml>, the command panics during YAML parsing with an interface conversion error. This happens before any Azure resources are accessed, immediately after reading the agent.yaml file.

Environment

Component Version
azd 1.23.3 (commit c53baf4)
azure.ai.agents extension 0.1.8-preview
OS Windows 11

Steps to Reproduce

  1. Install the azure.ai.agents extension: azd ext install azure.ai.agents
  2. Create an agent.yaml file (see below)
  3. Run: azd ai agent init -m "path/to/agent.yaml" --no-prompt

agent.yaml content

# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/AgentSchema/refs/heads/main/schemas/v1.0/ContainerAgent.yaml

kind: hosted
name: lego-social-media-agent
description: |
    An AI-powered social media content generator for LEGO products.
metadata:
    authors:
        - LEGO Social Media Team
    example:
        - content: Generate a Twitter post about Star Wars LEGO sets
          role: user
    tags:
        - Social Media
        - Content Generation
protocols:
    - protocol: responses
      version: v1
environment_variables:
    - name: POSTGRES_SERVER
      value: ${POSTGRES_SERVER}
    - name: POSTGRES_DATABASE
      value: ${POSTGRES_DATABASE}

Error Output

Initializing AI agent project...

Reading agent.yaml from local file: D:\git\demos\zap1\SocialMediaAgentPython\agent.yaml
panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 1 [running]:
azureaiagent/internal/pkg/agents/agent_yaml.ExtractAgentDefinition({0xc0002c8380, 0x376, 0x377})
        azureaiagent/internal/pkg/agents/agent_yaml/parse.go:50 +0x725
azureaiagent/internal/pkg/agents/agent_yaml.LoadAndValidateAgentManifest({0xc0002c8380, 0x376, 0x377})
        azureaiagent/internal/pkg/agents/agent_yaml/parse.go:23 +0xb0
azureaiagent/internal/cmd.(*InitAction).downloadAgentYaml(0xc000743b30, {0x7ff7ccafe300, 0xc00047a180}, {0xc000134080, 0x33}, {0x0, 0x0})
        azureaiagent/internal/cmd/init.go:1040 +0x1233
azureaiagent/internal/cmd.(*InitAction).Run(0xc000743b30, {0x7ff7ccafe300, 0xc00047a180})
        azureaiagent/internal/cmd/init.go:213 +0x219
azureaiagent/internal/cmd.newInitCommand.func1(0xc00030db08, {0xc00047a0f0?, 0x4?, 0x7ff7cc72f429?})
        azureaiagent/internal/cmd/init.go:150 +0x678
github.com/spf13/cobra.(*Command).execute(0xc00030db08, {0xc00047a090, 0x3, 0x3})
        github.com/spf13/cobra@v1.10.1/command.go:1015 +0xb02
github.com/spf13/cobra.(*Command).ExecuteC(0xc00030cf08)
        github.com/spf13/cobra@v1.10.1/command.go:1148 +0x465

Additional Notes

  • I also tested with a known-working agent.yaml from the copilot-hosted-agent sample and received the same error
  • The panic occurs in parse.go:50 during ExtractAgentDefinition, suggesting the YAML parser expects a specific structure that isn't being found
  • This is different from issue azd ai agent init - panic when initializing agent #6050 which panicked later in the flow (after model SKU selection)

Expected Behavior

The command should either:

  1. Successfully parse the agent.yaml and proceed with initialization, or
  2. Provide a helpful error message if the YAML format is invalid

Impact

This bug completely blocks the azd ai agent workflow for deploying hosted agents to Azure AI Foundry.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 2, 2026 03:37
- Update ExtractAgentDefinition to handle both manifest and standalone formats
- Add nil check for template field before type assertion
- Support flat YAML structure with agent definition at root level
- Add comprehensive tests for both YAML formats and edge cases

Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
- Add support for both 'template' and 'agent' fields in manifest format
- Add test for 'agent' field format used in sample files
- Now supports three formats: template field, agent field, and standalone

Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
@vhvb1989 vhvb1989 marked this pull request as ready for review February 2, 2026 03:40
Copilot AI review requested due to automatic review settings February 2, 2026 03:40
- Add error handling for yaml.Marshal calls
- Replace custom contains function with strings.Contains from stdlib
- Remove redundant helper functions

Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a 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 fixes a panic in azd ai agent init that occurred when parsing agent.yaml files without a template field. The panic was caused by attempting to convert a nil interface{} to a map without proper nil checking.

Changes:

  • Updated ExtractAgentDefinition to handle three YAML formats: manifest with template field, manifest with agent field (alias), and standalone agent definition
  • Added comprehensive test coverage for different YAML parsing scenarios
  • Implemented proper nil checks and type assertions with error messages

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_yaml/parse.go Added logic to handle multiple YAML formats with proper nil checks and type validation to prevent panic
cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_yaml/parse_test.go Added comprehensive test suite covering all three YAML formats and edge cases
Comments suppressed due to low confidence (1)

cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_yaml/parse_test.go:267

  • The custom contains and stringContains helper functions are unnecessary. The standard library's strings.Contains function should be used instead, which is already imported and used extensively throughout the codebase (e.g., in init.go, helpers.go, and parser.go). Replace calls to the custom contains function with strings.Contains directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Update protobuf from 5.29.5 to 6.33.5 in microsoft.azd.extensions
- Addresses JSON recursion depth bypass vulnerability
- Affected versions: <= 6.33.4
- Patched version: 6.33.5

Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic during agent.yaml parsing in azd ai agent init Fix panic in agent.yaml parsing and protobuf security vulnerability Feb 2, 2026
@rajeshkamal5050
Copy link
Contributor

@copilot looks like you weren't able to apply this feedback - #6683 (comment) can you try again?

- Return error when neither 'template' nor 'agent' field exists
- Add check for empty template/agent maps
- Update tests to expect errors for YAMLs without wrapper fields
- Add test for precedence when both fields present
- Add test for empty/null agent field handling

Per feedback: the rest of the code assumes manifest format, so supporting
standalone format would lead to undefined behavior. Now returns a clear
error message with link to AgentSchema documentation.

Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 3, 2026

@copilot looks like you weren't able to apply this feedback - #6683 (comment) can you try again?

Applied the feedback in commit 859d1e8. The code now returns a proper error message when neither template nor agent field exists, instead of attempting to parse the whole document as a standalone agent definition. This prevents the undefined behavior that would occur since the rest of the code assumes manifest format.

Per review feedback, the 'agent' field is not valid in AgentManifest format.
- Remove agent field handling from ExtractAgentDefinition
- Update error messages to only mention 'template' field
- Remove tests for agent field, BothTemplateAndAgent precedence
- Update sample files to use 'template' instead of 'agent'
- Rename EmptyAgentField test to EmptyTemplateField

The AgentManifest struct defines yaml:"template" as the only valid field.
Valid manifest examples: https://github.com/microsoft-foundry/foundry-samples

Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com>
@rajeshkamal5050
Copy link
Contributor

@vhvb1989 @JeffreyCA can we do error with suggestion from extensions? So we could also suggest users to look at the foundry-samples repo link for valid agent yamls

@JeffreyCA
Copy link
Contributor

@vhvb1989 @JeffreyCA can we do error with suggestion from extensions? So we could also suggest users to look at the foundry-samples repo link for valid agent yamls

Yes would be great if we could reuse the enhanced ErrorWithSuggestion changes in #6700. Currently it's in internal package which makes it so it can't be used outside of azd core.

@rajeshkamal5050
Copy link
Contributor

rajeshkamal5050 commented Feb 3, 2026

@vhvb1989 @JeffreyCA can we do error with suggestion from extensions? So we could also suggest users to look at the foundry-samples repo link for valid agent yamls

Yes would be great if we could reuse the enhanced ErrorWithSuggestion changes in #6700. Currently it's in internal package which makes it so it can't be used outside of azd core.

Thanks @JeffreyCA got it.

Lets may be fix the panic right now with error message and pointers to agentschema and the foundry-samples repo links.

We can probably enhance using suggestions on a later PR.

Per review feedback, update error messages to point to:
- AgentManifest reference: https://microsoft.github.io/AgentSchema/reference/agentmanifest
- Sample manifests: https://github.com/microsoft-foundry/foundry-samples

This provides users with both the format specification and working examples
when they encounter YAML format errors.

Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 3, 2026

@copilot can we clean up these changes and emit an appropriate error message pointing to https://microsoft.github.io/AgentSchema/reference/agentmanifest and https://github.com/microsoft-foundry/foundr...

Updated error messages in commit dc2875d to include links to both the AgentManifest reference documentation (https://microsoft.github.io/AgentSchema/reference/agentmanifest) and the foundry-samples repository for working examples.

Add ci-test.ps1 script and remove SkipTests flag to enable unit tests in
the CI pipeline for azure.ai.agents extension.

Changes:
- Create ci-test.ps1 script matching other extensions (uses gotestsum or go test)
- Remove SkipTests: true from release-ext-azure-ai-agents.yml pipeline

This aligns with PR #6589 to enable unit test validation in the CI pipeline.

Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Copilot AI requested a review from danieljurek as a code owner February 3, 2026 23:37
Copilot AI changed the title Fix panic in agent.yaml parsing Fix panic in agent.yaml parsing and enable CI tests for azure.ai.agents Feb 3, 2026
@JeffreyCA JeffreyCA requested a review from trangevi February 3, 2026 23:39
@JeffreyCA JeffreyCA self-assigned this Feb 3, 2026
@JeffreyCA JeffreyCA dismissed trangevi’s stale review February 4, 2026 17:24

Addressed feedback

Copilot AI added a commit that referenced this pull request Feb 4, 2026
…#6695

Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
@rajeshkamal5050 rajeshkamal5050 merged commit 1e62693 into main Feb 5, 2026
19 checks passed
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.

[azure.ai.agents] azd ai agent init panics during agent.yaml parsing with interface conversion error

5 participants