44# --------------------------------------------------------------------------------------------
55
66import json
7+ import urllib .parse
78
89from knack .util import CLIError
910from knack .log import get_logger
1011
12+ import azure .core .rest
1113from azure .mgmt .cognitiveservices .models import Account as CognitiveServicesAccount , Sku , \
1214 VirtualNetworkRule , IpRule , NetworkRuleSet , NetworkRuleAction , \
1315 AccountProperties as CognitiveServicesAccountProperties , ApiProperties as CognitiveServicesAccountApiProperties , \
@@ -327,52 +329,108 @@ def commitment_plan_create_or_update(
327329 return client .create_or_update (resource_group_name , account_name , commitment_plan_name , plan )
328330
329331
330- def agent_update (client , account_name , agent_name , agent_version ,
331- min_replica = None , max_replica = None , description = None , tags = None ):
332+ AGENT_API_VERSION_PARAMS = { 'api-version' : '2025-11-15-preview' }
333+
334+ def agent_update (client , account_name , project_name , agent_name , agent_version ,
335+ min_replica = None , max_replica = None , description = None , tags = None , endpoint = None ):
332336 """
333337 Update hosted agent deployment configuration.
334338 Updates horizontal scale configuration (min and max replica), agent meta-data such as description and tags.
335339 New version is not created for this update.
336340 """
337- raise NotImplementedError ("agent_update command is not yet implemented" )
338-
341+ request_body = {}
342+ if min_replica is not None :
343+ request_body ['min_replica' ] = min_replica
344+ if max_replica is not None :
345+ request_body ['max_replica' ] = max_replica
346+ request = azure .core .rest .HttpRequest ('POST' , f'/agents/{ urllib .parse .quote (agent_name )} /containers/default:update' , json = request_body , params = AGENT_API_VERSION_PARAMS )
347+ response = client .send_request (request )
348+ response .raise_for_status ()
349+ return response .json ()
339350
340- def agent_stop (client , account_name , agent_name , agent_version ):
351+ def agent_stop (client , account_name , project_name , agent_name , agent_version , endpoint = None ):
341352 """
342353 Stop hosted agent deployment.
343354 """
344- raise NotImplementedError ("agent_stop command is not yet implemented" )
355+ request = azure .core .rest .HttpRequest ('POST' , f'/agents/{ urllib .parse .quote (agent_name )/ containers / default :start} ' , params = AGENT_API_VERSION_PARAMS )
356+ response = client .send_request (request )
357+ response .raise_for_status ()
358+ return response .json ()
345359
346360
347- def agent_start (client , account_name , agent_name , agent_version ):
361+ def agent_start (client , account_name , project_name , agent_name , agent_version , endpoint = None ):
348362 """
349363 Start hosted agent deployment.
350364 """
351- raise NotImplementedError ("agent_start command is not yet implemented" )
365+ request = azure .core .rest .HttpRequest ('POST' , f'/agents/{ urllib .parse .quote (agent_name )/ containers / default :start} ' , params = AGENT_API_VERSION_PARAMS )
366+ response = client .send_request (request )
367+ response .raise_for_status ()
368+ return response .json ()
352369
353370
354- def agent_delete_deployment (client , account_name , agent_name , agent_version ):
371+ def agent_delete_deployment (client , account_name , project_name , agent_name , agent_version , endpoint = None ):
355372 """
356373 Delete hosted agent deployment.
357374 Deletes the agent deployment only, agent version associated with the deployment remains.
358375 """
359376 raise NotImplementedError ("agent_delete_deployment command is not yet implemented" )
360377
361378
362- def agent_delete (client , account_name , agent_name , agent_version = None ):
379+ def agent_delete (client , account_name , project_name , agent_name , agent_version = None , endpoint = None ):
363380 """
364381 Delete hosted agent version or all versions.
365- If agent_version is provided, deletes the agent instance and agent definition associated with that version.
382+ If agent_version is provided, deletes the agent instance and agent definition associated with ` that version.
366383 If agent_version is not provided, deletes all agent instances and agent definitions associated with the agent name.
367384 """
368- raise NotImplementedError ("agent_delete command is not yet implemented" )
385+ request = azure .core .rest .HttpRequest ('DELETE' , f'/agents/{ urllib .parse .quote (agent_name )} ' , params = AGENT_API_VERSION_PARAMS )
386+ response = client .send_request (request )
387+ response .raise_for_status ()
388+ return response .json ()
369389
370390
371- def agent_list (client , account_name , agent_name , agent_version = None ):
391+ def agent_list (client , account_name , project_name , endpoint = None ):
372392 """
373393 List hosted agent versions or deployments.
374394 If agent_version is not provided, lists all versions for an agent.
375395 If agent_version is provided, lists all deployments for that agent version.
376396 """
377- raise NotImplementedError ("agent_list command is not yet implemented" )
378-
397+ agents = []
398+ params = AGENT_API_VERSION_PARAMS .copy ()
399+ while True :
400+ request = azure .core .rest .HttpRequest ('GET' , f'/agents' , params = params )
401+ response = client .send_request (request )
402+ response .raise_for_status ()
403+ body = response .json ()
404+ agents .extend (body .get ('data' , []))
405+ if body .get ('has_more' ):
406+ params ['after' ] = body .get ('last_id' )
407+ else :
408+ return agents
409+
410+
411+ def agent_versions_list (client , account_name , project_name , agent_name , endpoint = None ):
412+ """
413+ List all versions of a hosted agent.
414+ """
415+ versions = []
416+ params = AGENT_API_VERSION_PARAMS .copy ()
417+ while True :
418+ request = azure .core .rest .HttpRequest ('GET' , f'/agents/{ urllib .parse .quote (agent_name )} /versions' , params = params )
419+ response = client .send_request (request )
420+ response .raise_for_status ()
421+ body = response .json ()
422+ versions .extend (body .get ('data' , []))
423+ if body .get ('has_more' ):
424+ params ['after' ] = body .get ('last_id' )
425+ else :
426+ return versions
427+
428+
429+ def agent_show (client , account_name , project_name , agent_name , endpoint = None ):
430+ """
431+ Show details of a hosted agent.
432+ """
433+ request = azure .core .rest .HttpRequest ('GET' , f'/agents/{ urllib .parse .quote (agent_name )} ' , params = AGENT_API_VERSION_PARAMS )
434+ response = client .send_request (request )
435+ response .raise_for_status ()
436+ return response .json ()
0 commit comments