-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: managed agents follow-ups - safety, observability, tests, CLI parity #1435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
73b2ea8
8653157
482494c
bafbf1e
0294e37
7e5eb36
0195581
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -532,6 +532,97 @@ def ids_restore( | |
| print(result) | ||
|
|
||
|
|
||
| # ───────────────────────────────────────────────────────────────────────────── | ||
| # Delete commands for missing CLI operations (Fix A7) | ||
| # ───────────────────────────────────────────────────────────────────────────── | ||
|
|
||
| @sessions_app.command("delete") | ||
| def sessions_delete( | ||
| session_id: str = typer.Argument(..., help="Session ID to delete"), | ||
| force: bool = typer.Option(False, "--force", help="Force delete without confirmation"), | ||
| ): | ||
| """Delete a managed session.""" | ||
| if not force: | ||
| confirm = typer.confirm(f"Delete session {session_id}?") | ||
| if not confirm: | ||
| typer.echo("Cancelled.") | ||
| return | ||
|
|
||
| client = _get_client() | ||
| try: | ||
| # For Anthropic managed agents, delete via API | ||
| response = client.delete(f"/v1/agent_sessions/{session_id}") | ||
| typer.secho(f"Session {session_id} deleted", fg="green") | ||
| except Exception as e: | ||
| typer.secho(f"Failed to delete session: {e}", fg="red") | ||
|
|
||
|
|
||
| @agents_app.command("delete") | ||
| def agents_delete( | ||
| agent_id: str = typer.Argument(..., help="Agent ID to delete"), | ||
| force: bool = typer.Option(False, "--force", help="Force delete without confirmation"), | ||
| ): | ||
| """Delete a managed agent.""" | ||
| if not force: | ||
| confirm = typer.confirm(f"Delete agent {agent_id}? This will also delete all its sessions.") | ||
| if not confirm: | ||
| typer.echo("Cancelled.") | ||
| return | ||
|
|
||
| client = _get_client() | ||
| try: | ||
| response = client.delete(f"/v1/agents/{agent_id}") | ||
| typer.secho(f"Agent {agent_id} deleted", fg="green") | ||
| except Exception as e: | ||
| typer.secho(f"Failed to delete agent: {e}", fg="red") | ||
|
|
||
|
|
||
| @envs_app.command("update") | ||
| def envs_update( | ||
| env_id: str = typer.Argument(..., help="Environment ID to update"), | ||
| name: Optional[str] = typer.Option(None, "--name", help="New environment name"), | ||
| description: Optional[str] = typer.Option(None, "--description", help="New environment description"), | ||
| ): | ||
| """Update a managed environment.""" | ||
| if not name and not description: | ||
| typer.echo("Must specify at least --name or --description") | ||
| return | ||
|
|
||
| client = _get_client() | ||
| try: | ||
| data = {} | ||
| if name: | ||
| data["name"] = name | ||
| if description: | ||
| data["description"] = description | ||
|
|
||
| response = client.patch(f"/v1/environments/{env_id}", json=data) | ||
| typer.secho(f"Environment {env_id} updated", fg="green") | ||
| typer.echo(json.dumps(response.json(), indent=2)) | ||
| except Exception as e: | ||
| typer.secho(f"Failed to update environment: {e}", fg="red") | ||
|
|
||
|
|
||
| @envs_app.command("delete") | ||
| def envs_delete( | ||
| env_id: str = typer.Argument(..., help="Environment ID to delete"), | ||
| force: bool = typer.Option(False, "--force", help="Force delete without confirmation"), | ||
| ): | ||
| """Delete a managed environment.""" | ||
| if not force: | ||
| confirm = typer.confirm(f"Delete environment {env_id}? This may affect running agents.") | ||
| if not confirm: | ||
| typer.echo("Cancelled.") | ||
| return | ||
|
|
||
| client = _get_client() | ||
| try: | ||
| response = client.delete(f"/v1/environments/{env_id}") | ||
| typer.secho(f"Environment {env_id} deleted", fg="green") | ||
| except Exception as e: | ||
| typer.secho(f"Failed to delete environment: {e}", fg="red") | ||
|
Comment on lines
+556
to
+629
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failures are swallowed — CLI returns exit 0 even when the server rejects the request. Each 🧰 Tools🪛 Ruff (0.15.10)[warning] 556-556: Do not catch blind exception: (BLE001) [warning] 576-576: Do not catch blind exception: (BLE001) [warning] 602-602: Do not catch blind exception: (BLE001) [warning] 622-622: Do not catch blind exception: (BLE001) 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| # ───────────────────────────────────────────────────────────────────────────── | ||
| # Register sub-apps onto main app | ||
| # ───────────────────────────────────────────────────────────────────────────── | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MervinPraison/PraisonAI
Length of output: 49
🌐 Web query:
Which methods does the Anthropic Python SDK expose on client.beta.sessions, client.beta.agents, and client.beta.environments for delete and update operations?💡 Result:
client.beta.sessions exposes: - delete(session_id): Deletes a session. Returns BetaManagedAgentsDeletedSession. - update(session_id, kwargs): Updates session metadata/title. Returns BetaManagedAgentsSession. client.beta.agents exposes: - update(agent_id, kwargs): Updates agent configuration. Returns BetaManagedAgentsAgent. - No delete method (uses archive instead). client.beta.environments exposes: - delete(environment_id): Deletes an environment. Returns BetaEnvironmentDeleteResponse. - update(environment_id, kwargs): Updates environment configuration. Returns BetaEnvironment.
Citations:
🌐 Web query:
What is the correct method to delete or archive a managed agent in the Anthropic Python SDK? Does client.beta.agents have a delete() method or does it use archive()?💡 Result:
The correct method to manage (delete or archive) a managed agent in the Anthropic Python SDK is to use client.beta.agents.archive(agent_id). There is no delete method for agents; agents can only be archived, not hard-deleted. Archiving makes the agent read-only: new sessions cannot reference it, but existing sessions continue running. Example: client.beta.agents.archive(agent_id="agent_123") This is confirmed across official Anthropic documentation and SDK references. Other resources like sessions, environments, and vaults support both delete and archive, but agents specifically do not have delete.
Citations:
Replace raw HTTP calls with SDK resource methods — agents use archive, not delete.
All other commands here route through the Anthropic SDK's resource-oriented namespace (e.g.
client.beta.sessions.retrieve,client.beta.agents.update,client.beta.environments.retrieve). The new delete/update commands instead callclient.delete("/v1/...")andclient.patch("/v1/...")directly, which:client.beta.sessions.delete,client.beta.agents.archive,client.beta.environments.delete,client.beta.environments.update) that are the documented surface for these operations and consistent with the rest of this file.client.patch(...)in the Anthropic SDK returns a parsed/typed pydantic object, not anhttpx.Response, soresponse.json()at line 601 returns a JSON string (pydantic's serializer), which then gets double-encoded byjson.dumps(...)on the same line./v1/...URL paths that may not match the beta API routes the rest of the CLI targets.Critical: agents do not support delete — use
client.beta.agents.archive(agent_id)instead. Replace with:sessions_delete:client.beta.sessions.delete(session_id)(withraise typer.Exit(1)on exception)agents_delete:client.beta.agents.archive(agent_id)(withraise typer.Exit(1)on exception)envs_update:client.beta.environments.update(env_id, name=..., description=...)and output the typed response fields directly (not.json())envs_delete:client.beta.environments.delete(env_id)(withraise typer.Exit(1)on exception)🧰 Tools
🪛 Ruff (0.15.10)
[warning] 556-556: Do not catch blind exception:
Exception(BLE001)
[warning] 576-576: Do not catch blind exception:
Exception(BLE001)
[warning] 602-602: Do not catch blind exception:
Exception(BLE001)
🤖 Prompt for AI Agents