Skip to content

Python AgentRuntimeClient can create sessions but cannot delete them #395

Description

@nabrahma

What would you like to be added:

I propose adding explicit server-side session deletion to AgentRuntimeClient
in the Python SDK to match the lifecycle behavior CodeInterpreterClient already
has. This includes:

  1. Extending ControlPlaneClient (sdk-python/agentcube/clients/control_plane.py)
    to support DELETE /v1/agent-runtime/sessions/:sessionId — either by adding a
    dedicated delete_agent_runtime_session(session_id) method or by making the
    existing delete_session method accept the resource kind. The existing
    delete_session path used by CodeInterpreterClient will remain unchanged.

  2. Adding optional workload_manager_url and auth_token parameters to
    AgentRuntimeClient.__init__ (sdk-python/agentcube/agent_runtime.py) with
    the same env-var fallback pattern used by CodeInterpreterClient, so existing
    callers that do not need explicit delete are not broken.

  3. Adding a stop() method to AgentRuntimeClient that:

    • Closes the local data-plane connection.
    • Calls the WorkloadManager delete API for sessions the client created itself.
    • Does NOT auto-delete sessions that were attached by passing an existing
      session_id (to preserve long-running session reuse).
  4. Updating AgentRuntimeClient.__exit__ to call stop() instead of close().

  5. Updating sdk-python/examples/agent_runtime_usage.py to demonstrate the full
    create → invoke → stop lifecycle.

  6. Adding tests covering:

    • Owned session: stop() calls the delete endpoint.
    • Attached session: stop() does not auto-delete.
    • Context manager: stop() is called on exit for owned sessions.

The backend route DELETE /v1/agent-runtime/sessions/:sessionId already exists
in pkg/workloadmanager/server.go and uses the shared handleDeleteSandbox
handler. No Go backend changes are needed.

Why is this needed:

Currently AgentRuntimeClient.close() only closes the local HTTP connection —
no WorkloadManager API call is made and the server-side sandbox is never released
through the SDK. CodeInterpreterClient already has this full lifecycle via
stop() which calls DELETE /v1/code-interpreter/sessions/:sessionId.

As agent itself may be long-running (issue #303 is removing the default 8h max
TTL for AgentRuntime), SDK users will have no path to release server-side
resources. The sandbox keeps running until idle-timeout fires or someone manually
cleans up the cluster. CodeInterpreterClient and AgentRuntimeClient should
have a consistent lifecycle contract.

This is a Python SDK-only change. No Go code, no CRD regeneration, no generated
client changes are required.

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions