Skip to content

Commit 0154d64

Browse files
authored
[AI Agents Extension] Tool parsing (#6091)
* Add tool resource parsing for hosted Signed-off-by: trangevi <[email protected]> * move the handling Signed-off-by: trangevi <[email protected]> * Add support for prompt tools handling Signed-off-by: trangevi <[email protected]> * cspell Signed-off-by: trangevi <[email protected]> * capitalization Signed-off-by: trangevi <[email protected]> * cspell again Signed-off-by: trangevi <[email protected]> * Add check for connection id from registry Signed-off-by: trangevi <[email protected]> --------- Signed-off-by: trangevi <[email protected]>
1 parent a6dfa6d commit 0154d64

File tree

11 files changed

+1471
-116
lines changed

11 files changed

+1471
-116
lines changed

cli/azd/.vscode/cspell.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ overrides:
188188
- mcpservertoolspecifyapprovalmode
189189
- protocolversionrecord
190190
- openapitool
191+
- filename: extensions/azure.ai.agents/internal/pkg/agents/agent_api/models.go
192+
words:
193+
- Dataagent
194+
- dataagent
195+
- webp
196+
- filename: extensions/azure.ai.agents/internal/pkg/agents/registry_api/operations.go
197+
words:
198+
- Dataagent
191199
- filename: docs/new-azd-command.md
192200
words:
193201
- pflag

cli/azd/extensions/azure.ai.agents/internal/cmd/init.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,14 @@ func (a *InitAction) downloadAgentYaml(
721721
return nil, "", fmt.Errorf("failed to process manifest parameters: %w", err)
722722
}
723723

724+
_, isPromptAgent := agentManifest.Template.(agent_yaml.PromptAgent)
725+
if isPromptAgent {
726+
agentManifest, err = agent_yaml.ProcessPromptAgentToolsConnections(ctx, agentManifest, a.azdClient)
727+
if err != nil {
728+
return nil, "", fmt.Errorf("failed to process prompt agent tools connections: %w", err)
729+
}
730+
}
731+
724732
content, err = yaml.Marshal(agentManifest)
725733
if err != nil {
726734
return nil, "", fmt.Errorf("marshaling agent manifest to YAML after parameter processing: %w", err)
@@ -800,6 +808,7 @@ func (a *InitAction) addToProject(ctx context.Context, targetDir string, agentMa
800808
var agentConfig = project.ServiceTargetAgentConfig{}
801809

802810
deploymentDetails := []project.Deployment{}
811+
resourceDetails := []project.Resource{}
803812
switch agentDef.Kind {
804813
case agent_yaml.AgentKindPrompt:
805814
agentDef := agentManifest.Template.(agent_yaml.PromptAgent)
@@ -836,9 +845,39 @@ func (a *InitAction) addToProject(ctx context.Context, targetDir string, agentMa
836845
deploymentDetails = append(deploymentDetails, *modelDeployment)
837846
}
838847
}
848+
849+
// Handle tool resources that require connection names
850+
if agentManifest.Resources != nil {
851+
for _, resource := range agentManifest.Resources {
852+
// Try to cast to ToolResource
853+
if toolResource, ok := resource.(agent_yaml.ToolResource); ok {
854+
// Check if this is a resource that requires a connection name
855+
if toolResource.Id == "bing_grounding" || toolResource.Id == "azure_ai_search" {
856+
// Prompt the user for a connection name
857+
resp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
858+
Options: &azdext.PromptOptions{
859+
Message: fmt.Sprintf("Enter connection name for %s resource:", toolResource.Id),
860+
IgnoreHintKeys: true,
861+
},
862+
})
863+
if err != nil {
864+
return fmt.Errorf("prompting for connection name for %s: %w", toolResource.Id, err)
865+
}
866+
867+
// Add to resource details
868+
resourceDetails = append(resourceDetails, project.Resource{
869+
Resource: toolResource.Id,
870+
ConnectionName: resp.Value,
871+
})
872+
}
873+
}
874+
// Skip the resource if the cast fails
875+
}
876+
}
839877
}
840878

841879
agentConfig.Deployments = deploymentDetails
880+
agentConfig.Resources = resourceDetails
842881

843882
var agentConfigStruct *structpb.Struct
844883
if agentConfigStruct, err = project.MarshalStruct(&agentConfig); err != nil {

cli/azd/extensions/azure.ai.agents/internal/cmd/listen.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ func preprovisionEnvUpdate(ctx context.Context, azdClient *azdext.AzdClient, azd
9696
return err
9797
}
9898

99+
if err := resourcesEnvUpdate(ctx, foundryAgentConfig.Resources, azdClient, currentEnvResponse.Environment.Name); err != nil {
100+
return err
101+
}
102+
99103
return nil
100104
}
101105

@@ -163,6 +167,20 @@ func deploymentEnvUpdate(ctx context.Context, deployments []project.Deployment,
163167
return setEnvVar(ctx, azdClient, envName, "AI_PROJECT_DEPLOYMENTS", escapedJsonString)
164168
}
165169

170+
func resourcesEnvUpdate(ctx context.Context, resources []project.Resource, azdClient *azdext.AzdClient, envName string) error {
171+
resourcesJson, err := json.Marshal(resources)
172+
if err != nil {
173+
return fmt.Errorf("failed to marshal resource details to JSON: %w", err)
174+
}
175+
176+
// Escape backslashes and double quotes for environment variable
177+
jsonString := string(resourcesJson)
178+
escapedJsonString := strings.ReplaceAll(jsonString, "\\", "\\\\")
179+
escapedJsonString = strings.ReplaceAll(escapedJsonString, "\"", "\\\"")
180+
181+
return setEnvVar(ctx, azdClient, envName, "AI_PROJECT_DEPENDENT_RESOURCES", escapedJsonString)
182+
}
183+
166184
func containerAgentHandling(ctx context.Context, azdClient *azdext.AzdClient, project *azdext.ProjectConfig, svc *azdext.ServiceConfig) error {
167185
servicePath := svc.RelativePath
168186
fullPath := filepath.Join(project.Path, servicePath)

0 commit comments

Comments
 (0)