Skip to content

Commit 6df0437

Browse files
MervinPraisonpraisonai-triage-agent[bot]Copilot
authored
feat: add delete/update CLI parity to managed agents (fixes #1430) (#1441)
* feat: add delete operations and envs update to managed CLI - Add sessions delete command with confirmation prompt - Add agents delete command with confirmation prompt - Add envs update command supporting --packages and --networking - Add envs delete command with confirmation prompt - All destructive commands support --yes/-y flag to skip confirmation - Add comprehensive unit tests for all new commands - Follows existing patterns in managed.py for consistency Fixes #1430 Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com> * test(cli): patch anthropic via sys.modules since _get_client imports lazily * fix(cli): validate and sanitize env package list on managed env update Agent-Logs-Url: https://github.com/MervinPraison/PraisonAI/sessions/1b7812ec-b08b-493c-a403-53a33364cc7a Co-authored-by: MervinPraison <454862+MervinPraison@users.noreply.github.com> --------- Co-authored-by: praisonai-triage-agent[bot] <272766704+praisonai-triage-agent[bot]@users.noreply.github.com> Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MervinPraison <454862+MervinPraison@users.noreply.github.com>
1 parent af1fab4 commit 6df0437

File tree

2 files changed

+473
-0
lines changed

2 files changed

+473
-0
lines changed

β€Žsrc/praisonai/praisonai/cli/commands/managed.pyβ€Ž

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,32 @@ def sessions_resume(
316316
print(result)
317317

318318

319+
@sessions_app.command("delete")
320+
def sessions_delete(
321+
session_id: str = typer.Argument(..., help="Session ID to delete (sesn_01...)"),
322+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
323+
):
324+
"""Delete a session.
325+
326+
Example:
327+
praisonai managed sessions delete sesn_01AbCdEf
328+
praisonai managed sessions delete sesn_01AbCdEf --yes
329+
"""
330+
if not yes:
331+
confirm = typer.confirm(f"Are you sure you want to delete session {session_id}?")
332+
if not confirm:
333+
typer.echo("Deletion cancelled.")
334+
raise typer.Exit(0)
335+
336+
client = _get_client()
337+
try:
338+
client.beta.sessions.delete(session_id)
339+
typer.echo(f"Session {session_id} deleted successfully.")
340+
except Exception as e:
341+
typer.echo(f"Error deleting session: {e}")
342+
raise typer.Exit(1)
343+
344+
319345
# ─────────────────────────────────────────────────────────────────────────────
320346
# agents sub-commands
321347
# ─────────────────────────────────────────────────────────────────────────────
@@ -397,6 +423,32 @@ def agents_update(
397423
typer.echo(f"Updated agent: {updated.id} (v{getattr(updated,'version','')})")
398424

399425

426+
@agents_app.command("delete")
427+
def agents_delete(
428+
agent_id: str = typer.Argument(..., help="Agent ID to delete (agent_01...)"),
429+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
430+
):
431+
"""Delete an agent.
432+
433+
Example:
434+
praisonai managed agents delete agent_01AbCdEf
435+
praisonai managed agents delete agent_01AbCdEf --yes
436+
"""
437+
if not yes:
438+
confirm = typer.confirm(f"Are you sure you want to delete agent {agent_id}?")
439+
if not confirm:
440+
typer.echo("Deletion cancelled.")
441+
raise typer.Exit(0)
442+
443+
client = _get_client()
444+
try:
445+
client.beta.agents.delete(agent_id)
446+
typer.echo(f"Agent {agent_id} deleted successfully.")
447+
except Exception as e:
448+
typer.echo(f"Error deleting agent: {e}")
449+
raise typer.Exit(1)
450+
451+
400452
# ─────────────────────────────────────────────────────────────────────────────
401453
# envs sub-commands
402454
# ─────────────────────────────────────────────────────────────────────────────
@@ -441,6 +493,72 @@ def envs_get(
441493
typer.echo(f"Config: {cfg}")
442494

443495

496+
@envs_app.command("update")
497+
def envs_update(
498+
env_id: str = typer.Argument(..., help="Environment ID (env_01...)"),
499+
packages: Optional[str] = typer.Option(None, "--packages", "-p", help="Comma-separated pip packages"),
500+
networking: Optional[str] = typer.Option(None, "--networking", help="Networking type: 'full' or 'limited'"),
501+
):
502+
"""Update an environment's configuration.
503+
504+
Example:
505+
praisonai managed envs update env_01AbCdEf --packages "numpy,pandas"
506+
praisonai managed envs update env_01AbCdEf --networking limited
507+
"""
508+
client = _get_client()
509+
kwargs = {}
510+
511+
if packages:
512+
pkg_list = [p.strip() for p in packages.split(",") if p.strip()]
513+
if not pkg_list:
514+
typer.echo("Error: --packages must include at least one package name")
515+
raise typer.Exit(1)
516+
kwargs["packages"] = {"pip": pkg_list}
517+
518+
if networking:
519+
if networking not in ["full", "limited"]:
520+
typer.echo("Error: --networking must be 'full' or 'limited'")
521+
raise typer.Exit(1)
522+
kwargs["networking"] = {"type": networking}
523+
524+
if not kwargs:
525+
typer.echo("Nothing to update. Pass --packages or --networking.")
526+
raise typer.Exit(0)
527+
528+
try:
529+
updated = client.beta.environments.update(env_id, **kwargs)
530+
typer.echo(f"Updated environment: {updated.id}")
531+
except Exception as e:
532+
typer.echo(f"Error updating environment: {e}")
533+
raise typer.Exit(1)
534+
535+
536+
@envs_app.command("delete")
537+
def envs_delete(
538+
env_id: str = typer.Argument(..., help="Environment ID to delete (env_01...)"),
539+
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
540+
):
541+
"""Delete an environment.
542+
543+
Example:
544+
praisonai managed envs delete env_01AbCdEf
545+
praisonai managed envs delete env_01AbCdEf --yes
546+
"""
547+
if not yes:
548+
confirm = typer.confirm(f"Are you sure you want to delete environment {env_id}?")
549+
if not confirm:
550+
typer.echo("Deletion cancelled.")
551+
raise typer.Exit(0)
552+
553+
client = _get_client()
554+
try:
555+
client.beta.environments.delete(env_id)
556+
typer.echo(f"Environment {env_id} deleted successfully.")
557+
except Exception as e:
558+
typer.echo(f"Error deleting environment: {e}")
559+
raise typer.Exit(1)
560+
561+
444562
# ─────────────────────────────────────────────────────────────────────────────
445563
# ids sub-commands (save / restore / show β€” no Anthropic IDs are user-defined)
446564
# ─────────────────────────────────────────────────────────────────────────────

0 commit comments

Comments
Β (0)