Skip to content

feat(api_server): add POST /v1/runs/{run_id}/stop endpoint#1

Open
EKKOLearnAI wants to merge 3 commits into
mainfrom
feat/api-server-stop-run
Open

feat(api_server): add POST /v1/runs/{run_id}/stop endpoint#1
EKKOLearnAI wants to merge 3 commits into
mainfrom
feat/api-server-stop-run

Conversation

@EKKOLearnAI
Copy link
Copy Markdown
Owner

Summary

  • Add POST /v1/runs/{run_id}/stop endpoint to interrupt a running agent
  • Store agent/task references in _active_run_agents and _active_run_tasks during execution
  • Call agent.interrupt() to gracefully stop LLM calls, then cancel the asyncio task
  • Clean up references in _run_and_close finally block and orphan sweep
  • Add 15 tests covering start, events, and stop scenarios (auth, 404, interrupt, cleanup)

Test plan

  • python -m pytest tests/gateway/test_api_server_runs.py -v — 15 passed
  • Manual: curl -X POST http://localhost:8642/v1/runs -d '{"input":"hello"}' → stop → verify events stream closes

EKKOLearnAI and others added 3 commits April 25, 2026 21:45
Add ability to interrupt a running agent via the runs API. Previously
/v1/runs could start a run and subscribe to events, but there was no
way to cancel it. The new endpoint stores agent and task references
during execution, calls agent.interrupt() to stop LLM calls, then
cancels the asyncio task.

Includes 15 tests covering start, events, and stop scenarios.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant