Skip to content

feat: implement agent template initialization and selection process#7052

Draft
therealjohn wants to merge 2 commits intoAzure:mainfrom
therealjohn:init-filtered-templates
Draft

feat: implement agent template initialization and selection process#7052
therealjohn wants to merge 2 commits intoAzure:mainfrom
therealjohn:init-filtered-templates

Conversation

@therealjohn
Copy link

@therealjohn therealjohn commented Mar 10, 2026

Prototype for #7050

The azd init command presents users with a choice: "Scan current directory" or "Select a template."
This pattern is familiar to azd users and provides a good onboarding experience.

Currently, azd ai agent init (without the -m flag) jumps directly into an "init from code" flow
that scaffolds a new agent from scratch. There is no way to browse and start from a sample template.

This feature adds an initial prompt to azd ai agent init that mirrors the azd init experience,
letting users choose between using their existing code or starting from a curated template.

Demo

image image image

UX Flow

$ azd ai agent init

? How do you want to initialize your agent?  [Use arrows to move, type to filter]
> Use the code in the current directory
  Start new from a template

--- If "Start new from a template" is selected ---

? Select a language:  [Use arrows to move, type to filter]
> Python
  C#

--- After language is selected ---

? Select an agent template:  [Use arrows to move, type to filter]
> Echo Agent                                     (Agent Framework)
  Agent with Foundry Tools                       (Agent Framework)
  Agent with Local Tools                         (Agent Framework)
  ...
  Calculator Agent                               (LangGraph)
  ...

--- After template is selected ---

→ If source URL ends with agent.yaml or agent.manifest.yaml:
  Proceeds via the same code path as `azd ai agent init -m <url>`

→ Otherwise (full azd template repo):
  Dispatches `azd init -t <repo>` to scaffold the entire project

Key UX Decisions

  1. "Use the code in the current directory" maps to the existing InitFromCodeAction (unchanged).
  2. "Start new from a template" prompts for language first (Python / C#), then shows a filtered
    list of agent templates.
  3. Template type is detected from the source URL, not a separate field:
    • If the URL ends with agent.yaml or agent.manifest.yamlagent manifest flow:
      the URL is used as the manifest pointer, reusing the InitAction code path (same as -m <url>).
    • Otherwise → full azd template flow: the source is treated as a GitHub repo slug and
      dispatched via azd init -t <repo> workflow, which clones the full template (azure.yaml,
      infra/, source code, etc.).
  4. When -m is provided on the command line, the prompt is skipped entirely (existing behavior).

Architecture

Template Data Source

Templates are defined in a JSON file hosted on GitHub:

  • Repository: therealjohn/awesome-azd (fork of Azure/awesome-azd)
  • Branch: agent-templates
  • File: website/static/agent-templates.json
  • URL: https://aka.ms/foundry-agents

This mirrors how azd init uses https://aka.ms/awesome-azd/templates.json for its template list,
but with a custom schema tailored for agent templates.

JSON Schema

[
  {
    "title": "Echo Agent",
    "description": "A custom AI agent that echoes user input. Useful for testing and learning.",
    "language": "python",
    "framework": "Agent Framework",
    "source": "https://github.com/microsoft-foundry/foundry-samples/blob/main/samples/python/hosted-agents/agent-framework/echo-agent/agent.yaml",
    "tags": ["example", "learning"]
  }
]
Field Type Description
title string Display name shown in the selection list
description string Brief description of what the agent does
language string "python" or "csharp" — used for filtering after language prompt
framework string "Agent Framework", "LangGraph", or "Custom" — shown as detail text
source string URL to agent.yaml file or a GitHub repo slug for full azd templates
tags string[] Categorization tags (for future filtering)

Template Type Detection

The template type is not stored in the JSON — it is inferred from the source URL at runtime:

  • If source ends with /agent.yaml or /agent.manifest.yamlagent manifest template.
    The URL is passed to downloadAgentYaml() via the existing -m flow.
  • Otherwise → full azd template. The source is treated as a GitHub repo slug
    (e.g., Azure-Samples/my-agent-template) and dispatched via azd init -t <repo>.

This means the same JSON catalog can contain both types of templates without any schema changes.
Adding a full azd template is as simple as setting source to the repo slug instead of an agent.yaml URL.

Two Template Flows

Agent manifest flow (source ends with agent.yaml):

  1. ensureAzureContext() — set up project, environment, subscription, location
  2. InitAction.Run()downloadAgentYaml() — download agent.yaml + sibling files
  3. addToProject() — register agent as a service in azure.yaml

Full azd template flow (source is a repo slug):

  1. Dispatch azd init -t <repo> via azdClient.Workflow().Run()
  2. azd clones the full template repo (azure.yaml, infra/, source code, agent definitions)
  3. Project is fully initialized — no further steps needed

Key Difference from azd init Templates

azd init templates are always full GitHub repositories cloned via azd. Agent templates support
two modes: (1) agent manifest templates that point to agent.yaml files inside shared repos like
microsoft-foundry/foundry-samples, and (2) full azd templates that are standalone repos with
azure.yaml, infra/, and source code — identical to azd init templates.

Template Inventory

All templates come from microsoft-foundry/foundry-samples under samples/{language}/hosted-agents/.

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.

1 participant