Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/azd/.vscode/cspell-azd-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AADSTS
ABRT
ACCESSTOKEN
Agentic
agentmanifests
aiomysql
aiopg
akvs
Expand Down Expand Up @@ -156,6 +157,7 @@ lechnerc77
libc
llms
localtools
maml
mcptools
memfs
mergo
Expand Down
16 changes: 16 additions & 0 deletions cli/azd/extensions/azure.foundry.ai.agents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWp
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/adam-lavrik/go-imath v0.0.0-20210910152346-265a42a96f0b h1:g9SuFmxM/WucQFKTMSP+irxyf5m0RiUJreBDhGI6jSA=
github.com/adam-lavrik/go-imath v0.0.0-20210910152346-265a42a96f0b/go.mod h1:XjvqMUpGd3Xn9Jtzk/4GEBCSoBX0eB2RyriXgne0IdM=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/chroma/v2 v2.20.0 h1:sfIHpxPyR07/Oylvmcai3X/exDlE8+FA820NTz+9sGw=
github.com/alecthomas/chroma/v2 v2.20.0/go.mod h1:e7tViK0xh/Nf4BYHl00ycY6rV7b8iXBksI9E359yNmA=
github.com/alecthomas/repr v0.5.1 h1:E3G4t2QbHTSNpPKBgMTln5KLkZHLOcU7r37J4pXBuIg=
github.com/alecthomas/repr v0.5.1/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/azure/azure-dev v0.0.0-20251020231858-e118c23d7f65 h1:pRASrI8Jbwa3ebf/fl/L7g+e0r+JbNme4Ol8SoXu2SA=
github.com/azure/azure-dev v0.0.0-20251020231858-e118c23d7f65/go.mod h1:fxSuNif5f3su+U252I7Ba7emSfo1rKyvr36YkexqDHo=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
Expand Down
142 changes: 136 additions & 6 deletions cli/azd/extensions/azure.foundry.ai.agents/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ import (
"strings"

"azureaiagent/internal/pkg/agents/agent_yaml"
"azureaiagent/internal/pkg/agents/registry_api"

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/azure/azure-dev/cli/azd/pkg/azdext"
"github.com/azure/azure-dev/cli/azd/pkg/exec"
"github.com/azure/azure-dev/cli/azd/pkg/input"
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
"github.com/azure/azure-dev/cli/azd/pkg/tools/github"
"github.com/fatih/color"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)

