Skip to content

[Python SDK] Agent.stop() is not implemented #355

@santoshkumarradha

Description

@santoshkumarradha

Summary

agentfield.Agent has no stop() method. The TypeScript SDK's Agent class exposes a symmetric serve()/shutdown() (or start()/stop()) lifecycle, and the documentation in several places implies the Python SDK has the same. Today it does not, which means external callers cannot programmatically stop a long-running agent without going through signal handling — a leaky abstraction.

Where

  • File: sdk/python/agentfield/agent.py
  • Class: Agent
  • Discovered by: sdk/python/tests/test_agent_graceful_shutdown.py::test_agent_stop_is_idempotent (skipped with pytest.skip("source bug: Agent.stop() is not implemented"))

Reproduction

agent = Agent(
    node_id="shutdown-agent",
    agentfield_server="http://agentfield",
    auto_register=False,
    enable_did=False,
)
hasattr(agent, "stop")  # False

Expected behavior

Agent.stop() should:

  1. Mark the agent as shutting down (set _shutdown_requested = True, transition _current_status to OFFLINE)
  2. Stop the heartbeat loop
  3. Notify the control plane via client.notify_graceful_shutdown (best effort — failure should not block stop)
  4. Tear down async resources (the same path as _cleanup_async_resources)
  5. Be idempotent — calling stop() twice should be a no-op the second time, not raise

This pairs cleanly with whatever start/serve method the agent already exposes.

Acceptance criteria

  • Agent.stop() exists and is async
  • Calling it transitions status, stops heartbeat, notifies control plane (best effort), and tears down async resources
  • Calling it twice does not raise
  • The skipped test in test_agent_graceful_shutdown.py::test_agent_stop_is_idempotent is unskipped and passes
  • Stop semantics documented in the Agent docstring

Related

Discovered via

PR #352 (test coverage improvements). One of 5 source bugs surfaced while writing failure-mode tests for the Python SDK.

Metadata

Metadata

Assignees

Labels

ai-friendlyWell-documented task suitable for AI-assisted developmentbugSomething isn't workingsdk:pythonPython SDK relatedtestsUnit test improvements and coverage

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions