Repository navigation
agents: poll tool tasks in the Python Claude Agent SDK adapter - #1801
Merged
Merged
Conversation
…urces ClaudeAgentRunner implements poll_tool_task and cancel_tool_task. Each routes the stored call to the tool source that built it, unwraps the source's own reference, and passes the record on. The session now sets supports_tool_tasks for this runner, so a source call that returns ToolTaskStarted is polled on a Timer and its result reaches the resumed Claude session; cancel_turn cancels the task through the source.
McpToolSource marks the heartbeat checkpoint of a task it hands to the session with mcp_task_polled_by_session, as the TypeScript source does. A retried CallTool attempt hands a saved task to the session only when the marker is set; a task saved by an in-Step poll keeps polling in the tool Step and is sent again with the same idempotency key when lost. The Claude adapter's tool task docs move to 0.6.6, the cancel docstring follows the CancelToolTask order, and the tests check that the stored transcript answers every tool_use once and cover a source without cancel_tool_task.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Python Claude Agent SDK runner gains
poll_tool_taskandcancel_tool_task, routed to the ToolSource that built the call, exactly asexecute_deferred_tool_callroutes. The session core then reportssupports_tool_tasksas true, so a ToolSource tool may returnToolTaskStarted; the session polls it inPollToolTaskSteps and hands the final output to the resumed Claude session as the tool's result.Why
An application wants a ToolSource tool that waits for an external event (for example a human reply) without a separate polling Flow. The built-in loop runner and pi already poll tool tasks; the Claude Agent SDK adapter recorded a started task as a call without a poller. The TypeScript adapter needs a public type change and waits for an owner decision.
Behavior change
McpToolSource, seeingsupports_tool_taskstrue, now hands Streamable HTTP server tasks to the session to poll instead of finishing them inside the tool Step.Testing
tests/test_tool_tasks.py: pending twice then output reaches the resumed session; pollToolExecutionErrorrecords failed;cancel_turncalls the source'scancel_tool_taskonce and the session still answers afterwards.