Skip to content

feat: implement Agent.stop() in python sdk#446

Open
shuaixr wants to merge 1 commit intoAgent-Field:mainfrom
shuaixr:feat/implement-Agent.stop()-in-python-sdk
Open

feat: implement Agent.stop() in python sdk#446
shuaixr wants to merge 1 commit intoAgent-Field:mainfrom
shuaixr:feat/implement-Agent.stop()-in-python-sdk

Conversation

@shuaixr
Copy link
Copy Markdown

@shuaixr shuaixr commented Apr 12, 2026

Summary

Implements Agent.stop() method that performs a clean async shutdown of an agent instance:

  • Marks agent as shutting down and transitions status to OFFLINE
  • Stops heartbeat background worker
  • Notifies AgentField control plane of graceful shutdown (best effort)
  • Cleans up async execution resources, memory event clients, and connection managers
  • Idempotent: repeated calls have no additional effect after the first

Closes: #355

Testing

  • ./scripts/test-all.sh
  • Additional verification (please describe):

Checklist

  • I updated documentation where applicable.
  • I added or updated tests (or none were needed).
  • I updated CHANGELOG.md (or this change does not warrant a changelog entry).

Screenshots (if UI-related)

Related issues

@shuaixr shuaixr requested review from a team and AbirAbbas as code owners April 12, 2026 16:24
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 12, 2026

CLA assistant check
All committers have signed the CLA.

@shuaixr shuaixr force-pushed the feat/implement-Agent.stop()-in-python-sdk branch from c853bf8 to 7e64515 Compare April 12, 2026 16:28
@github-actions
Copy link
Copy Markdown
Contributor

Performance

SDK Memory Δ Latency Δ Tests Status
Python 7.9 KB -13% 0.33 µs -6%

✓ No regressions detected

@github-actions
Copy link
Copy Markdown
Contributor

📊 Coverage gate

Thresholds from .coverage-gate.toml: per-surface ≥ 86%, aggregate ≥ 88%, max per-surface regression ≤ 1.0 pp, max aggregate regression ≤ 0.50 pp.

Surface Current Baseline Δ
control-plane 87.30% 87.30% → +0.00 pp 🟡
sdk-go 90.70% 90.70% → +0.00 pp 🟢
sdk-python 93.63% 93.63% ↑ +0.00 pp 🟢
sdk-typescript 92.56% 92.56% → +0.00 pp 🟢
web-ui 90.02% 90.01% ↑ +0.01 pp 🟢
aggregate 89.02% 89.01% ↑ +0.01 pp 🟡

✅ Gate passed

No surface regressed past the allowed threshold and the aggregate stayed above the floor.

@github-actions
Copy link
Copy Markdown
Contributor

📐 Patch coverage gate

Threshold: 80% on lines this PR touches vs origin/main (from .coverage-gate.toml:thresholds.min_patch).

Surface Touched lines Patch coverage Status
control-plane 0 ➖ no changes
sdk-go 0 ➖ no changes
sdk-python 0 ➖ no changes
sdk-typescript 0 ➖ no changes
web-ui 0 ➖ no changes

✅ Patch gate passed

Every surface whose lines were touched by this PR has patch coverage at or above the threshold.

Copy link
Copy Markdown
Contributor

@AbirAbbas AbirAbbas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition — the try/except isolation around each cleanup step is the right call, and the idempotency guard works. A couple things worth addressing:

if self.dev_mode:
from agentfield.logger import log_error

log_error(f"Registry clear error during stop(): {e}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calls clear_current_agent() but doesn't clear Agent._current_agent (the class-level attr). The existing _clear_current() method right above does both — it deletes the class attr and calls clear_current_agent().

After stop(), Agent.get_current() will still return the stopped agent. Should probably just call self._clear_current() here instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants