Add asynchronous tool support with agent pause/resume#105
Draft
weeco wants to merge 1 commit into
Draft
Conversation
…104) Wire the existing FinishReasonInputRequired scaffolding into a working pause/resume system for human-in-the-loop and long-running tools. Breaking change: Tool interface gains IsAsynchronous() bool. All Tool implementations must add this method (return false for synchronous tools). Core changes: - tool.Tool: add IsAsynchronous() to signal tools that cannot complete in a single synchronous call (user input, CI/CD, batch jobs) - agent/llmagent: executeTools() detects async tools via IsAsynchronous() and returns inputRequiredIDs; executeSingleTurn() emits FinishReasonInputRequired with InputRequiredToolIDs - runner: add Resume() for providing tool results after pause; refactor Run()/Resume() to share runAgent() helper - tool/registry: annotate async tool descriptions with re-invocation warning for the LLM - tool/mcp: wire ElicitationHandler to MCP SDK ClientOptions for server-initiated user input requests - tool/builtin/require_input: mark as IsAsynchronous()=true; simplify Execute() to return pending status https://claude.ai/code/session_01WFwbKjni1JS6Rf17VNySb1
|
Found 1 test failure on Blacksmith runners: Failure
|
Contributor
Author
|
This was a test using the new ultraplan feature. Still have to review and check if I'd be happy with that API, I only planned and let it go create the PR without loooking into it |
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
This PR adds support for asynchronous tools that require external completion (e.g., user input, long-running deployments). When an asynchronous tool is executed, the agent pauses with
FinishReasonInputRequiredand can be resumed later viaRunner.Resume()with the final tool results.Key Changes
Tool Interface Enhancement: Added
IsAsynchronous()method to theToolinterface to declare whether a tool requires external completionAgent Pause/Resume Logic:
LLMAgent.executeSingleTurn()to detect asynchronous tools and pause execution withFinishReasonInputRequiredInvocationEndEvent.InputRequiredToolIDsStatusStageInputRequiredevent when pausing for external inputRunner Resume Support:
Runner.Resume()method to continue paused invocations by providing tool resultsrunAgent()helper used by bothRun()andResume()ToolResponseparts before resumingTool Registry Enhancement: Registry now appends a note to asynchronous tool descriptions instructing the LLM not to re-invoke them after a pending status
MCP Elicitation Support: Added
ElicitationHandlerandWithElicitationHandler()to support MCP server requests for user input during tool executionBuilt-in Tool Updates:
RequireInputToolnow declares itself as asynchronousIsAsynchronous()returningfalseComprehensive Tests: Added
TestRun_AsyncToolPausesExecutionandTestRun_MixedSyncAndAsyncToolsto verify pause/resume behavior with mixed tool typesImplementation Details
executeTools()executeToolsResultstruct now tracks both response parts and IDs of tools requiring external inputResume()https://claude.ai/code/session_01WFwbKjni1JS6Rf17VNySb1