type initFlags struct {
Expand All @@ -45,7 +48,7 @@ type InitAction struct {
//modelCatalog map[string]*ai.AiModel
//modelCatalogService *ai.ModelCatalogService
projectConfig *azdext.ProjectConfig
environment *azdext.Environment
environment *azdext.Environment
}

// GitHubUrlInfo holds parsed information from a GitHub URL
Expand Down Expand Up @@ -147,7 +150,7 @@ func (a *InitAction) Run(ctx context.Context, flags *initFlags) error {

// If --project-id is given
if flags.projectResourceId != "" {
// projectResourceId is a string of the format
// projectResourceId is a string of the format
// /subscriptions/[AZURE_SUBSCRIPTION]/resourceGroups/[AZURE_RESOURCE_GROUP]/providers/Microsoft.CognitiveServices/accounts/[AI_ACCOUNT_NAME]/projects/[AI_PROJECT_NAME]
// extract each of those fields from the string, issue an error if it doesn't match the format
fmt.Println("Setting up your azd environment to use the provided AI Foundry project resource ID...")
Expand Down Expand Up @@ -193,12 +196,12 @@ func (a *InitAction) Run(ctx context.Context, flags *initFlags) error {
color.Green("\nAI agent added to your project successfully!")
}

// Validate command flags
// // Validate command flags
// if err := a.validateFlags(flags); err != nil {
// return err
// }

// Prompt for any missing input values
// // Prompt for any missing input values
// if err := a.promptForMissingValues(ctx, a.azdClient, flags); err != nil {
// return fmt.Errorf("collecting required information: %w", err)
// }
Expand Down Expand Up @@ -411,7 +414,7 @@ func (a *InitAction) promptForMissingValues(ctx context.Context, azdClient *azde
func (a *InitAction) parseAndSetProjectResourceId(ctx context.Context, projectResourceId string) error {
// Define the regex pattern for the project resource ID
pattern := `^/subscriptions/([^/]+)/resourceGroups/([^/]+)/providers/Microsoft\.CognitiveServices/accounts/([^/]+)/projects/([^/]+)$`

regex, err := regexp.Compile(pattern)
if err != nil {
return fmt.Errorf("failed to compile regex pattern: %w", err)
Expand Down Expand Up @@ -492,6 +495,67 @@ func (a *InitAction) isGitHubUrl(manifestPointer string) bool {
strings.Contains(hostname, "github")
}

type RegistryManifest struct {
registryName string
manifestName string
manifestVersion string // Defaults to "" if not specified in URL
}

func (a *InitAction) isRegistryUrl(manifestPointer string) (bool, *RegistryManifest) {
// Check if it matches the format "azureml://registries/{registryName}/agentmanifests/{manifestName}[/versions/{manifestVersion}]"
if !strings.HasPrefix(manifestPointer, "azureml://") {
return false, nil
}

// Remove the "azureml://" prefix
path := strings.TrimPrefix(manifestPointer, "azureml://")

// Split by "/" to get all path components
parts := strings.Split(path, "/")

// Should have either 4 parts (without version) or 6 parts (with version)
// Format 1: "registries", registryName, "agentmanifests", manifestName
// Format 2: "registries", registryName, "agentmanifests", manifestName, "versions", manifestVersion
if len(parts) != 4 && len(parts) != 6 {
return false, nil
}

// Validate the expected path structure for the first 4 parts
if parts[0] != "registries" || parts[2] != "agentmanifests" {
return false, nil
}

// All basic parts should be non-empty
registryName := strings.TrimSpace(parts[1])
manifestName := strings.TrimSpace(parts[3])

if registryName == "" || manifestName == "" {
return false, nil
}

var manifestVersion string

// If we have 6 parts, validate the version structure
if len(parts) == 6 {
if parts[4] != "versions" {
return false, nil
}
manifestVersion = strings.TrimSpace(parts[5])
if manifestVersion == "" {
return false, nil
}
} else {
// If no version specified, default to ""
manifestVersion = ""
}

return true, &RegistryManifest{
registryName: registryName,
manifestName: manifestName,
manifestVersion: manifestVersion,
}
}

func (a *InitAction) downloadAgentYaml(
ctx context.Context, manifestPointer string, targetDir string) (*agent_yaml.AgentManifest, string, error) {
if manifestPointer == "" {
Expand Down Expand Up @@ -560,6 +624,63 @@ func (a *InitAction) downloadAgentYaml(
}

content = []byte(contentStr)
} else if isRegistry, registryManifest := a.isRegistryUrl(manifestPointer); isRegistry {
// Handle registry URLs

// Create Azure credential
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
return nil, "", fmt.Errorf("failed to create Azure credential: %w", err)
}

manifestClient := registry_api.NewRegistryAgentManifestClient(registryManifest.registryName, cred)

var versionResult *registry_api.Manifest
if registryManifest.manifestVersion == "" {
// No version specified, get latest version from GetAllLatest
fmt.Printf("No version provided for manifest '%s', retrieving latest version\n", registryManifest.manifestName)

allManifests, err := manifestClient.GetAllLatest(ctx)
if err != nil {
return nil, "", fmt.Errorf("getting latest manifests: %w", err)
}

// Find the manifest with matching name
for _, manifest := range allManifests {
if manifest.Name == registryManifest.manifestName {
versionResult = &manifest
break
}
}

if versionResult == nil {
return nil, "", fmt.Errorf("manifest '%s' not found in registry '%s'", registryManifest.manifestName, registryManifest.registryName)
}
} else {
// Specific version requested
fmt.Printf("Downloading agent.yaml from registry: %s\n", manifestPointer)

manifest, err := manifestClient.GetManifest(ctx, registryManifest.manifestName, registryManifest.manifestVersion)
if err != nil {
return nil, "", fmt.Errorf("getting materialized manifest: %w", err)
}
versionResult = manifest
}

// Process the manifest into a maml format
processedManifest, err := registry_api.ProcessRegistryManifest(ctx, versionResult, a.azdClient)
if err != nil {
return nil, "", fmt.Errorf("processing manifest with parameters: %w", err)
}

fmt.Println("Retrieved and processed manifest from registry")

// Convert to YAML bytes for the content variable
manifestBytes, err := yaml.Marshal(processedManifest)
if err != nil {
return nil, "", fmt.Errorf("marshaling agent manifest to YAML: %w", err)
}
content = manifestBytes
}

// Parse and validate the YAML content against AgentManifest structure
Expand All @@ -570,6 +691,16 @@ func (a *InitAction) downloadAgentYaml(

fmt.Println("✓ YAML content successfully validated against AgentManifest format")

agentManifest, err = registry_api.ProcessManifestParameters(ctx, agentManifest, a.azdClient)
if err != nil {
return nil, "", fmt.Errorf("failed to process manifest parameters: %w", err)
}

content, err = yaml.Marshal(agentManifest)
if err != nil {
return nil, "", fmt.Errorf("marshaling agent manifest to YAML after parameter processing: %w", err)
}

agentId := agentManifest.Agent.Name

// Use targetDir if provided or set to local file pointer, otherwise default to "src/{agentId}"
Expand Down Expand Up @@ -1141,4 +1272,3 @@ func (a *InitAction) setEnvVar(ctx context.Context, envName, key, value string)
fmt.Printf("Set environment variable: %s=%s\n", key, value)
return nil
}

Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type ContainerAgent struct {
type AgentManifest struct {
Agent AgentDefinition `json:"agent"` // The agent that this manifest is based on
// Models []Model `json:"models"` // Additional models that are known to work with this prompt
Parameters []interface{} `json:"parameters"` // Parameters for configuring the agent's behavior and execution
Parameters []Parameter `json:"parameters"` // Parameters for configuring the agent's behavior and execution
}

// Binding represents Represents a binding between an input property and a tool parameter.
Expand Down
Loading
Loading