@@ -14,6 +14,7 @@ import (
1414 "strings"
1515
1616 "azureaiagent/internal/exterrors"
17+ projectpkg "azureaiagent/internal/project"
1718
1819 "github.com/azure/azure-dev/cli/azd/pkg/azdext"
1920)
@@ -34,14 +35,22 @@ type AgentLocalContext struct {
3435}
3536
3637// resolveConfigPath returns the full path to the .foundry-agent.json file
37- // in the azd project root directory .
38- func resolveConfigPath (ctx context.Context , azdClient * azdext.AzdClient ) string {
38+ // in the current azd environment directory (< project root>/.azure/<env name>/) .
39+ func resolveConfigPath (ctx context.Context , azdClient * azdext.AzdClient ) ( string , error ) {
3940 projectResponse , err := azdClient .Project ().Get (ctx , & azdext.EmptyRequest {})
4041 if err != nil || projectResponse .Project == nil {
41- return ConfigFile
42+ return "" , fmt . Errorf ( "failed to get project config: %w" , err )
4243 }
4344
44- return filepath .Join (projectResponse .Project .Path , ConfigFile )
45+ envResponse , err := azdClient .Environment ().GetCurrent (ctx , & azdext.EmptyRequest {})
46+ if err != nil {
47+ return "" , fmt .Errorf ("failed to get current environment: %w" , err )
48+ }
49+ if envResponse .Environment == nil || envResponse .Environment .Name == "" {
50+ return "" , fmt .Errorf ("no current environment set; run 'azd env select' or 'azd init' first" )
51+ }
52+
53+ return filepath .Join (projectResponse .Project .Path , ".azure" , envResponse .Environment .Name , ConfigFile ), nil
4554}
4655
4756// loadLocalContext reads the .foundry-agent.json state file.
@@ -74,7 +83,10 @@ func resolveSessionID(ctx context.Context, azdClient *azdext.AzdClient, agentNam
7483 if explicit != "" {
7584 return explicit , nil
7685 }
77- configPath := resolveConfigPath (ctx , azdClient )
86+ configPath , err := resolveConfigPath (ctx , azdClient )
87+ if err != nil {
88+ return "" , err
89+ }
7890 agentCtx := loadLocalContext (configPath )
7991 if agentCtx .Sessions == nil {
8092 agentCtx .Sessions = make (map [string ]string )
@@ -93,25 +105,31 @@ func resolveSessionID(ctx context.Context, azdClient *azdext.AzdClient, agentNam
93105}
94106
95107// resolveConversationID resolves or creates a Foundry conversation ID.
96- // Returns empty string if creation fails (multi-turn memory disabled).
97- func resolveConversationID (ctx context.Context , azdClient * azdext.AzdClient , agentName string , forceNew bool ) string {
98- configPath := resolveConfigPath (ctx , azdClient )
108+ // Returns empty string if no existing conversation is found or on error.
109+ func resolveConversationID (ctx context.Context , azdClient * azdext.AzdClient , agentName string , forceNew bool ) (string , error ) {
110+ configPath , err := resolveConfigPath (ctx , azdClient )
111+ if err != nil {
112+ return "" , err
113+ }
99114 agentCtx := loadLocalContext (configPath )
100115 if agentCtx .Conversations == nil {
101116 agentCtx .Conversations = make (map [string ]string )
102117 }
103118 if ! forceNew {
104119 if convID , ok := agentCtx .Conversations [agentName ]; ok {
105- return convID
120+ return convID , nil
106121 }
107122 }
108123 // Conversation creation requires an API call — handled by the invoke command.
109- return ""
124+ return "" , nil
110125}
111126
112127// saveConversationID persists a conversation ID for an agent.
113128func saveConversationID (ctx context.Context , azdClient * azdext.AzdClient , agentName , convID string ) error {
114- configPath := resolveConfigPath (ctx , azdClient )
129+ configPath , err := resolveConfigPath (ctx , azdClient )
130+ if err != nil {
131+ return err
132+ }
115133 agentCtx := loadLocalContext (configPath )
116134 if agentCtx .Conversations == nil {
117135 agentCtx .Conversations = make (map [string ]string )
@@ -348,11 +366,10 @@ func resolveServiceRunContext(ctx context.Context, azdClient *azdext.AzdClient,
348366 projectDir := filepath .Join (project .Path , svc .RelativePath )
349367
350368 var startupCmd string
351- if svc .AdditionalProperties != nil {
352- if fields := svc .AdditionalProperties .GetFields (); fields != nil {
353- if v , ok := fields ["startupCommand" ]; ok && v != nil {
354- startupCmd = v .GetStringValue ()
355- }
369+ if svc .Config != nil {
370+ var agentConfig projectpkg.ServiceTargetAgentConfig
371+ if err := projectpkg .UnmarshalStruct (svc .Config , & agentConfig ); err == nil {
372+ startupCmd = agentConfig .StartupCommand
356373 }
357374 }
358375
0 commit comments