@@ -83,25 +83,64 @@ def _create_agent(project_client: AIProjectClient, *, model: str, name: str, ins
8383 except TypeError :
8484 pass
8585
86+ # Preferred: pass name + definition explicitly (newer SDK signature)
87+ try :
88+ from azure .ai .projects .models import PromptAgentDefinition , AgentKind
89+
90+ agent_def = PromptAgentDefinition (
91+ kind = AgentKind .PROMPT ,
92+ model = model ,
93+ instructions = instructions ,
94+ )
95+ return agents .create (name = name , definition = agent_def , description = name )
96+ except Exception :
97+ pass
98+
8699 # Fall back to SDK model definitions
87100 try :
88- from azure .ai .projects .models import PromptAgentDefinition
101+ from azure .ai .projects .models import PromptAgentDefinition , AgentKind
89102
90- agent_def = PromptAgentDefinition (model = model , name = name , instructions = instructions )
103+ agent_def = PromptAgentDefinition (
104+ kind = AgentKind .PROMPT ,
105+ model = model ,
106+ instructions = instructions ,
107+ )
91108 return agents .create (agent_def )
92109 except Exception :
93110 pass
94111
95112 try :
96- from azure .ai .projects .models import AgentDefinition
113+ from azure .ai .projects .models import AgentDefinition , AgentKind
97114
98- agent_def = AgentDefinition (model = model , name = name , instructions = instructions )
115+ agent_def = AgentDefinition (kind = str ( AgentKind . PROMPT ) )
99116 return agents .create (agent_def )
100117 except Exception :
101118 pass
102119
103- # Last resort: pass a dict payload
104- return agents .create ({"model" : model , "name" : name , "instructions" : instructions })
120+ # Try AgentCreateRequest with explicit definition
121+ try :
122+ from azure .ai .projects .models import AgentCreateRequest , PromptAgentDefinition , AgentKind
123+
124+ agent_def = PromptAgentDefinition (
125+ kind = AgentKind .PROMPT ,
126+ model = model ,
127+ instructions = instructions ,
128+ )
129+ request = AgentCreateRequest (definition = agent_def , name = name , description = name )
130+ return agents .create (request )
131+ except Exception :
132+ pass
133+
134+ # Some SDKs require a "definition" wrapper in the payload
135+ payload = {
136+ "name" : name ,
137+ "kind" : "prompt" ,
138+ "definition" : {
139+ "model" : model ,
140+ "instructions" : instructions ,
141+ },
142+ }
143+ return agents .create (payload )
105144
106145 if hasattr (agents , "create_prompt_agent" ):
107146 return agents .create_prompt_agent (model = model , name = name , instructions = instructions )
@@ -166,7 +205,7 @@ def deploy_agents():
166205 "Your role is to help customers find products, answer questions about inventory, provide recommendations, and assist with general shopping needs. "
167206 "Be friendly, professional, and informative. Keep answers concise and helpful."
168207 ),
169- "model" : agent_model_map .get ("cora" , model_deployment )
208+ "model" : agent_model_map .get ("cora" , "model-router" )
170209 },
171210 {
172211 "name" : "Interior Design Specialist" ,
@@ -418,8 +457,8 @@ def deploy_agents():
418457 print (f"WARNING: Failed to write state file: { se } " )
419458
420459 # Update src/.env with real agent IDs (early propagation)
421- # NOTE: Terraform generates ../src/.env (workspace-relative), not ../src/app/.env .
422- env_path = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , '..' , '..' , '.env' ))
460+ # NOTE: Terraform generates ../src/.env (workspace-relative).
461+ env_path = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , '..' , '..' , 'src' , ' .env' ))
423462 if os .path .exists (env_path ):
424463 try :
425464 import re
0 commit comments